Class: RSCM::Monotone

Inherits:
Base
  • Object
show all
Defined in:
lib/rscm/scm/monotone.rb

Constant Summary

Constants included from RevisionPoller

RevisionPoller::BASE_INCREMENT, RevisionPoller::CRITICAL_REVISION_SIZE, RevisionPoller::TWENTY_FOUR_HOURS

Instance Attribute Summary collapse

Attributes inherited from Base

#default_options, #store_revisions_command

Attributes included from RevisionPoller

#logger

Instance Method Summary collapse

Methods inherited from Base

#==, #available?, #checked_out_files, #checkout, #checkout_commandline, #checkout_dir, #checkout_dir=, #destroy_working_copy, #edit, #open, #store_revisions_command?, #to_identifier, #to_yaml_properties, #update_commandline

Methods included from RevisionPoller

#poll

Constructor Details

#initialize(branch = nil, key = nil, passphrase = nil, keys_file = nil, server = nil, central_checkout_dir = nil) ⇒ Monotone

Returns a new instance of Monotone.



14
15
16
17
18
19
20
21
# File 'lib/rscm/scm/monotone.rb', line 14

def initialize(branch=nil, key=nil, passphrase=nil, keys_file=nil, server=nil, central_checkout_dir=nil)
  @branch = branch
  @key = key
  @passphrase = passphrase
  @keys_file = keys_file
  @server = server
  @central_checkout_dir = File.expand_path(central_checkout_dir) unless central_checkout_dir.nil?
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



8
9
10
# File 'lib/rscm/scm/monotone.rb', line 8

def branch
  @branch
end

#db_fileObject

Returns the value of attribute db_file.



7
8
9
# File 'lib/rscm/scm/monotone.rb', line 7

def db_file
  @db_file
end

#keyObject

Returns the value of attribute key.



9
10
11
# File 'lib/rscm/scm/monotone.rb', line 9

def key
  @key
end

#keys_fileObject

Returns the value of attribute keys_file.



11
12
13
# File 'lib/rscm/scm/monotone.rb', line 11

def keys_file
  @keys_file
end

#passphraseObject

Returns the value of attribute passphrase.



10
11
12
# File 'lib/rscm/scm/monotone.rb', line 10

def passphrase
  @passphrase
end

#serverObject

Returns the value of attribute server.



12
13
14
# File 'lib/rscm/scm/monotone.rb', line 12

def server
  @server
end

Instance Method Details

#add(relative_filename) ⇒ Object



23
24
25
26
27
28
# File 'lib/rscm/scm/monotone.rb', line 23

def add(relative_filename)
  db = db(@checkout_dir)
  with_working_dir(@checkout_dir) do
    monotone("add #{relative_filename}", db)
  end
end

#can_create_central?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rscm/scm/monotone.rb', line 37

def can_create_central?
  @server == "localhost" && !@central_checkout_dir.nil?
end

#central_exists?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rscm/scm/monotone.rb', line 41

def central_exists?
  @central_checkout_dir && @serve_pid
end

#checked_out?Boolean

Returns:

  • (Boolean)


108
109
110
111
# File 'lib/rscm/scm/monotone.rb', line 108

def checked_out?
  mt = File.expand_path("#{@checkout_dir}/MT")
  File.exists?(mt)
end

#commit(message) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/rscm/scm/monotone.rb', line 134

def commit(message)
  commit_in_dir(message, @checkout_dir)
  with_working_dir(@checkout_dir) do
    monotone("push #{@server} #{@branch}") do |io|
      io.puts(@passphrase)
      io.close_write
      io.read
    end
  end
end

#create_centralObject



45
46
47
48
49
50
51
52
# File 'lib/rscm/scm/monotone.rb', line 45

def create_central
  init(@central_checkout_dir)
  # create empty working copy
  dir = PathConverter.filepath_to_nativepath(@central_checkout_dir, false)
  # set up a working copy
  monotone("setup #{dir}")
  start_serve
end

#destroy_centralObject



89
90
91
92
93
94
# File 'lib/rscm/scm/monotone.rb', line 89

def destroy_central
  stop_serve
  FileUtils.rm_rf(@central_checkout_dir) if File.exist?(@central_checkout_dir)
  FileUtils.rm(db(@central_checkout_dir)) if File.exist?(db(@central_checkout_dir))
  puts "Destroyed Monotone server"
end

#diff(change, &block) ⇒ Object



174
175
176
177
178
179
180
181
# File 'lib/rscm/scm/monotone.rb', line 174

def diff(change, &block)
  checkout(change.revision)
  with_working_dir(@checkout_dir) do
    monotone("diff --revision=#{change.previous_native_revision_identifier} #{change.path}") do |stdout|
      yield stdout
    end
  end
end

#import_central(dir, message) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/rscm/scm/monotone.rb', line 100

def import_central(dir, message)
  FileUtils.cp_r(Dir["#{dir}/*"], @central_checkout_dir)
  with_working_dir(@central_checkout_dir) do
    monotone("add .")
    commit_in_dir(message, @central_checkout_dir)
  end
end

#install_trigger(trigger_command, install_dir) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/rscm/scm/monotone.rb', line 154

def install_trigger(trigger_command, install_dir)
  stop_serve
  if (WINDOWS)
    install_win_trigger(trigger_comand, install_dir)
  else
    install_unix_trigger(trigger_command, install_dir)
  end
  start_serve
end

#move(relative_src, relative_dest) ⇒ Object



30
31
32
33
34
35
# File 'lib/rscm/scm/monotone.rb', line 30

def move(relative_src, relative_dest)
  with_working_dir(@checkout_dir) do
    monotone("rename #{relative_src} #{relative_dest}", db)
    FileUtils.mv(relative_src, relative_dest)
  end
end

#revisions(from_identifier, to_identifier = Time.infinity) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/rscm/scm/monotone.rb', line 124

def revisions(from_identifier, to_identifier=Time.infinity)
  checkout(to_identifier)
  to_identifier = Time.infinity if to_identifier.nil?
  with_working_dir(checkout_dir) do
    monotone("log") do |stdout|
      MonotoneLogParser.new.parse_revisions(stdout, from_identifier, to_identifier)
    end
  end
end

#start_serveObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rscm/scm/monotone.rb', line 54

def start_serve
  mode = File::CREAT|File::WRONLY
  if File.exist?(rcfile)
    mode = File::APPEND|File::WRONLY
  end

  begin
    File.open(rcfile, mode) do |file|
      file.puts("function get_netsync_anonymous_read_permitted(collection)")
      file.puts("  return true")
      file.puts("end")
    end
  rescue => e
    puts e.message
    puts e.backtrace.join("\n")
    raise "Didn't have permission to write to #{rcfile}."
  end

  @serve_pid = fork do
    #Signal.trap("HUP") { puts "Monotone server shutting down..."; exit }
    monotone("serve --rcfile=\"#{rcfile}\" #{@server} #{@branch}", db(@central_checkout_dir)) do |io|
      puts "PASSPHRASE: #{@passphrase}"
      io.puts(@passphrase)
      io.close_write
    end
  end
  Process.detach(@serve_pid)
end

#stop_serveObject



83
84
85
86
87
# File 'lib/rscm/scm/monotone.rb', line 83

def stop_serve
  Process.kill("HUP", @serve_pid) if @serve_pid
  Process.waitpid2(@serve_pid) if @serve_pid
  @serve_pid = nil
end

#supports_trigger?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/rscm/scm/monotone.rb', line 145

def supports_trigger?
  true
end

#transactional?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/rscm/scm/monotone.rb', line 96

def transactional?
  true
end

#trigger_installed?(trigger_command, install_dir) ⇒ Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/rscm/scm/monotone.rb', line 164

def trigger_installed?(trigger_command, install_dir)
  File.exist?(rcfile)
end

#trigger_mechanismObject



149
150
151
# File 'lib/rscm/scm/monotone.rb', line 149

def trigger_mechanism
  "MT/monotonerc"
end

#uninstall_trigger(trigger_command, install_dir) ⇒ Object



168
169
170
171
172
# File 'lib/rscm/scm/monotone.rb', line 168

def uninstall_trigger(trigger_command, install_dir)
  stop_serve
  File.delete(rcfile)
  start_serve
end

#uptodate?(identifier = nil) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
121
122
# File 'lib/rscm/scm/monotone.rb', line 113

def uptodate?(identifier=nil)
  if (!checked_out?)
    false
  else
    pull

    rev = identifier ? identifier : head_revision
    local_revision == rev
  end
end