/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 tests/test_builder.py

  • 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
 
# Copyright (C) 2007 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
"""Test our ability to build up test repositories"""
18
 
 
19
 
from cStringIO import StringIO
20
 
 
21
 
from bzrlib.plugins.git import tests
22
 
 
23
 
 
24
 
class TestGitBranchBuilder(tests.TestCase):
25
 
 
26
 
    def test__create_blob(self):
27
 
        stream = StringIO()
28
 
        builder = tests.GitBranchBuilder(stream)
29
 
        self.assertEqual(1, builder._create_blob('foo\nbar\n'))
30
 
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
31
 
                             stream.getvalue())
32
 
 
33
 
    def test_set_file(self):
34
 
        stream = StringIO()
35
 
        builder = tests.GitBranchBuilder(stream)
36
 
        builder.set_file('foobar', 'foo\nbar\n', False)
37
 
        self.assertEqualDiff('blob\nmark :1\ndata 8\nfoo\nbar\n\n',
38
 
                             stream.getvalue())
39
 
        self.assertEqual(['M 100644 :1 foobar\n'], builder.commit_info)
40
 
 
41
 
    def test_set_file_unicode(self):
42
 
        stream = StringIO()
43
 
        builder = tests.GitBranchBuilder(stream)
44
 
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
45
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
46
 
                             stream.getvalue())
47
 
        self.assertEqual(['M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
48
 
 
49
 
    def test_set_file_newline(self):
50
 
        stream = StringIO()
51
 
        builder = tests.GitBranchBuilder(stream)
52
 
        builder.set_file(u'foo\nbar', 'contents\nbar\n', False)
53
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
54
 
                             stream.getvalue())
55
 
        self.assertEqual(['M 100644 :1 "foo\\nbar"\n'], builder.commit_info)
56
 
 
57
 
    def test_set_file_executable(self):
58
 
        stream = StringIO()
59
 
        builder = tests.GitBranchBuilder(stream)
60
 
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', True)
61
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n',
62
 
                             stream.getvalue())
63
 
        self.assertEqual(['M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
64
 
 
65
 
    def test_set_link(self):
66
 
        stream = StringIO()
67
 
        builder = tests.GitBranchBuilder(stream)
68
 
        builder.set_link(u'f\xb5/bar', 'link/contents')
69
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
70
 
                             stream.getvalue())
71
 
        self.assertEqual(['M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
72
 
 
73
 
    def test_set_link_newline(self):
74
 
        stream = StringIO()
75
 
        builder = tests.GitBranchBuilder(stream)
76
 
        builder.set_link(u'foo\nbar', 'link/contents')
77
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\nlink/contents\n',
78
 
                             stream.getvalue())
79
 
        self.assertEqual(['M 120000 :1 "foo\\nbar"\n'], builder.commit_info)
80
 
 
81
 
    def test_delete_entry(self):
82
 
        stream = StringIO()
83
 
        builder = tests.GitBranchBuilder(stream)
84
 
        builder.delete_entry(u'path/to/f\xb5')
85
 
        self.assertEqual(['D path/to/f\xc2\xb5\n'], builder.commit_info)
86
 
 
87
 
    def test_delete_entry_newline(self):
88
 
        stream = StringIO()
89
 
        builder = tests.GitBranchBuilder(stream)
90
 
        builder.delete_entry(u'path/to/foo\nbar')
91
 
        self.assertEqual(['D "path/to/foo\\nbar"\n'], builder.commit_info)
92
 
 
93
 
    def test_encode_path(self):
94
 
        encode = tests.GitBranchBuilder._encode_path
95
 
        # Unicode is encoded to utf-8
96
 
        self.assertEqual(encode(u'f\xb5'), 'f\xc2\xb5')
97
 
        # The name must be quoted if it starts by a double quote or contains a
98
 
        # newline.
99
 
        self.assertEqual(encode(u'"foo'), '"\\"foo"')
100
 
        self.assertEqual(encode(u'fo\no'), '"fo\\no"')
101
 
        # When the name is quoted, all backslash and quote chars must be
102
 
        # escaped.
103
 
        self.assertEqual(encode(u'fo\\o\nbar'), '"fo\\\\o\\nbar"')
104
 
        self.assertEqual(encode(u'fo"o"\nbar'), '"fo\\"o\\"\\nbar"')
105
 
        # Other control chars, such as \r, need not be escaped.
106
 
        self.assertEqual(encode(u'foo\r\nbar'), '"foo\r\\nbar"')
107
 
 
108
 
    def test_add_and_commit(self):
109
 
        stream = StringIO()
110
 
        builder = tests.GitBranchBuilder(stream)
111
 
 
112
 
        builder.set_file(u'f\xb5/bar', 'contents\nbar\n', False)
113
 
        self.assertEqual(2, builder.commit('Joe Foo <joe@foo.com>',
114
 
                                           u'committing f\xb5/bar',
115
 
                                           timestamp=1194586400,
116
 
                                           timezone='+0100'))
117
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nbar\n\n'
118
 
                             'commit refs/heads/master\n'
119
 
                             'mark :2\n'
120
 
                             'committer Joe Foo <joe@foo.com> 1194586400 +0100\n'
121
 
                             'data 18\n'
122
 
                             'committing f\xc2\xb5/bar'
123
 
                             '\n'
124
 
                             'M 100644 :1 f\xc2\xb5/bar\n'
125
 
                             '\n',
126
 
                             stream.getvalue())
127
 
 
128
 
    def test_commit_base(self):
129
 
        stream = StringIO()
130
 
        builder = tests.GitBranchBuilder(stream)
131
 
 
132
 
        builder.set_file(u'foo', 'contents\nfoo\n', False)
133
 
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
134
 
                            timestamp=1194586400)
135
 
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
136
 
                            timestamp=1194586405)
137
 
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
138
 
                            timestamp=1194586410,
139
 
                            base=r1)
140
 
 
141
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
142
 
                             'commit refs/heads/master\n'
143
 
                             'mark :2\n'
144
 
                             'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
145
 
                             'data 5\n'
146
 
                             'first'
147
 
                             '\n'
148
 
                             'M 100644 :1 foo\n'
149
 
                             '\n'
150
 
                             'commit refs/heads/master\n'
151
 
                             'mark :3\n'
152
 
                             'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
153
 
                             'data 6\n'
154
 
                             'second'
155
 
                             '\n'
156
 
                             '\n'
157
 
                             'commit refs/heads/master\n'
158
 
                             'mark :4\n'
159
 
                             'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
160
 
                             'data 5\n'
161
 
                             'third'
162
 
                             '\n'
163
 
                             'from :2\n'
164
 
                             '\n', stream.getvalue())
165
 
 
166
 
    def test_commit_merge(self):
167
 
        stream = StringIO()
168
 
        builder = tests.GitBranchBuilder(stream)
169
 
 
170
 
        builder.set_file(u'foo', 'contents\nfoo\n', False)
171
 
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
172
 
                            timestamp=1194586400)
173
 
        r2 = builder.commit('Joe Foo <joe@foo.com>', u'second',
174
 
                            timestamp=1194586405)
175
 
        r3 = builder.commit('Joe Foo <joe@foo.com>', u'third',
176
 
                            timestamp=1194586410,
177
 
                            base=r1)
178
 
        r4 = builder.commit('Joe Foo <joe@foo.com>', u'Merge',
179
 
                            timestamp=1194586415,
180
 
                            merge=[r2])
181
 
 
182
 
        self.assertEqualDiff('blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
183
 
                             'commit refs/heads/master\n'
184
 
                             'mark :2\n'
185
 
                             'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
186
 
                             'data 5\n'
187
 
                             'first'
188
 
                             '\n'
189
 
                             'M 100644 :1 foo\n'
190
 
                             '\n'
191
 
                             'commit refs/heads/master\n'
192
 
                             'mark :3\n'
193
 
                             'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
194
 
                             'data 6\n'
195
 
                             'second'
196
 
                             '\n'
197
 
                             '\n'
198
 
                             'commit refs/heads/master\n'
199
 
                             'mark :4\n'
200
 
                             'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
201
 
                             'data 5\n'
202
 
                             'third'
203
 
                             '\n'
204
 
                             'from :2\n'
205
 
                             '\n'
206
 
                             'commit refs/heads/master\n'
207
 
                             'mark :5\n'
208
 
                             'committer Joe Foo <joe@foo.com> 1194586415 +0000\n'
209
 
                             'data 5\n'
210
 
                             'Merge'
211
 
                             '\n'
212
 
                             'merge :3\n'
213
 
                             '\n', stream.getvalue())
214
 
 
215
 
    def test_auto_timestamp(self):
216
 
        stream = StringIO()
217
 
        builder = tests.GitBranchBuilder(stream)
218
 
        builder.commit('Joe Foo <joe@foo.com>', u'message')
219
 
        self.assertContainsRe(stream.getvalue(),
220
 
                              r'committer Joe Foo <joe@foo\.com> \d+ \+0000')
221
 
 
222
 
    def test_reset(self):
223
 
        stream = StringIO()
224
 
        builder = tests.GitBranchBuilder(stream)
225
 
        builder.reset()
226
 
        self.assertEqualDiff('reset refs/heads/master\n\n', stream.getvalue())
227
 
 
228
 
    def test_reset_named_ref(self):
229
 
        stream = StringIO()
230
 
        builder = tests.GitBranchBuilder(stream)
231
 
        builder.reset('refs/heads/branch')
232
 
        self.assertEqualDiff('reset refs/heads/branch\n\n', stream.getvalue())
233
 
 
234
 
    def test_reset_revision(self):
235
 
        stream = StringIO()
236
 
        builder = tests.GitBranchBuilder(stream)
237
 
        builder.reset(mark=123)
238
 
        self.assertEqualDiff(
239
 
            'reset refs/heads/master\n'
240
 
            'from :123\n'
241
 
            '\n', stream.getvalue())
242
 
 
243
 
 
244
 
class TestGitBranchBuilderReal(tests.TestCaseInTempDir):
245
 
 
246
 
    def test_create_real_branch(self):
247
 
        tests.run_git('init')
248
 
 
249
 
        builder = tests.GitBranchBuilder()
250
 
        builder.set_file(u'foo', 'contents\nfoo\n', False)
251
 
        r1 = builder.commit('Joe Foo <joe@foo.com>', u'first',
252
 
                            timestamp=1194586400)
253
 
        mapping = builder.finish()
254
 
        self.assertEqual({1:'44411e8e9202177dd19b6599d7a7991059fa3cb4',
255
 
                          2: 'b0b62e674f67306fddcf72fa888c3b56df100d64',
256
 
                         }, mapping)