Rev 2070: Merge bzr-foreign. in http://people.samba.org/bzr/jelmer/bzr-svn/0.5

Jelmer Vernooij jelmer at samba.org
Tue Nov 25 01:04:09 GMT 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/0.5

------------------------------------------------------------
revno: 2070
revision-id: jelmer at samba.org-20081125010407-8k1yhrxm9ydx4i91
parent: jelmer at samba.org-20081124232027-kogzqdcurj1inh6l
parent: jelmer at samba.org-20081125010300-eopsjg95uslhfeqw
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.5
timestamp: Tue 2008-11-25 02:04:07 +0100
message:
  Merge bzr-foreign.
modified:
  foreign/__init__.py            foreign.py-20080827193306-rxeku2c2obec90c4-1
    ------------------------------------------------------------
    revno: 0.6.8
    revision-id: jelmer at samba.org-20081125010300-eopsjg95uslhfeqw
    parent: jelmer at samba.org-20081125003332-60b0uol0fd7436gt
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Tue 2008-11-25 02:03:00 +0100
    message:
      Add more docstrings.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
    ------------------------------------------------------------
    revno: 0.6.7
    revision-id: jelmer at samba.org-20081125003332-60b0uol0fd7436gt
    parent: jelmer at samba.org-20081119131027-4895dyr5a5i28dum
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Tue 2008-11-25 01:33:32 +0100
    message:
      Merge improvements from bzr-svn.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
      upgrade.py                     upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
    ------------------------------------------------------------
    revno: 0.6.6
    revision-id: jelmer at samba.org-20081119131027-4895dyr5a5i28dum
    parent: jelmer at samba.org-20081112181618-jp45woeqhhfv80oy
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Wed 2008-11-19 14:10:27 +0100
    message:
      Only register foreign property show function once.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
    ------------------------------------------------------------
    revno: 0.6.5
    revision-id: jelmer at samba.org-20081112181618-jp45woeqhhfv80oy
    parent: jelmer at samba.org-20081112143610-30109vbbkeuj94y0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Wed 2008-11-12 19:16:18 +0100
    message:
      Merge bzr-svn improvements.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
    ------------------------------------------------------------
    revno: 0.6.4
    revision-id: jelmer at samba.org-20081112143610-30109vbbkeuj94y0
    parent: jelmer at samba.org-20081112111919-kicfbop2ucy7dxb0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Wed 2008-11-12 15:36:10 +0100
    message:
      import bzr-svn improvements.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
      upgrade.py                     upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
      versionedfiles.py              versionedfiles.py-20080829145632-midkv3h7msuyoibq-2
=== modified file 'foreign/__init__.py'
--- a/foreign/__init__.py	2008-11-21 14:29:04 +0000
+++ b/foreign/__init__.py	2008-11-25 01:04:07 +0000
@@ -16,13 +16,20 @@
 
 """Foreign branch utilities."""
 
-from bzrlib import errors, log, osutils, registry
 from bzrlib.branch import Branch
 from bzrlib.commands import Command, Option
-from bzrlib.errors import InvalidRevisionId
 from bzrlib.repository import Repository
 from bzrlib.revision import Revision
-from bzrlib.trace import info
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+from bzrlib import (
+    errors,
+    log,
+    osutils,
+    registry,
+    )
+""")
+
 
 class VcsMapping(object):
     """Describes the mapping between the semantics of Bazaar and a foreign vcs.
@@ -60,6 +67,7 @@
         :param foreign_revid: Foreign revision id.
         :return: Dictionary mapping string keys to string values.
         """
+        # TODO: This could be on ForeignVcs instead
         return { }
 
 
@@ -95,36 +103,6 @@
         raise NotImplementedError(self.revision_id_bzr_to_foreign)
 
 
-class ForeignVcs(object):
-    """A foreign version control system."""
-
-    def __init__(self, mapping_registry):
-        self.mapping_registry = mapping_registry
-
-
-class ForeignVcsRegistry(registry.Registry):
-    """Registry for Foreign VCSes.
-    
-    """
-
-    def register(self, key, foreign_vcs, help):
-        """Register a foreign VCS.
-
-        """
-        if ":" in key or "-" in key:
-            raise ValueError("vcs name can not contain : or -")
-        registry.Registry.register(self, key, foreign_vcs, help)
-
-    def parse_revision_id(self, revid):
-        if not "-" in revid:
-            raise InvalidRevisionId(revid, None)
-        try:
-            foreign_vcs = self.get(revid.split("-")[0])
-        except KeyError:
-            raise InvalidRevisionId(revid, None)
-        return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid)
-
-
 class ForeignBranch(Branch):
     """Branch that exists in a foreign version control system."""
 
@@ -136,7 +114,9 @@
         """Pull deltas from another branch.
 
         :note: This does not, like pull, retain the revision ids from 
-        the source branch.
+        the source branch and will, rather than adding bzr-specific metadata,
+        push only those semantics of the revision that can be natively 
+        represented in this branch.
 
         :param source: Source branch
         :param stop_revision: Revision to pull, defaults to last revision.
@@ -216,6 +196,7 @@
         from bzrlib import urlutils
         from bzrlib.bzrdir import BzrDir
         from bzrlib.errors import BzrCommandError, NoWorkingTree
+        from bzrlib.trace import info
         from bzrlib.workingtree import WorkingTree
 
         if directory is None:
@@ -314,12 +295,56 @@
 
     # Revision was once imported from a foreign repository
     try:
-        foreign_revid, mapping = foreign_vcs_registry.parse_revision_id(rev.revision_id)
-    except InvalidRevisionId:
+        foreign_revid, mapping = \
+            foreign_vcs_registry.parse_revision_id(rev.revision_id)
+    except errors.InvalidRevisionId:
         return {}
 
     return mapping.show_foreign_revid(foreign_revid)
 
+
+class ForeignVcs(object):
+    """A foreign version control system."""
+
+    def __init__(self, mapping_registry):
+        self.mapping_registry = mapping_registry
+
+
+class ForeignVcsRegistry(registry.Registry):
+    """Registry for Foreign VCSes.
+
+    There should be one entry per foreign VCS. Example entries would be 
+    "git", "svn", "hg", "darcs", etc.
+
+    """
+
+    def register(self, key, foreign_vcs, help):
+        """Register a foreign VCS.
+
+        :param key: Prefix of the foreign VCS in revision ids
+        :param foreign_vcs: ForeignVCS instance
+        :param help: Description of the foreign VCS
+        """
+        if ":" in key or "-" in key:
+            raise ValueError("vcs name can not contain : or -")
+        registry.Registry.register(self, key, foreign_vcs, help)
+
+    def parse_revision_id(self, revid):
+        """Parse a bzr revision and return the matching mapping and foreign 
+        revid.
+        
+        :param revid: The bzr revision id
+        :return: tuple with foreign revid and vcs mapping
+        """
+        if not "-" in revid:
+            raise errors.InvalidRevisionId(revid, None)
+        try:
+            foreign_vcs = self.get(revid.split("-")[0])
+        except KeyError:
+            raise errors.InvalidRevisionId(revid, None)
+        return foreign_vcs.mapping_registry.revision_id_bzr_to_foreign(revid)
+
+
 if not "foreign" in log.properties_handler_registry:
     log.properties_handler_registry.register("foreign",
                                              show_foreign_properties,




More information about the bazaar-commits mailing list