Rev 111: Merge bzr-foreign. in http://people.samba.org/bzr/jelmer/bzr-git/trunk

Jelmer Vernooij jelmer at samba.org
Mon Nov 10 16:20:17 GMT 2008


At http://people.samba.org/bzr/jelmer/bzr-git/trunk

------------------------------------------------------------
revno: 111
revision-id: jelmer at samba.org-20081110162016-41nffrsmw9knil2h
parent: jelmer at samba.org-20080910111436-89veglifyh2v9ate
parent: jelmer at samba.org-20081110161650-147q2c84jb754ukg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2008-11-10 17:20:16 +0100
message:
  Merge bzr-foreign.
modified:
  branch.py                      git_branch.py-20071108230535-su8dxk529f4uk9fx-2
  foreign/__init__.py            foreign.py-20080827193306-rxeku2c2obec90c4-1
  foreign/upgrade.py             upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
    ------------------------------------------------------------
    revno: 0.1.17
    revision-id: jelmer at samba.org-20081110161650-147q2c84jb754ukg
    parent: jelmer at samba.org-20081110161420-bax1raw5jkm1p67h
    parent: jelmer at samba.org-20081105201428-wdna6mc47zdeb0w6
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Mon 2008-11-10 17:16:50 +0100
    message:
      Merge trunk.
        ------------------------------------------------------------
        revno: 0.2.2
        revision-id: jelmer at samba.org-20081105201428-wdna6mc47zdeb0w6
        parent: jelmer at samba.org-20080930203134-76qinvlamxl3lstm
        committer: Jelmer Vernooij <jelmer at samba.org>
        branch nick: trunk
        timestamp: Wed 2008-11-05 21:14:28 +0100
        message:
          Import escape commit message function.
        modified:
          __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
        ------------------------------------------------------------
        revno: 0.2.1
        revision-id: jelmer at samba.org-20080930203134-76qinvlamxl3lstm
        parent: jelmer at samba.org-20080909154418-4512tlepljq72tn3
        committer: Jelmer Vernooij <jelmer at samba.org>
        branch nick: trunk
        timestamp: Tue 2008-09-30 22:31:34 +0200
        message:
          Add ForeignBranch class, make dpush fallback to regular push.
        modified:
          __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
    ------------------------------------------------------------
    revno: 0.1.16
    revision-id: jelmer at samba.org-20081110161420-bax1raw5jkm1p67h
    parent: jelmer at samba.org-20080909154418-4512tlepljq72tn3
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Mon 2008-11-10 17:14:20 +0100
    message:
      Import fixes from bzr-svn.
    modified:
      __init__.py                    foreign.py-20080827193306-rxeku2c2obec90c4-1
      upgrade.py                     upgrade.py-20080909124113-1j5ajrrwjp4x7z52-1
=== modified file 'branch.py'
--- a/branch.py	2008-08-29 15:58:12 +0000
+++ b/branch.py	2008-11-10 16:20:16 +0000
@@ -24,6 +24,7 @@
     )
 from bzrlib.decorators import needs_read_lock
 
+from bzrlib.plugins.git.foreign import ForeignBranch
 from bzrlib.plugins.git.mapping import default_mapping
 
 class GitTagDict(tag.BasicTags):
@@ -64,7 +65,7 @@
         return True
 
 
-class GitBranch(branch.Branch):
+class GitBranch(ForeignBranch):
     """An adapter to git repositories for bzr Branch objects."""
 
     def __init__(self, bzrdir, repository, head, base, lockfiles):

=== modified file 'foreign/__init__.py'
--- a/foreign/__init__.py	2008-09-09 15:44:18 +0000
+++ b/foreign/__init__.py	2008-11-10 16:16:50 +0000
@@ -17,7 +17,9 @@
 """Foreign branch utilities."""
 
 from bzrlib import errors, registry
+from bzrlib.branch import Branch
 from bzrlib.commands import Command, Option
+from bzrlib.trace import info
 
 
 class VcsMapping(object):
@@ -71,6 +73,16 @@
         return self.get(self._get_default_key())
 
 
+class ForeignBranch(Branch):
+
+    def __init__(self, mapping):
+        super(ForeignBranch, self).__init__()
+        self.mapping = mapping
+
+    def dpull(self, source, stop_revision=None):
+        raise NotImplementedError(self.pull)
+
+
 class FakeControlFiles(object):
     """Dummy implementation of ControlFiles.
     
@@ -132,7 +144,12 @@
         bzrdir = BzrDir.open(location)
         target_branch = bzrdir.open_branch()
         target_branch.lock_write()
-        revid_map = target_branch.dpull(source_branch)
+        if not isinstance(target_branch, ForeignBranch):
+            info("target branch is not a foreign branch, using regular push.")
+            target_branch.pull(source_branch)
+            no_rebase = True
+        else:
+            revid_map = target_branch.dpull(source_branch)
         # We successfully created the target, remember it
         if source_branch.get_push_location() is None or remember:
             source_branch.set_push_location(target_branch.base)
@@ -151,7 +168,30 @@
     from bzrlib.tests import TestUtil
     loader = TestUtil.TestLoader()
     suite = TestSuite()
+    import test_versionedfiles
     testmod_names = ['test_versionedfiles',]
     suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
     return suite
 
+def escape_commit_message(message):
+    """Replace xml-incompatible control characters."""
+    if message is None:
+        return None
+    import re
+    # FIXME: RBC 20060419 this should be done by the revision
+    # serialiser not by commit. Then we can also add an unescaper
+    # in the deserializer and start roundtripping revision messages
+    # precisely. See repository_implementations/test_repository.py
+    
+    # Python strings can include characters that can't be
+    # represented in well-formed XML; escape characters that
+    # aren't listed in the XML specification
+    # (http://www.w3.org/TR/REC-xml/#NT-Char).
+    message, _ = re.subn(
+        u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
+        lambda match: match.group(0).encode('unicode_escape'),
+        message)
+    return message
+
+
+

=== modified file 'foreign/upgrade.py'
--- a/foreign/upgrade.py	2008-09-09 12:59:14 +0000
+++ b/foreign/upgrade.py	2008-11-10 16:14:20 +0000
@@ -22,7 +22,6 @@
 
 import itertools
 
-
 class RebaseNotPresent(DependencyNotPresent):
     _fmt = "Unable to import bzr-rebase (required for upgrade support): %(error)s"
 
@@ -74,8 +73,10 @@
 def determine_fileid_renames(old_tree, new_tree):
     for old_file_id in old_tree:
         new_file_id = new_tree.path2id(old_tree.id2path(old_file_id))
+        if old_file_id == new_file_id:
+            continue
         if new_file_id is not None:
-            yield old_file_id, new_file_id
+            yield new_tree.id2path(new_file_id), old_file_id, new_file_id
 
 
 def upgrade_workingtree(wt, foreign_repository, new_mapping, mapping_registry, 
@@ -87,21 +88,55 @@
     wt.lock_write()
     try:
         old_revid = wt.last_revision()
-        renames = upgrade_branch(wt.branch, foreign_repository, new_mapping=new_mapping,
+        revid_renames = upgrade_branch(wt.branch, foreign_repository, new_mapping=new_mapping,
                                  mapping_registry=mapping_registry,
                                  allow_changes=allow_changes, verbose=verbose)
         last_revid = wt.branch.last_revision()
+        if old_revid == last_revid:
+            return revid_renames
+
+        fileid_renames = dict([(path, (old_fileid, new_fileid)) for (path, old_fileid, new_fileid) in determine_fileid_renames(wt.branch.repository.revision_tree(old_revid), wt.branch.repository.revision_tree(last_revid))])
+        old_fileids = []
+        new_fileids = []
+        new_root_id = None
+        # Adjust file ids in working tree
+        for path in sorted(fileid_renames.keys(), reverse=True):
+            if path != "":
+                old_fileids.append(fileid_renames[path][0])
+                new_fileids.append((path, fileid_renames[path][1]))
+            else:
+                new_root_id = fileid_renames[path][1]
+        new_fileids.reverse()
+        wt.unversion(old_fileids)
+        if new_root_id is not None:
+            wt.set_root_id(new_root_id)
+        wt.add([x[0] for x in new_fileids], [x[1] for x in new_fileids])
         wt.set_last_revision(last_revid)
-
-        # Adjust file ids in working tree
-        for (old_fileid, new_fileid) in determine_fileid_renames(wt.branch.repository.revision_tree(old_revid), wt.basis_tree()):
-            path = wt.id2path(old_fileid)
-            wt.remove(path)
-            wt.add([path], [new_fileid])
     finally:
         wt.unlock()
 
-    return renames
+    return revid_renames
+
+
+def upgrade_tags(tags, repository, foreign_repository, new_mapping, mapping_registry, 
+                 allow_changes=False, verbose=False, branch_renames=None):
+    """Upgrade a tags dictionary."""
+    pb = ui.ui_factory.nested_progress_bar()
+    try:
+        tags_dict = tags.get_tag_dict()
+        for i, (name, revid) in enumerate(tags_dict.items()):
+            pb.update("upgrading tags", i, len(tags_dict))
+            if branch_renames is not None and revid in branch_renames:
+                renames = branch_renames
+            else:
+                renames = upgrade_repository(repository, foreign_repository, 
+                      revision_id=revid, new_mapping=new_mapping,
+                      mapping_registry=mapping_registry,
+                      allow_changes=allow_changes, verbose=verbose)
+            if revid in renames:
+                tags.set_tag(name, renames[revid])
+    finally:
+        pb.finished()
 
 
 def upgrade_branch(branch, foreign_repository, new_mapping, 
@@ -118,6 +153,9 @@
               revision_id=revid, new_mapping=new_mapping,
               mapping_registry=mapping_registry,
               allow_changes=allow_changes, verbose=verbose)
+    upgrade_tags(branch.tags, branch.repository, foreign_repository, 
+           new_mapping=new_mapping, mapping_registry=mapping_registry, 
+           allow_changes=allow_changes, verbose=verbose)
     if len(renames) > 0:
         branch.generate_revision_history(renames[revid])
     return renames
@@ -144,11 +182,11 @@
              dictionary.
     """
     rename_map = {}
-    # Create a list of revisions that can be renamed during the upgade
+    # Create a list of revisions that can be renamed during the upgrade
     for revid in revs:
         assert isinstance(revid, str)
         try:
-            (foreign_revid, mapping) = mapping_registry.parse_revision_id(revid)
+            (foreign_revid, _) = mapping_registry.parse_revision_id(revid)
         except InvalidRevisionId:
             # Not a foreign revision, nothing to do
             continue
@@ -202,8 +240,7 @@
         heads = [revision_id]
 
     plan = generate_transpose_plan(graph.iter_ancestry(heads), upgrade_map, 
-      graph,
-      lambda revid: create_upgraded_revid(revid, new_mapping.upgrade_suffix))
+      graph, lambda revid: create_upgraded_revid(revid, new_mapping.upgrade_suffix))
     def remove_parents((oldrevid, (newrevid, parents))):
         return (oldrevid, newrevid)
     upgrade_map.update(dict(map(remove_parents, plan.items())))




More information about the bazaar-commits mailing list