/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 bzrlib/multiparent.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:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib.lazy_import import lazy_import
18
18
 
23
23
from StringIO import StringIO
24
24
 
25
25
from bzrlib import (
26
 
    errors,
27
26
    patiencediff,
28
27
    trace,
29
28
    ui,
30
29
    )
31
 
from bzrlib import bencode
 
30
from bzrlib.util import bencode
32
31
""")
33
32
from bzrlib.tuned_gzip import GzipFile
34
33
 
35
34
 
36
 
def topo_iter_keys(vf, keys=None):
37
 
    if keys is None:
38
 
        keys = vf.keys()
39
 
    parents = vf.get_parent_map(keys)
40
 
    return _topo_iter(parents, keys)
41
 
 
42
35
def topo_iter(vf, versions=None):
 
36
    seen = set()
 
37
    descendants = {}
43
38
    if versions is None:
44
39
        versions = vf.versions()
45
 
    parents = vf.get_parent_map(versions)
46
 
    return _topo_iter(parents, versions)
47
 
 
48
 
def _topo_iter(parents, versions):
49
 
    seen = set()
50
 
    descendants = {}
51
40
    def pending_parents(version):
52
 
        if parents[version] is None:
53
 
            return []
54
 
        return [v for v in parents[version] if v in versions and
 
41
        return [v for v in vf.get_parents(version) if v in versions and
55
42
                v not in seen]
56
43
    for version_id in versions:
57
 
        if parents[version_id] is None:
58
 
            # parentless
59
 
            continue
60
 
        for parent_id in parents[version_id]:
 
44
        for parent_id in vf.get_parents(version_id):
61
45
            descendants.setdefault(parent_id, []).append(version_id)
62
46
    cur = [v for v in versions if len(pending_parents(v)) == 0]
63
47
    while len(cur) > 0:
71
55
            yield version_id
72
56
            seen.add(version_id)
73
57
        cur = next
 
58
    assert len(seen) == len(versions)
74
59
 
75
60
 
76
61
class MultiParent(object):
208
193
            elif cur_line[0] == '\n':
209
194
                hunks[-1].lines[-1] += '\n'
210
195
            else:
211
 
                if not (cur_line[0] == 'c'):
212
 
                    raise AssertionError(cur_line[0])
 
196
                assert cur_line[0] == 'c', cur_line[0]
213
197
                parent, parent_pos, child_pos, num_lines =\
214
198
                    [int(v) for v in cur_line.split(' ')[1:]]
215
199
                hunks.append(ParentText(parent, parent_pos, child_pos,
290
274
            ' %(num_lines)r)' % self.__dict__
291
275
 
292
276
    def __eq__(self, other):
293
 
        if self.__class__ is not other.__class__:
 
277
        if self.__class__ != other.__class__:
294
278
            return False
295
279
        return (self.__dict__ == other.__dict__)
296
280
 
316
300
        return version in self._parents
317
301
 
318
302
    def do_snapshot(self, version_id, parent_ids):
319
 
        """Determine whether to perform a snapshot for this version"""
 
303
        """Determine whether to perform a a snapshot for this version"""
320
304
        if self.snapshot_interval is None:
321
305
            return False
322
306
        if self.max_snapshots is not None and\
384
368
        :param single_parent: If true, omit all but one parent text, (but
385
369
            retain parent metadata).
386
370
        """
387
 
        if not (no_cache or not verify):
388
 
            raise ValueError()
 
371
        assert no_cache or not verify
389
372
        revisions = set(vf.versions())
390
373
        total = len(revisions)
391
374
        pb = ui.ui_factory.nested_progress_bar()
397
380
                    if [p for p in parents if p not in self._parents] != []:
398
381
                        continue
399
382
                    lines = [a + ' ' + l for a, l in
400
 
                             vf.annotate(revision)]
 
383
                             vf.annotate_iter(revision)]
401
384
                    if snapshots is None:
402
385
                        force_snapshot = None
403
386
                    else:
409
392
                        self.clear_cache()
410
393
                        vf.clear_cache()
411
394
                        if verify:
412
 
                            if not (lines == self.get_line_list([revision])[0]):
413
 
                                raise AssertionError()
 
395
                            assert lines == self.get_line_list([revision])[0]
414
396
                            self.clear_cache()
415
397
                    pb.update('Importing revisions',
416
398
                              (total - len(revisions)) + len(added), total)
526
508
        self._parents[version_id] = parent_ids
527
509
 
528
510
    def get_diff(self, version_id):
529
 
        try:
530
 
            return self._diffs[version_id]
531
 
        except KeyError:
532
 
            raise errors.RevisionNotPresent(version_id, self)
 
511
        return self._diffs[version_id]
533
512
 
534
513
    def destroy(self):
535
514
        self._diffs = {}