Class: Amp::Merges::MergeState
- Includes:
- Enumerable
- Defined in:
- lib/amp/merges/merge_state.rb
Overview
MergeState
MergeState handles the merge/ directory in the repository, in order to keep track of how well the current merge is progressing. There is a file called merge/state that lists all the files that need merging and a little info about whether it has beeen merged or not.
You can add a file to the mergestate, iterate over all of them, quickly look up to see if a file is still dirty, and so on.
Instance Method Summary collapse
-
#[](dirty_file) ⇒ String
Accesses the the given file’s merge status - can be “u” for unmerged, or other stuff we haven’t figured out yet.
-
#add(fcl, fco, fca, fd, flags) ⇒ Object
Adds a file to the mergestate, which creates a separate file in the merge directory with all the information.
-
#each {|file, state| ... } ⇒ Object
Iterates over all the files that are involved in the current merging transaction.
-
#include?(dirty_file) ⇒ Boolean
Returns whether the file is part of a merge or not.
-
#initialize(repo) ⇒ MergeState
constructor
Initializes a new mergestate with the given repo, and reads in all the information from merge/state.
-
#mark(dirty_file, state) ⇒ Object
Marks the given file with a given state, which is 1 letter.
-
#reset(node = nil) ⇒ Object
(also: #reset!)
Resets the merge status, by clearing all merge information and files.
-
#resolve(dirty_file, working_changeset, other_changeset) ⇒ Object
Resolves the given file for a merge between 2 changesets.
-
#save ⇒ Object
(also: #save!)
Public access to writing the file.
Methods included from Enumerable
Constructor Details
#initialize(repo) ⇒ MergeState
Initializes a new mergestate with the given repo, and reads in all the information from merge/state.
21 22 23 24 |
# File 'lib/amp/merges/merge_state.rb', line 21 def initialize(repo) @repo = repo read! end |
Instance Method Details
#[](dirty_file) ⇒ String
Accesses the the given file’s merge status - can be “u” for unmerged, or other stuff we haven’t figured out yet.
52 53 54 |
# File 'lib/amp/merges/merge_state.rb', line 52 def [](dirty_file) @state[dirty_file] ? @state[dirty_file][0, 1] : "" end |
#add(fcl, fco, fca, fd, flags) ⇒ Object
Adds a file to the mergestate, which creates a separate file in the merge directory with all the information. I don’t know what these parameters are for yet.
60 61 62 63 64 65 66 67 68 |
# File 'lib/amp/merges/merge_state.rb', line 60 def add(fcl, fco, fca, fd, flags) hash = Digest::SHA1.new.update(fcl.path).hexdigest @repo.open("merge/#{hash}", "w") do |file| file.write fcl.data end @state[fd] = ["u", hash, fcl.path, fca.path, fca.file_node.hexlify, fco.path, flags] save end |
#each {|file, state| ... } ⇒ Object
Iterates over all the files that are involved in the current merging transaction.
78 79 80 81 82 |
# File 'lib/amp/merges/merge_state.rb', line 78 def each @state.keys.sort.each do |key| yield(key, @state[key]) end end |
#include?(dirty_file) ⇒ Boolean
Returns whether the file is part of a merge or not
41 42 43 |
# File 'lib/amp/merges/merge_state.rb', line 41 def include?(dirty_file) not @state[dirty_file].nil? end |
#mark(dirty_file, state) ⇒ Object
Marks the given file with a given state, which is 1 letter. “u” means unmerged, “r” means resolved.
90 91 92 93 |
# File 'lib/amp/merges/merge_state.rb', line 90 def mark(dirty_file, state) @state[dirty_file][0] = state save end |
#reset(node = nil) ⇒ Object Also known as: reset!
Resets the merge status, by clearing all merge information and files
30 31 32 33 34 |
# File 'lib/amp/merges/merge_state.rb', line 30 def reset(node = nil) @state = {} @local = node if node FileUtils.rm_rf @repo.join("merge") end |
#resolve(dirty_file, working_changeset, other_changeset) ⇒ Object
Resolves the given file for a merge between 2 changesets.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/amp/merges/merge_state.rb', line 102 def resolve(dirty_file, working_changeset, other_changeset) return 0 if self[dirty_file] == "r" state, hash, lfile, afile, anode, ofile, flags = @state[dirty_file] r = true @repo.open("merge/#{hash}") do |file| @repo.working_write(dirty_file, file.read, flags) working_file = working_changeset[dirty_file] other_file = other_changeset[ofile] ancestor_file = @repo.versioned_file(afile, :file_id => anode) r = UI.file_merge(@repo, @local, lfile, working_file, other_file, ancestor_file) end mark(dirty_file, "r") if r.nil? || r == false return r end |
#save ⇒ Object Also known as: save!
Public access to writing the file.
120 121 122 |
# File 'lib/amp/merges/merge_state.rb', line 120 def save write! end |