From 816189f5be68c364d3beda4c20ed07d375f9f162 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 25 Jul 2010 17:53:11 +0200 Subject: [PATCH] Atomic merges Move the tree-merging method to Tree, and make it atomic: if merging fails, the tree is not updated. Since the error propagates up, and the tree merge is the first step of a commit merge, commit merges are atomic too. --- rcs-fast-export.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/rcs-fast-export.rb b/rcs-fast-export.rb index 406ae45..45389f8 100755 --- a/rcs-fast-export.rb +++ b/rcs-fast-export.rb @@ -489,9 +489,17 @@ module RCS @files = Hash.new end - def add(rcs, rev) - if @files.key? rcs - prev = @files[rcs] + def merge!(tree) + testfiles = @files.dup + tree.each { |rcs, rev| self.add(rcs, rev, testfiles) } + # the next line is only reached if all the adds were + # succesfull, so the merge is atomic + @files.replace testfiles + end + + def add(rcs, rev, file_list=@files) + if file_list.key? rcs + prev = file_list[rcs] if prev.log == rev.log str = "re-adding existing file #{rcs.fname} (old: #{prev.rev}, new: #{rev.rev})" else @@ -503,7 +511,7 @@ module RCS @commit.warn_about str end end - @files[rcs] = rev + file_list[rcs] = rev end def each &block @@ -557,9 +565,7 @@ module RCS end def merge!(commit) - commit.tree.each do |rcs, rev| - self.tree.add rcs, rev - end + self.tree.merge! commit.tree if commit.date > self.date warn_about "updating date to #{commit.date}" self.date = commit.date -- 2.32.0.93.g670b81a890