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
1=== modified file 'breezy/diff.py'
2--- breezy/diff.py 2020-01-11 17:41:33 +0000
3+++ breezy/diff.py 2020-05-30 20:21:21 +0000
4@@ -734,10 +734,10 @@
5 new_date = self.EPOCH_DATE
6 else:
7 return self.CANNOT_DIFF
8- from_label = '%s%s\t%s' % (self.old_label, old_path,
9- old_date)
10- to_label = '%s%s\t%s' % (self.new_label, new_path,
11- new_date)
12+ from_label = '%s%s\t%s' % (
13+ self.old_label, old_path or new_path, old_date)
14+ to_label = '%s%s\t%s' % (
15+ self.new_label, new_path or old_path, new_date)
16 return self.diff_text(old_path, new_path, from_label, to_label)
17
18 def diff_text(self, from_path, to_path, from_label, to_label):
19@@ -765,7 +765,9 @@
20 except errors.BinaryFile:
21 self.to_file.write(
22 ("Binary files %s%s and %s%s differ\n" %
23- (self.old_label, from_path, self.new_label, to_path)).encode(self.path_encoding, 'replace'))
24+ (self.old_label, from_path or to_path,
25+ self.new_label, to_path or from_path)
26+ ).encode(self.path_encoding, 'replace'))
27 return self.CHANGED
28
29
30@@ -1055,8 +1057,8 @@
31 'supported on this filesystem.' % (change.path[0],))
32 continue
33 oldpath, newpath = change.path
34- oldpath_encoded = get_encoded_path(change.path[0])
35- newpath_encoded = get_encoded_path(change.path[1])
36+ oldpath_encoded = get_encoded_path(oldpath)
37+ newpath_encoded = get_encoded_path(newpath)
38 old_present = (change.kind[0] is not None and change.versioned[0])
39 new_present = (change.kind[1] is not None and change.versioned[1])
40 executable = change.executable
41@@ -1076,11 +1078,9 @@
42 if (old_present, new_present) == (True, False):
43 self.to_file.write(b"=== removed %s '%s'\n" %
44 (kind[0].encode('ascii'), oldpath_encoded))
45- newpath = oldpath
46 elif (old_present, new_present) == (False, True):
47 self.to_file.write(b"=== added %s '%s'\n" %
48 (kind[1].encode('ascii'), newpath_encoded))
49- oldpath = newpath
50 elif renamed:
51 self.to_file.write(b"=== renamed %s '%s' => '%s'%s\n" %
52 (kind[0].encode('ascii'), oldpath_encoded, newpath_encoded, prop_str))
53
54=== modified file 'breezy/tests/blackbox/test_diff.py'
55--- breezy/tests/blackbox/test_diff.py 2020-01-31 03:05:58 +0000
56+++ breezy/tests/blackbox/test_diff.py 2020-05-30 20:21:21 +0000
57@@ -358,6 +358,26 @@
58 "=== removed file 'a'\nBinary files old/a and new/a differ\n",
59 output[0])
60
61+ def test_moved_away(self):
62+ # pad.lv/1880354
63+ tree = self.make_branch_and_tree('.')
64+ self.build_tree_contents([('a', 'asdf\n')])
65+ tree.add(['a'])
66+ tree.commit('add a')
67+ tree.rename_one('a', 'b')
68+ self.build_tree_contents([('a', 'qwer\n')])
69+ tree.add('a')
70+ output, error = self.run_bzr('diff -p0', retcode=1)
71+ self.assertEqualDiff("""\
72+=== added file 'a'
73+--- a\tYYYY-MM-DD HH:MM:SS +ZZZZ
74++++ a\tYYYY-MM-DD HH:MM:SS +ZZZZ
75+@@ -0,0 +1,1 @@
76++qwer
77+
78+=== renamed file 'a' => 'b'
79+""", subst_dates(output))
80+
81
82 class TestCheckoutDiff(TestDiff):
83
84
85=== modified file 'breezy/tests/test_diff.py'
86--- breezy/tests/test_diff.py 2019-12-23 01:39:21 +0000
87+++ breezy/tests/test_diff.py 2020-05-30 20:21:21 +0000
88@@ -608,8 +608,8 @@
89 [('tree/' + alpha, b'\0'),
90 ('tree/' + omega,
91 (b'The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
92- tree.add([alpha], [b'file-id'])
93- tree.add([omega], [b'file-id-2'])
94+ tree.add([alpha])
95+ tree.add([omega])
96 diff_content = StubO()
97 diff.show_diff_trees(tree.basis_tree(), tree, diff_content)
98 diff_content.check_types(self, bytes)
99@@ -805,8 +805,11 @@
100 self.differ.diff('olddir/oldfile', 'newdir/newfile')
101 self.assertContainsRe(
102 self.differ.to_file.getvalue(),
103- br'--- olddir/oldfile.*\n\+\+\+ newdir/newfile.*\n\@\@ -1,1 \+0,0'
104- br' \@\@\n-old\n\n')
105+ br'--- olddir/oldfile.*\n'
106+ br'\+\+\+ newdir/newfile.*\n'
107+ br'\@\@ -1,1 \+0,0 \@\@\n'
108+ br'-old\n'
109+ br'\n')
110 self.assertContainsRe(self.differ.to_file.getvalue(),
111 b"=== target is 'new'\n")
112

Subscribers

People subscribed via source and target branches