Rev 4394: (Jelmer) Move showing of foreign revision info onto log, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jun 1 12:59:26 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4394
revision-id: pqm at pqm.ubuntu.com-20090601115923-dc69lgc44tj8mgc2
parent: pqm at pqm.ubuntu.com-20090530150110-c87w11jf6sqevh16
parent: jelmer at samba.org-20090601025534-6by2tezdu22j7f89
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-06-01 12:59:23 +0100
message:
  (Jelmer) Move showing of foreign revision info onto log,
  	for better performance.
modified:
  bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
  bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
  bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4393.1.2
    revision-id: jelmer at samba.org-20090601025534-6by2tezdu22j7f89
    parent: jelmer at samba.org-20090601022656-a4a6dvgs7j4lvgu7
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Mon 2009-06-01 04:55:34 +0200
    message:
      Move showing of foreign revision info onto log, for better performance.
    modified:
      bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4393.1.1
    revision-id: jelmer at samba.org-20090601022656-a4a6dvgs7j4lvgu7
    parent: pqm at pqm.ubuntu.com-20090530150110-c87w11jf6sqevh16
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Mon 2009-06-01 04:26:56 +0200
    message:
      Check for : in foreign revids early.
    modified:
      bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2009-05-23 04:55:52 +0000
+++ b/bzrlib/foreign.py	2009-06-01 02:55:34 +0000
@@ -119,25 +119,6 @@
         self.mapping = mapping
 
 
-def show_foreign_properties(rev):
-    """Custom log displayer for foreign revision identifiers.
-
-    :param rev: Revision object.
-    """
-    # Revision comes directly from a foreign repository
-    if isinstance(rev, ForeignRevision):
-        return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
-
-    # Revision was once imported from a foreign repository
-    try:
-        foreign_revid, mapping = \
-            foreign_vcs_registry.parse_revision_id(rev.revision_id)
-    except errors.InvalidRevisionId:
-        return {}
-
-    return mapping.vcs.show_foreign_revid(foreign_revid)
-
-
 class ForeignVcs(object):
     """A foreign version control system."""
 
@@ -179,7 +160,7 @@
         :param revid: The bzr revision id
         :return: tuple with foreign revid and vcs mapping
         """
-        if not "-" in revid:
+        if not ":" in revid or not "-" in revid:
             raise errors.InvalidRevisionId(revid, None)
         try:
             foreign_vcs = self.get(revid.split("-")[0])

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2009-04-20 08:37:32 +0000
+++ b/bzrlib/log.py	2009-06-01 02:55:34 +0000
@@ -69,6 +69,7 @@
     config,
     diff,
     errors,
+    foreign,
     repository as _mod_repository,
     revision as _mod_revision,
     revisionspec,
@@ -1366,14 +1367,42 @@
         else:
             return ''
 
+    def show_foreign_info(self, rev, indent):
+        """Custom log displayer for foreign revision identifiers.
+
+        :param rev: Revision object.
+        """
+        # Revision comes directly from a foreign repository
+        if isinstance(rev, foreign.ForeignRevision):
+            self._write_properties(indent, rev.mapping.vcs.show_foreign_revid(
+                rev.foreign_revid))
+            return
+
+        # Imported foreign revision revision ids always contain :
+        if not ":" in rev.revision_id:
+            return
+
+        # Revision was once imported from a foreign repository
+        try:
+            foreign_revid, mapping = \
+                foreign.foreign_vcs_registry.parse_revision_id(rev.revision_id)
+        except errors.InvalidRevisionId:
+            return
+
+        self._write_properties(indent, 
+            mapping.vcs.show_foreign_revid(foreign_revid))
+
     def show_properties(self, revision, indent):
         """Displays the custom properties returned by each registered handler.
 
         If a registered handler raises an error it is propagated.
         """
         for key, handler in properties_handler_registry.iteritems():
-            for key, value in handler(revision).items():
-                self.to_file.write(indent + key + ': ' + value + '\n')
+            self._write_properties(indent, handler(revision))
+
+    def _write_properties(self, indent, properties):
+        for key, value in properties.items():
+            self.to_file.write(indent + key + ': ' + value + '\n')
 
     def show_diff(self, to_file, diff, indent):
         for l in diff.rstrip().split('\n'):
@@ -1403,6 +1432,7 @@
             to_file.write('\n')
             for parent_id in revision.rev.parent_ids:
                 to_file.write(indent + 'parent: %s\n' % (parent_id,))
+        self.show_foreign_info(revision.rev, indent)
         self.show_properties(revision.rev, indent)
 
         committer = revision.rev.committer
@@ -1485,6 +1515,7 @@
                             self.show_timezone, date_fmt="%Y-%m-%d",
                             show_offset=False),
                 tags, self.merge_marker(revision)))
+        self.show_foreign_info(revision.rev, indent+offset)
         self.show_properties(revision.rev, indent+offset)
         if self.show_ids:
             to_file.write(indent + offset + 'revision-id:%s\n'
@@ -1901,9 +1932,6 @@
 
 
 properties_handler_registry = registry.Registry()
-properties_handler_registry.register_lazy("foreign",
-                                          "bzrlib.foreign",
-                                          "show_foreign_properties")
 
 
 # adapters which revision ids to log are filtered. When log is called, the

=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py	2009-05-23 04:55:52 +0000
+++ b/bzrlib/tests/test_foreign.py	2009-06-01 02:55:34 +0000
@@ -301,36 +301,6 @@
         self.assertEquals(mapp, rev.mapping)
 
 
-class ShowForeignPropertiesTests(TestCase):
-    """Tests for the show_foreign_properties() function."""
-
-    def setUp(self):
-        super(ShowForeignPropertiesTests, self).setUp()
-        self.vcs = DummyForeignVcs()
-        foreign.foreign_vcs_registry.register("dummy",
-            self.vcs, "Dummy VCS")
-
-    def tearDown(self):
-        super(ShowForeignPropertiesTests, self).tearDown()
-        foreign.foreign_vcs_registry.remove("dummy")
-
-    def test_show_non_foreign(self):
-        """Test use with a native (non-foreign) bzr revision."""
-        self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
-
-    def test_show_imported(self):
-        rev = Revision("dummy-v1:my-foreign-revid")
-        self.assertEquals({ "dummy ding": "my/foreign\\revid" },
-                          foreign.show_foreign_properties(rev))
-
-    def test_show_direct(self):
-        rev = foreign.ForeignRevision(("some", "foreign", "revid"),
-                                      DummyForeignVcsMapping(self.vcs),
-                                      "roundtrip-revid")
-        self.assertEquals({ "dummy ding": "some/foreign\\revid" },
-                          foreign.show_foreign_properties(rev))
-
-
 class WorkingTreeFileUpdateTests(TestCaseWithTransport):
     """Tests for update_workingtree_fileids()."""
 




More information about the bazaar-commits mailing list