/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to patches/ndiff.patch

  • Committer: Robert Collins
  • Date: 2008-01-06 20:04:22 UTC
  • mto: (3221.11.1 StackableBranch)
  • mto: This revision was merged to the branch mainline in revision 3226.
  • Revision ID: robertc@robertcollins.net-20080106200422-x8yz6cxotlzltvwp
The bzrdir format registry now accepts an ``alias`` keyword to
register_metadir, used to indicate that a format name is an alias for
some other format and thus should not be reported when describing the
format. (Robert Collins)
-------------- This line and the fmllowing will be ignored --------------

modified:
  NEWS
  bzrlib/bzrdir.py
  bzrlib/info.py
  bzrlib/tests/test_bzrdir.py
  bzrlib/tests/test_info.py

=== modified file 'NEWS'
--- a/NEWS      2008-01-02 22:30:46 +0000
+++ b/NEWS      2008-01-06 20:04:15 +0000
@@ -135,6 +135,11 @@
     * Patience Diff now supports arbitrary python objects, as long as they
       support ``hash()``. (John Arbash Meinel)
 
+    * The bzrdir format registry now accepts an ``alias`` keyword to
+      register_metadir, used to indicate that a format name is an alias for
+      some other format and thus should not be reported when describing the
+      format. (Robert Collins)
+
   API BREAKS:
 
   TESTING:

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py  2008-01-02 22:30:46 +0000
+++ b/bzrlib/bzrdir.py  2008-01-06 19:41:29 +0000
@@ -2447,12 +2447,22 @@
     e.g. BzrDirMeta1 with weave repository.  Also, it's more user-oriented.
     """
 
+    def __init__(self):
+        """Create a BzrDirFormatRegistry."""
+        self._aliases = set()
+        super(BzrDirFormatRegistry, self).__init__()
+
+    def aliases(self):
+        """Return a set of the format names which are aliases."""
+        return frozenset(self._aliases)
+
     def register_metadir(self, key,
              repository_format, help, native=True, deprecated=False,
              branch_format=None,
              tree_format=None,
              hidden=False,
-             experimental=False):
+             experimental=False,
+             alias=False):
         """Register a metadir subformat.
 
         These all use a BzrDirMetaFormat1 bzrdir, but can be parameterized
@@ -2491,10 +2501,10 @@
                 bd.repository_format = _load(repository_format)
             return bd
         self.register(key, helper, help, native, deprecated, hidden,
-            experimental)
+            experimental, alias)
 
     def register(self, key, factory, help, native=True, deprecated=False,
-                 hidden=False, experimental=False):
+                 hidden=False, experimental=False, alias=False):
         """Register a BzrDirFormat factory.
         
         The factory must be a callable that takes one parameter: the key.
@@ -2505,11 +2515,15 @@
         """
         registry.Registry.register(self, key, factory, help,
             BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def register_lazy(self, key, module_name, member_name, help, native=True,
-                      deprecated=False, hidden=False, experimental=False):
+        deprecated=False, hidden=False, experimental=False, alias=False):
         registry.Registry.register_lazy(self, key, module_name, member_name,
             help, BzrDirFormatInfo(native, deprecated, hidden, experimental))
+        if alias:
+            self._aliases.add(key)
 
     def set_default(self, key):
         """Set the 'default' key to be a clone of the supplied key.
@@ -2518,6 +2532,7 @@
         """
         registry.Registry.register(self, 'default', self.get(key),
             self.get_help(key), info=self.get_info(key))
+        self._aliases.add('default')
 
     def set_default_repository(self, key):
         """Set the FormatRegistry default and Repository default.
@@ -2670,6 +2685,7 @@
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     hidden=False,
     )
+# The following two formats should always just be aliases.
 format_registry.register_metadir('development',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Current development format. Can convert data to and from pack-0.92 '
@@ -2681,6 +2697,7 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
 format_registry.register_metadir('development-subtree',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0Subtree',
@@ -2693,7 +2710,9 @@
     branch_format='bzrlib.branch.BzrBranchFormat6',
     tree_format='bzrlib.workingtree.WorkingTreeFormat4',
     experimental=True,
+    alias=True,
     )
+# And the development formats which the will have aliased one of follow:
 format_registry.register_metadir('development0',
     'bzrlib.repofmt.pack_repo.RepositoryFormatPackDevelopment0',
     help='Trivial rename of pack-0.92 to provide a development format. '

=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py    2007-11-06 09:00:25 +0000
+++ b/bzrlib/info.py    2008-01-06 20:01:30 +0000
@@ -440,7 +440,9 @@
         tree.bzrdir.root_transport.base):
         branch = None
         repository = None
-    for key in bzrdir.format_registry.keys():
+    non_aliases = set(bzrdir.format_registry.keys())
+    non_aliases.difference_update(bzrdir.format_registry.aliases())
+    for key in non_aliases:
         format = bzrdir.format_registry.make_bzrdir(key)
         if isinstance(format, bzrdir.BzrDirMetaFormat1):
             if (tree and format.workingtree_format !=
@@ -457,11 +459,12 @@
         candidates.append(key)
     if len(candidates) == 0:
         return 'unnamed'
-    new_candidates = [c for c in candidates if c != 'default']
-    if len(new_candidates) > 0:
-        candidates = new_candidates
+    candidates.sort()
     new_candidates = [c for c in candidates if not
         bzrdir.format_registry.get_info(c).hidden]
     if len(new_candidates) > 0:
+        # If there are any non-hidden formats that match, only return those to
+        # avoid listing hidden formats except when only a hidden format will
+        # do.
         candidates = new_candidates
     return ' or '.join(candidates)

=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py       2007-12-21 20:32:22 +0000
+++ b/bzrlib/tests/test_bzrdir.py       2008-01-06 19:45:00 +0000
@@ -170,6 +170,16 @@
         finally:
             bzrdir.format_registry.set_default_repository(old_default)
 
+    def test_aliases(self):
+        a_registry = bzrdir.BzrDirFormatRegistry()
+        a_registry.register('weave', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True)
+        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
+            'Pre-0.8 format.  Slower and does not support checkouts or shared'
+            ' repositories', deprecated=True, alias=True)
+        self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
+    
 
 class SampleBranch(bzrlib.branch.Branch):
     """A dummy branch for guess what, dummy use."""

=== modified file 'bzrlib/tests/test_info.py'
--- a/bzrlib/tests/test_info.py 2007-11-26 13:55:51 +0000
+++ b/bzrlib/tests/test_info.py 2008-01-06 20:02:10 +0000
@@ -126,16 +126,22 @@
 
     def test_describe_tree_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             self.assertTreeDescription(key)
 
     def test_describe_checkout_format(self):
         for key in bzrdir.format_registry.keys():
-            if key in ('default', 'weave', 'experimental'):
-                continue
-            if key.startswith('experimental-'):
-                # these are typically hidden or aliases for other formats
+            if key in bzrdir.format_registry.aliases():
+                # Aliases will not describe correctly in the UI because the
+                # real format is found.
+                continue
+            # legacy: weave does not support checkouts
+            if key == 'weave':
+                continue
+            if bzrdir.format_registry.get_info(key).experimental:
+                # We don't require that experimental formats support checkouts
+                # or describe correctly in the UI.
                 continue
             expected = None
             if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
@@ -149,7 +155,7 @@
 
     def test_describe_branch_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit'):
@@ -158,7 +164,7 @@
 
     def test_describe_repo_format(self):
         for key in bzrdir.format_registry.keys():
-            if key == 'default':
+            if key in bzrdir.format_registry.aliases():
                 continue
             expected = None
             if key in ('dirstate', 'knit', 'dirstate-tags'):

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
*** modified file 'bzrlib/commands.py'
2
 
--- bzrlib/commands.py 
3
 
+++ bzrlib/commands.py 
4
 
@@ -721,10 +721,11 @@
5
 
     """
6
 
     
7
 
     takes_args = ['file*']
8
 
-    takes_options = ['revision', 'diff-options']
9
 
+    takes_options = ['revision', 'diff-options', 'ndiff']
10
 
     aliases = ['di', 'dif']
11
 
 
12
 
-    def run(self, revision=None, file_list=None, diff_options=None):
13
 
+    def run(self, revision=None, file_list=None, diff_options=None,
14
 
+            ndiff=None):
15
 
         from bzrlib.diff import show_diff
16
 
 
17
 
         if file_list:
18
 
@@ -735,9 +736,15 @@
19
 
                 file_list = None
20
 
         else:
21
 
             b = find_branch('.')
22
 
-    
23
 
+
24
 
+        if ndiff:
25
 
+            format = 'ndiff'
26
 
+        else:
27
 
+            format = None
28
 
+
29
 
         show_diff(b, revision, specific_files=file_list,
30
 
-                  external_diff_options=diff_options)
31
 
+                  external_diff_options=diff_options,
32
 
+                  format=format)
33
 
 
34
 
 
35
 
         
36
 
@@ -1344,6 +1351,7 @@
37
 
     'format':                 unicode,
38
 
     'forward':                None,
39
 
     'message':                unicode,
40
 
+    'ndiff':                  None,
41
 
     'no-recurse':             None,
42
 
     'profile':                None,
43
 
     'revision':               _parse_revision_str,
44
 
 
45
 
*** modified file 'bzrlib/diff.py'
46
 
--- bzrlib/diff.py 
47
 
+++ bzrlib/diff.py 
48
 
@@ -70,6 +70,13 @@
49
 
     print >>to_file
50
 
 
51
 
 
52
 
+
53
 
+def internal_ndiff(old_label, oldlines,
54
 
+                   new_label, newlines,
55
 
+                   to_file):
56
 
+    """Show diff in python-specific ndiff format."""
57
 
+    from difflib import ndiff
58
 
+    to_file.writelines(ndiff(oldlines, newlines))
59
 
 
60
 
 
61
 
 def external_diff(old_label, oldlines, new_label, newlines, to_file,
62
 
@@ -152,7 +159,8 @@
63
 
     
64
 
 
65
 
 
66
 
-def show_diff(b, revision, specific_files, external_diff_options=None):
67
 
+def show_diff(b, revision, specific_files, external_diff_options=None,
68
 
+              format=None):
69
 
     """Shortcut for showing the diff to the working tree.
70
 
 
71
 
     b
72
 
@@ -160,6 +168,9 @@
73
 
 
74
 
     revision
75
 
         None for each, or otherwise the old revision to compare against.
76
 
+
77
 
+    format
78
 
+        'unified', 'context', 'ndiff', 'external'
79
 
     
80
 
     The more general form is show_diff_trees(), where the caller
81
 
     supplies any two trees.
82
 
@@ -174,12 +185,13 @@
83
 
     new_tree = b.working_tree()
84
 
 
85
 
     show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
86
 
-                    external_diff_options)
87
 
+                    external_diff_options, format)
88
 
 
89
 
 
90
 
 
91
 
 def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
92
 
-                    external_diff_options=None):
93
 
+                    external_diff_options=None,
94
 
+                    format=None):
95
 
     """Show in text form the changes from one tree to another.
96
 
 
97
 
     to_files
98
 
@@ -204,10 +216,12 @@
99
 
     if external_diff_options:
100
 
         assert isinstance(external_diff_options, basestring)
101
 
         opts = external_diff_options.split()
102
 
-        def diff_file(olab, olines, nlab, nlines, to_file):
103
 
+        def diff_fn(olab, olines, nlab, nlines, to_file):
104
 
             external_diff(olab, olines, nlab, nlines, to_file, opts)
105
 
+    elif format == 'ndiff':
106
 
+        diff_fn = internal_ndiff
107
 
     else:
108
 
-        diff_file = internal_diff
109
 
+        diff_fn = internal_diff
110
 
     
111
 
 
112
 
     delta = compare_trees(old_tree, new_tree, want_unchanged=False,
113
 
@@ -216,7 +230,7 @@
114
 
     for path, file_id, kind in delta.removed:
115
 
         print >>to_file, '*** removed %s %r' % (kind, path)
116
 
         if kind == 'file':
117
 
-            diff_file(old_label + path,
118
 
+            diff_fn(old_label + path,
119
 
                       old_tree.get_file(file_id).readlines(),
120
 
                       DEVNULL, 
121
 
                       [],
122
 
@@ -225,7 +239,7 @@
123
 
     for path, file_id, kind in delta.added:
124
 
         print >>to_file, '*** added %s %r' % (kind, path)
125
 
         if kind == 'file':
126
 
-            diff_file(DEVNULL,
127
 
+            diff_fn(DEVNULL,
128
 
                       [],
129
 
                       new_label + path,
130
 
                       new_tree.get_file(file_id).readlines(),
131
 
@@ -234,7 +248,7 @@
132
 
     for old_path, new_path, file_id, kind, text_modified in delta.renamed:
133
 
         print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
134
 
         if text_modified:
135
 
-            diff_file(old_label + old_path,
136
 
+            diff_fn(old_label + old_path,
137
 
                       old_tree.get_file(file_id).readlines(),
138
 
                       new_label + new_path,
139
 
                       new_tree.get_file(file_id).readlines(),
140
 
@@ -243,7 +257,7 @@
141
 
     for path, file_id, kind in delta.modified:
142
 
         print >>to_file, '*** modified %s %r' % (kind, path)
143
 
         if kind == 'file':
144
 
-            diff_file(old_label + path,
145
 
+            diff_fn(old_label + path,
146
 
                       old_tree.get_file(file_id).readlines(),
147
 
                       new_label + path,
148
 
                       new_tree.get_file(file_id).readlines(),
149