Rev 3130: Sort diff results alphabetically in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Dec 19 21:17:34 GMT 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3130
revision-id:pqm at pqm.ubuntu.com-20071219211725-mgnpnt2keboqflwi
parent: pqm at pqm.ubuntu.com-20071219091053-81xgp971m1pgmccf
parent: abentley at panoramicfeedback.com-20071219201946-stemyt7hujf76w7p
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-12-19 21:17:25 +0000
message:
Sort diff results alphabetically
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3123.4.3
revision-id:abentley at panoramicfeedback.com-20071219201946-stemyt7hujf76w7p
parent: abentley at panoramicfeedback.com-20071219154601-c530qweqgev4z7x5
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Wed 2007-12-19 15:19:46 -0500
message:
Tweak path handling
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
------------------------------------------------------------
revno: 3123.4.2
revision-id:abentley at panoramicfeedback.com-20071219154601-c530qweqgev4z7x5
parent: aaron.bentley at utoronto.ca-20071218041534-w9spqi20zck44bvd
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: no-inventory2
timestamp: Wed 2007-12-19 10:46:01 -0500
message:
Handle diff with property change correctly
modified:
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
------------------------------------------------------------
revno: 3123.4.1
revision-id:aaron.bentley at utoronto.ca-20071218041534-w9spqi20zck44bvd
parent: pqm at pqm.ubuntu.com-20071217234754-hzi1en08nilnvh6s
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: no-inventory2
timestamp: Mon 2007-12-17 23:15:34 -0500
message:
Diff sorts files in alphabetical order
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
=== modified file 'NEWS'
--- a/NEWS 2007-12-19 08:06:07 +0000
+++ b/NEWS 2007-12-19 21:17:25 +0000
@@ -21,6 +21,8 @@
IMPROVEMENTS:
+ * ``bzr diff`` now sorts files in alphabetical order. (Aaron Bentley)
+
* ``bzr diff`` now works on branches without working trees. Tree-less
branches can also be compared to each other and to working trees using
the new diff options ``--old`` and ``--new``. Diffing between branches,
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py 2007-12-18 15:22:47 +0000
+++ b/bzrlib/diff.py 2007-12-19 21:17:25 +0000
@@ -813,45 +813,52 @@
"""
# TODO: Generation of pseudo-diffs for added/deleted files could
# be usefully made into a much faster special case.
-
- delta = self.new_tree.changes_from(self.old_tree,
- specific_files=specific_files,
- extra_trees=extra_trees, require_versioned=True)
-
+ iterator = self.new_tree._iter_changes(self.old_tree,
+ specific_files=specific_files,
+ extra_trees=extra_trees,
+ require_versioned=True)
has_changes = 0
- for path, file_id, kind in delta.removed:
- has_changes = 1
- path_encoded = path.encode(self.path_encoding, "replace")
- self.to_file.write("=== removed %s '%s'\n" % (kind, path_encoded))
- self.diff(file_id, path, path)
-
- for path, file_id, kind in delta.added:
- has_changes = 1
- path_encoded = path.encode(self.path_encoding, "replace")
- self.to_file.write("=== added %s '%s'\n" % (kind, path_encoded))
- self.diff(file_id, path, path)
- for (old_path, new_path, file_id, kind,
- text_modified, meta_modified) in delta.renamed:
- has_changes = 1
- prop_str = get_prop_change(meta_modified)
- oldpath_encoded = old_path.encode(self.path_encoding, "replace")
- newpath_encoded = new_path.encode(self.path_encoding, "replace")
- self.to_file.write("=== renamed %s '%s' => '%s'%s\n" % (kind,
- oldpath_encoded, newpath_encoded, prop_str))
- if text_modified:
- self.diff(file_id, old_path, new_path)
- for path, file_id, kind, text_modified, meta_modified in\
- delta.modified:
- has_changes = 1
- prop_str = get_prop_change(meta_modified)
- path_encoded = path.encode(self.path_encoding, "replace")
- self.to_file.write("=== modified %s '%s'%s\n" % (kind,
- path_encoded, prop_str))
- # The file may be in a different location in the old tree (because
- # the containing dir was renamed, but the file itself was not)
- if text_modified:
- old_path = self.old_tree.id2path(file_id)
- self.diff(file_id, old_path, path)
+ def changes_key(change):
+ old_path, new_path = change[1]
+ path = new_path
+ if path is None:
+ path = old_path
+ return path
+ def get_encoded_path(path):
+ if path is not None:
+ return path.encode(self.path_encoding, "replace")
+ for (file_id, paths, changed_content, versioned, parent, name, kind,
+ executable) in sorted(iterator, key=changes_key):
+ if parent == (None, None):
+ continue
+ oldpath, newpath = paths
+ oldpath_encoded = get_encoded_path(paths[0])
+ newpath_encoded = get_encoded_path(paths[1])
+ old_present = (kind[0] is not None and versioned[0])
+ new_present = (kind[1] is not None and versioned[1])
+ renamed = (parent[0], name[0]) != (parent[1], name[1])
+ prop_str = get_prop_change(executable[0] != executable[1])
+ if (old_present, new_present) == (True, False):
+ self.to_file.write("=== removed %s '%s'\n" %
+ (kind[0], oldpath_encoded))
+ newpath = oldpath
+ elif (old_present, new_present) == (False, True):
+ self.to_file.write("=== added %s '%s'\n" %
+ (kind[1], newpath_encoded))
+ oldpath = newpath
+ elif renamed:
+ self.to_file.write("=== renamed %s '%s' => '%s'%s\n" %
+ (kind[0], oldpath_encoded, newpath_encoded, prop_str))
+ else:
+ # if it was produced by _iter_changes, it must be
+ # modified *somehow*, either content or execute bit.
+ self.to_file.write("=== modified %s '%s'%s\n" % (kind[0],
+ newpath_encoded, prop_str))
+ if changed_content:
+ self.diff(file_id, oldpath, newpath)
+ has_changes = 1
+ if renamed:
+ has_changes = 1
return has_changes
def diff(self, file_id, old_path, new_path):
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2007-12-06 18:20:35 +0000
+++ b/bzrlib/tests/test_diff.py 2007-12-18 04:15:34 +0000
@@ -723,6 +723,15 @@
self.assertContainsRe(differ.to_file.getvalue(),
'was: old\nis: new\n')
+ def test_alphabetical_order(self):
+ self.build_tree(['new-tree/a-file'])
+ self.new_tree.add('a-file')
+ self.build_tree(['old-tree/b-file'])
+ self.old_tree.add('b-file')
+ self.differ.show_diff(None)
+ self.assertContainsRe(self.differ.to_file.getvalue(),
+ '.*a-file(.|\n)*b-file')
+
class TestPatienceDiffLib(TestCase):
More information about the bazaar-commits
mailing list