Merge lp:~jelmer/brz/diff-fix into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/diff-fix
Merge into: lp:brz/3.1
Diff against target: 111 lines (+36/-13)
3 files modified
breezy/diff.py (+9/-9)
breezy/tests/blackbox/test_diff.py (+20/-0)
breezy/tests/test_diff.py (+7/-4)
To merge this branch: bzr merge lp:~jelmer/brz/diff-fix
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+384877@code.launchpad.net

Commit message

Distinguish between label and path when generating diffs.

Description of the change

Distinguish between label and path when generating diffs.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/diff.py'
--- breezy/diff.py 2020-01-11 17:41:33 +0000
+++ breezy/diff.py 2020-05-30 20:21:21 +0000
@@ -734,10 +734,10 @@
734 new_date = self.EPOCH_DATE734 new_date = self.EPOCH_DATE
735 else:735 else:
736 return self.CANNOT_DIFF736 return self.CANNOT_DIFF
737 from_label = '%s%s\t%s' % (self.old_label, old_path,737 from_label = '%s%s\t%s' % (
738 old_date)738 self.old_label, old_path or new_path, old_date)
739 to_label = '%s%s\t%s' % (self.new_label, new_path,739 to_label = '%s%s\t%s' % (
740 new_date)740 self.new_label, new_path or old_path, new_date)
741 return self.diff_text(old_path, new_path, from_label, to_label)741 return self.diff_text(old_path, new_path, from_label, to_label)
742742
743 def diff_text(self, from_path, to_path, from_label, to_label):743 def diff_text(self, from_path, to_path, from_label, to_label):
@@ -765,7 +765,9 @@
765 except errors.BinaryFile:765 except errors.BinaryFile:
766 self.to_file.write(766 self.to_file.write(
767 ("Binary files %s%s and %s%s differ\n" %767 ("Binary files %s%s and %s%s differ\n" %
768 (self.old_label, from_path, self.new_label, to_path)).encode(self.path_encoding, 'replace'))768 (self.old_label, from_path or to_path,
769 self.new_label, to_path or from_path)
770 ).encode(self.path_encoding, 'replace'))
769 return self.CHANGED771 return self.CHANGED
770772
771773
@@ -1055,8 +1057,8 @@
1055 'supported on this filesystem.' % (change.path[0],))1057 'supported on this filesystem.' % (change.path[0],))
1056 continue1058 continue
1057 oldpath, newpath = change.path1059 oldpath, newpath = change.path
1058 oldpath_encoded = get_encoded_path(change.path[0])1060 oldpath_encoded = get_encoded_path(oldpath)
1059 newpath_encoded = get_encoded_path(change.path[1])1061 newpath_encoded = get_encoded_path(newpath)
1060 old_present = (change.kind[0] is not None and change.versioned[0])1062 old_present = (change.kind[0] is not None and change.versioned[0])
1061 new_present = (change.kind[1] is not None and change.versioned[1])1063 new_present = (change.kind[1] is not None and change.versioned[1])
1062 executable = change.executable1064 executable = change.executable
@@ -1076,11 +1078,9 @@
1076 if (old_present, new_present) == (True, False):1078 if (old_present, new_present) == (True, False):
1077 self.to_file.write(b"=== removed %s '%s'\n" %1079 self.to_file.write(b"=== removed %s '%s'\n" %
1078 (kind[0].encode('ascii'), oldpath_encoded))1080 (kind[0].encode('ascii'), oldpath_encoded))
1079 newpath = oldpath
1080 elif (old_present, new_present) == (False, True):1081 elif (old_present, new_present) == (False, True):
1081 self.to_file.write(b"=== added %s '%s'\n" %1082 self.to_file.write(b"=== added %s '%s'\n" %
1082 (kind[1].encode('ascii'), newpath_encoded))1083 (kind[1].encode('ascii'), newpath_encoded))
1083 oldpath = newpath
1084 elif renamed:1084 elif renamed:
1085 self.to_file.write(b"=== renamed %s '%s' => '%s'%s\n" %1085 self.to_file.write(b"=== renamed %s '%s' => '%s'%s\n" %
1086 (kind[0].encode('ascii'), oldpath_encoded, newpath_encoded, prop_str))1086 (kind[0].encode('ascii'), oldpath_encoded, newpath_encoded, prop_str))
10871087
=== modified file 'breezy/tests/blackbox/test_diff.py'
--- breezy/tests/blackbox/test_diff.py 2020-01-31 03:05:58 +0000
+++ breezy/tests/blackbox/test_diff.py 2020-05-30 20:21:21 +0000
@@ -358,6 +358,26 @@
358 "=== removed file 'a'\nBinary files old/a and new/a differ\n",358 "=== removed file 'a'\nBinary files old/a and new/a differ\n",
359 output[0])359 output[0])
360360
361 def test_moved_away(self):
362 # pad.lv/1880354
363 tree = self.make_branch_and_tree('.')
364 self.build_tree_contents([('a', 'asdf\n')])
365 tree.add(['a'])
366 tree.commit('add a')
367 tree.rename_one('a', 'b')
368 self.build_tree_contents([('a', 'qwer\n')])
369 tree.add('a')
370 output, error = self.run_bzr('diff -p0', retcode=1)
371 self.assertEqualDiff("""\
372=== added file 'a'
373--- a\tYYYY-MM-DD HH:MM:SS +ZZZZ
374+++ a\tYYYY-MM-DD HH:MM:SS +ZZZZ
375@@ -0,0 +1,1 @@
376+qwer
377
378=== renamed file 'a' => 'b'
379""", subst_dates(output))
380
361381
362class TestCheckoutDiff(TestDiff):382class TestCheckoutDiff(TestDiff):
363383
364384
=== modified file 'breezy/tests/test_diff.py'
--- breezy/tests/test_diff.py 2019-12-23 01:39:21 +0000
+++ breezy/tests/test_diff.py 2020-05-30 20:21:21 +0000
@@ -608,8 +608,8 @@
608 [('tree/' + alpha, b'\0'),608 [('tree/' + alpha, b'\0'),
609 ('tree/' + omega,609 ('tree/' + omega,
610 (b'The %s and the %s\n' % (alpha_utf8, omega_utf8)))])610 (b'The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
611 tree.add([alpha], [b'file-id'])611 tree.add([alpha])
612 tree.add([omega], [b'file-id-2'])612 tree.add([omega])
613 diff_content = StubO()613 diff_content = StubO()
614 diff.show_diff_trees(tree.basis_tree(), tree, diff_content)614 diff.show_diff_trees(tree.basis_tree(), tree, diff_content)
615 diff_content.check_types(self, bytes)615 diff_content.check_types(self, bytes)
@@ -805,8 +805,11 @@
805 self.differ.diff('olddir/oldfile', 'newdir/newfile')805 self.differ.diff('olddir/oldfile', 'newdir/newfile')
806 self.assertContainsRe(806 self.assertContainsRe(
807 self.differ.to_file.getvalue(),807 self.differ.to_file.getvalue(),
808 br'--- olddir/oldfile.*\n\+\+\+ newdir/newfile.*\n\@\@ -1,1 \+0,0'808 br'--- olddir/oldfile.*\n'
809 br' \@\@\n-old\n\n')809 br'\+\+\+ newdir/newfile.*\n'
810 br'\@\@ -1,1 \+0,0 \@\@\n'
811 br'-old\n'
812 br'\n')
810 self.assertContainsRe(self.differ.to_file.getvalue(),813 self.assertContainsRe(self.differ.to_file.getvalue(),
811 b"=== target is 'new'\n")814 b"=== target is 'new'\n")
812815

Subscribers

People subscribed via source and target branches