Rev 2318: Simplify file id handling. in http://people.samba.org/bzr/jelmer/bzr-svn/0.5
Jelmer Vernooij
jelmer at samba.org
Fri Jan 16 23:21:41 GMT 2009
At http://people.samba.org/bzr/jelmer/bzr-svn/0.5
------------------------------------------------------------
revno: 2318
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
=== modified file 'fileids.py'
--- a/fileids.py 2009-01-16 22:37:58 +0000
+++ b/fileids.py 2009-01-16 23:21:38 +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.
+ :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)
+
+
def get_local_changes(paths, branch, mapping, layout, generate_revid,
get_children=None):
"""Obtain all of the changes relative to a particular path
@@ -121,11 +151,6 @@
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 get_idmap_delta(self, revmeta, mapping, find_children=None):
"""Change file id map to incorporate specified changes.
@@ -151,6 +176,14 @@
idmap.update(revmeta.get_fileid_map(mapping))
return (idmap, changes)
+ def update_idmap(self, map, revmeta, mapping, find_children=None):
+ (idmap, changes) = self.get_idmap_delta(revmeta,
+ mapping, find_children)
+ 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."""
(uuid, branch, revnum) = foreign_revid
@@ -178,44 +211,13 @@
if revmeta.is_hidden(mapping):
continue
revid = revmeta.get_revision_id(mapping)
- (idmap, changes) = self.get_idmap_delta(revmeta,
- mapping, self.repos.find_children)
- self.update_map(map, revid, idmap, changes)
- self._use_text_revids(mapping, revmeta, map)
+ self.update_idmap(map, revmeta, mapping, self.repos.find_children)
parent_revs = next_parent_revs
next_parent_revs = [revid]
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):
@@ -250,9 +252,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."""
@@ -297,15 +298,8 @@
for i, (revmeta, mapping) in enumerate(reversed(todo)):
pb.update('generating file id map', i, len(todo))
revid = revmeta.get_revision_id(mapping)
-
- (idmap, changes) = self.actual.get_idmap_delta(
- revmeta, mapping, self.repos.find_children)
-
- self.actual.update_map(map, revid, idmap, changes)
- self._use_text_revids(mapping, revmeta, map)
-
+ self.actual.update_idmap(map, revmeta, mapping, self.repos.find_children)
parent_revs = next_parent_revs
-
self.cache.save(revid, parent_revs, map)
next_parent_revs = [revid]
finally:
More information about the bazaar-commits
mailing list