Rev 2317: Merge 0.5. in file:///data/jelmer/bzr-svn/fileids/

Jelmer Vernooij jelmer at samba.org
Sat Jan 17 00:07:19 GMT 2009


At file:///data/jelmer/bzr-svn/fileids/

------------------------------------------------------------
revno: 2317
revision-id: jelmer at samba.org-20090117000710-6tgdrex7feze7gl0
parent: jelmer at samba.org-20090116222449-lizhi6puv0a2xy9j
parent: jelmer at samba.org-20090116235749-qf3wl555yvvi44sv
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: fileids
timestamp: Sat 2009-01-17 01:07:10 +0100
message:
  Merge 0.5.
modified:
  fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  tests/mapping3/__init__.py     __init__.py-20080831152358-oy04n53cpnh64aj6-1
    ------------------------------------------------------------
    revno: 2314.1.6
    revision-id: jelmer at samba.org-20090116235749-qf3wl555yvvi44sv
    parent: jelmer at samba.org-20090116233016-a60u9ewrcjrcek8q
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.5
    timestamp: Sat 2009-01-17 00:57:49 +0100
    message:
      Clarify docstrings, avoid regenerating foreign revid unnecessarily.
    modified:
      fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
    ------------------------------------------------------------
    revno: 2314.1.5
    revision-id: jelmer at samba.org-20090116233016-a60u9ewrcjrcek8q
    parent: jelmer at samba.org-20090116232138-ul9hz19qh8fz2s6q
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.5
    timestamp: Sat 2009-01-17 00:30:16 +0100
    message:
      Remove unnecessary code.
    modified:
      fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
    ------------------------------------------------------------
    revno: 2314.1.4
    revision-id: jelmer at samba.org-20090116232138-ul9hz19qh8fz2s6q
    parent: jelmer at samba.org-20090116230555-iokv10kr0o5a8bb4
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.5
    timestamp: Sat 2009-01-17 00:21:38 +0100
    message:
      Simplify file id handling.
    modified:
      fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
    ------------------------------------------------------------
    revno: 2314.1.3
    revision-id: jelmer at samba.org-20090116230555-iokv10kr0o5a8bb4
    parent: jelmer at samba.org-20090116223758-q8s83nefqij0y8b0
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.5
    timestamp: Sat 2009-01-17 00:05:55 +0100
    message:
      Fix test.
    modified:
      tests/mapping3/__init__.py     __init__.py-20080831152358-oy04n53cpnh64aj6-1
    ------------------------------------------------------------
    revno: 2314.1.2
    revision-id: jelmer at samba.org-20090116223758-q8s83nefqij0y8b0
    parent: jelmer at samba.org-20090116222209-aechpsghe1m96mg2
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: 0.5
    timestamp: Fri 2009-01-16 23:37:58 +0100
    message:
      Remove apply_changes to get_idmap_delta.
    modified:
      fetch.py                       fetch.py-20060625004942-x2lfaib8ra707a8p-1
      fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
=== modified file 'fetch.py'
--- a/fetch.py	2009-01-16 22:22:09 +0000
+++ b/fetch.py	2009-01-16 22:37:58 +0000
@@ -581,7 +581,7 @@
         if self._id_map is not None:
             return self._id_map
 
-        self._id_map = self.source.fileid_map.apply_changes(self.revmeta, 
+        self._id_map = self.source.fileid_map.get_idmap_delta(self.revmeta, 
             self.mapping)[0]
 
         return self._id_map

=== modified file 'fileids.py'
--- a/fileids.py	2009-01-16 22:24:49 +0000
+++ b/fileids.py	2009-01-17 00:07:10 +0000
@@ -32,6 +32,36 @@
         iter_with_mapping,
         )
 
+
+def apply_idmap_delta(map, revid, delta, changes):
+    """Update a file id map.
+
+    :param map: Existing file id map that needs to be updated
+    :param revid: Revision id of the id map
+    :param delta: Id map delta.
+    :param changes: Changes for the revision in question.
+    """
+    for p in changes:
+        inv_p = p.decode("utf-8")
+        if changes[p][0] == 'M' and not delta.has_key(p):
+            delta[inv_p] = map[inv_p][0]
+    
+    for x in sorted(delta.keys(), reverse=True):
+        assert isinstance(x, unicode)
+        if delta[x] is None:
+            del map[x]
+            for p in map.keys():
+                if p.startswith(u"%s/" % x):
+                    del map[p]
+
+    for x in sorted(delta.keys()):
+        if (delta[x] is not None and 
+            # special case - we change metadata in svn at the branch root path
+            # but that's not reflected as a bzr metadata change in bzr
+            (x != "" or not "" in map or map[x][1] == NULL_REVISION)):
+            map[x] = (str(delta[x]), revid)
+
+
 def get_local_changes(paths, branch, mapping, layout, generate_revid):
     """Obtain all of the changes relative to a particular path
     (usually a branch path).
@@ -45,6 +75,7 @@
     if (branch in paths and 
         paths[branch][0] == 'A' and 
         paths[branch][1] is None):
+        # Avoid finding all file ids
         return {}
     new_paths = {}
     for p in sorted(paths.keys(), reverse=False):
@@ -106,27 +137,32 @@
         self.apply_changes_fn = apply_changes_fn
         self.repos = repos
 
-    def _use_text_revids(self, mapping, revmeta, map):
-        for path, revid in revmeta.get_text_revisions(mapping).iteritems():
-            assert path in map
-            map[path] = (map[path][0], revid)
-
-    def apply_changes(self, map, revmeta, mapping):
+    def get_idmap_delta(self, revmeta, mapping):
         """Change file id map to incorporate specified changes.
 
         :param revmeta: RevisionMetadata object for revision with changes
+        :param renames: List of renames (known file ids for particular paths)
         :param mapping: Mapping
         """
         changes = get_local_changes(revmeta.get_paths(mapping), revmeta.branch_path, mapping,
                     self.repos.get_layout(),
                     self.repos.generate_revision_id)
 
+        foreign_revid = revmeta.get_foreign_revid()
         def new_file_id(x):
-            return mapping.generate_file_id(revmeta.get_foreign_revid(), x)
+            return mapping.generate_file_id(foreign_revid, x)
          
         idmap = self.apply_changes_fn(new_file_id, changes)
         idmap.update(revmeta.get_fileid_map(mapping))
-        self.update_map(map, revmeta.get_revision_id(mapping), idmap, changes)
+        return (idmap, changes)
+
+    def update_idmap(self, map, revmeta, mapping):
+        (idmap, changes) = self.get_idmap_delta(revmeta, 
+                mapping)
+        apply_idmap_delta(map, revmeta.get_revision_id(mapping), idmap, changes)
+        for path, revid in revmeta.get_text_revisions(mapping).iteritems():
+            assert path in map
+            map[path] = (map[path][0], revid)
 
     def get_map(self, foreign_revid, mapping):
         """Make sure the map is up to date until revnum."""
@@ -146,50 +182,17 @@
 
         # No history -> empty map
         todo = self.repos.get_mainline(branch, revnum, mapping)
-   
         pb = ui.ui_factory.nested_progress_bar()
-
         try:
             for i, (revmeta, mapping) in enumerate(reversed(todo)):
                 pb.update('generating file id map', i, len(todo))
                 if revmeta.is_hidden(mapping):
                     continue
-                self.apply_changes(map, revmeta, mapping)
-                self._use_text_revids(mapping, revmeta, map)
-                parent_revs = next_parent_revs
-                next_parent_revs = [revmeta.get_revision_id(mapping)]
+                self.update_idmap(map, revmeta, mapping)
         finally:
             pb.finished()
         return map
 
-    def update_map(self, map, revid, delta, changes):
-        """Update a file id map.
-
-        :param map: Existing file id map.
-        :param revid: Revision id of the id map
-        :param delta: Id map for just the delta
-        :param changes: Changes in revid.
-        """
-        for p in changes:
-            inv_p = p.decode("utf-8")
-            if changes[p][0] == 'M' and not delta.has_key(p):
-                delta[inv_p] = map[inv_p][0]
-        
-        for x in sorted(delta.keys(), reverse=True):
-            assert isinstance(x, unicode)
-            if delta[x] is None:
-                del map[x]
-                for p in map.keys():
-                    if p.startswith(u"%s/" % x):
-                        del map[p]
-
-        for x in sorted(delta.keys()):
-            if (delta[x] is not None and 
-                # special case - we change metadata in svn at the branch root path
-                # but that's not reflected as a bzr metadata change in bzr
-                (x != "" or not "" in map or map[x][1] == NULL_REVISION)):
-                map[x] = (str(delta[x]), revid)
-
 
 class FileIdMapCache(object):
 
@@ -224,9 +227,8 @@
     def __init__(self, cache_transport, actual):
         self.cache = FileIdMapCache(cache_transport)
         self.actual = actual
-        self.apply_changes = actual.apply_changes
-        self._use_text_revids = actual._use_text_revids
         self.repos = actual.repos
+        self.get_idmap_delta = actual.get_idmap_delta
 
     def get_map(self, (uuid, branch, revnum), mapping):
         """Make sure the map is up to date until revnum."""
@@ -270,11 +272,11 @@
         try:
             for i, (revmeta, mapping) in enumerate(reversed(todo)):
                 pb.update('generating file id map', i, len(todo))
-                self.actual.apply_changes(map, revmeta, mapping)
-                self._use_text_revids(mapping, revmeta, map)
+                revid = revmeta.get_revision_id(mapping)
+                self.actual.update_idmap(map, revmeta, mapping)
                 parent_revs = next_parent_revs
                 self.cache.save(revid, parent_revs, map)
-                next_parent_revs = [revmeta.get_revision_id(mapping)]
+                next_parent_revs = [revid]
         finally:
             pb.finished()
         return map

=== modified file 'tests/mapping3/__init__.py'
--- a/tests/mapping3/__init__.py	2009-01-16 22:22:09 +0000
+++ b/tests/mapping3/__init__.py	2009-01-16 23:05:55 +0000
@@ -89,7 +89,7 @@
 
     def test_generate_svn_file_id(self):
         self.assertEqual("2 at uuid:bp:path", 
-                self.mapping.generate_file_id(("uuid", "bp", 3), u"path"))
+                self.mapping.generate_file_id(("uuid", "bp", 2), u"path"))
 
     def test_generate_svn_file_id_nordic(self):
         self.assertEqual("2 at uuid:bp:%C3%A6%C3%B8%C3%A5", 




More information about the bazaar-commits mailing list