44f57851c5ae2a8adba7bc4f48ab0da99ab1ac45
Author: Robin Luckey
Date: 2009-08-11 12:10:22 -0700
diff --git a/lib/scm/parsers/bzr_parser.rb b/lib/scm/parsers/bzr_parser.rb
index a693be0..739bbc6 100644
--- a/lib/scm/parsers/bzr_parser.rb
+++ b/lib/scm/parsers/bzr_parser.rb
@@ -107,13 +107,15 @@ module Scm::Parsers
path[-1..-1] == '*' ? path[0..-2] : path
end
- # Bazaar may report that a file was both deleted, added, and/or modified all
- # in a single commit.
- #
- # All such cases mean that the path in question still exists, and that some
- # kind of modification occured, so we reduce all such multiple cases to
- # a single diff with an 'M' action.
def self.remove_dupes(diffs)
+ # Bazaar may report that a file was added and modified in a single commit.
+ # Reduce these cases to a single 'A' action.
+ diffs.delete_if do |d|
+ d.action == 'M' && diffs.select { |x| x.path == d.path && x.action == 'A' }.any?
+ end
+
+ # Bazaar may report that a file was both deleted and added in a single commit.
+ # Reduce these cases to a single 'M' action.
diffs.each do |d|
d.action = 'M' if diffs.select { |x| x.path == d.path }.size > 1
end.uniq
diff --git a/test/unit/bzr_parser_test.rb b/test/unit/bzr_parser_test.rb
index ebe6696..19bef08 100644
--- a/test/unit/bzr_parser_test.rb
+++ b/test/unit/bzr_parser_test.rb
@@ -433,5 +433,30 @@ added:
assert_equal "A", commits.first.diffs.last.action
assert_equal "", commits.first.diffs.last.path
end
+
+ # It is possible for Bzr to report a file as both renamed and modified
+ # in the same commit. We should treat this as only a rename -- that is, we
+ # should see a simple DELETE from the old location and an ADD to the new location.
+ def test_rename_and_modify_in_one_commit
+ log = <<-SAMPLE
+------------------------------------------------------------
+revno: 1
+message:
+ Changed the directory structure
+renamed:
+ oldname => newname
+modified:
+ newname
+ SAMPLE
+
+ commits = BzrParser.parse(log)
+
+ assert_equal 1, commits.size
+ assert_equal 2, commits.first.diffs.size
+ assert_equal "D", commits.first.diffs.first.action
+ assert_equal "oldname", commits.first.diffs.first.path
+ assert_equal "A", commits.first.diffs.last.action
+ assert_equal "newname", commits.first.diffs.last.path
+ end
end
end
