Rev 2113: More simplifications, use defaultdict. in http://people.samba.org/bzr/jelmer/bzr-svn/0.5
Jelmer Vernooij
jelmer at samba.org
Sun Nov 30 22:17:53 GMT 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/0.5
------------------------------------------------------------
revno: 2113
revision-id: jelmer at samba.org-20081130221751-vbj3vq6nxut5tm85
parent: jelmer at samba.org-20081130215652-pw8h6v2293cax1w2
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.5
timestamp: Sun 2008-11-30 23:17:51 +0100
message:
More simplifications, use defaultdict.
modified:
changes.py changes.py-20080330205801-lh92uht2ztppvdcz-1
logwalker.py logwalker.py-20060621215743-c13fhfnyzh1xzwh2-1
repository.py repository.py-20060306123302-1f8c5069b3fe0265
revmeta.py revmeta.py-20080901215045-n8a6arqybs9ez5hl-1
workingtree.py workingtree.py-20060306120941-b083cb0fdd4a69de
=== modified file 'changes.py'
--- a/changes.py 2008-11-27 01:19:08 +0000
+++ b/changes.py 2008-11-30 22:17:51 +0000
@@ -15,6 +15,8 @@
"""Utility functions for dealing with changes dictionaries as return by Subversions' log functions."""
+REV0_CHANGES = {"": ('A', None, -1)}
+
def path_is_child(branch_path, path):
"""Check whether path is or is under branch_path."""
return (branch_path == "" or
=== modified file 'logwalker.py'
--- a/logwalker.py 2008-11-29 04:34:10 +0000
+++ b/logwalker.py 2008-11-30 22:17:51 +0000
@@ -318,7 +318,7 @@
def get_revision_paths(self, revnum):
if revnum == 0:
- return {'': ('A', None, -1)}
+ return changes.REV0_CHANGES
self._fetch_revisions(revnum)
return self.cache.get_revision_paths(revnum)
@@ -478,7 +478,7 @@
if pb is not None:
pb.update("determining changes", from_revnum-revnum, from_revnum)
if revnum == 0 and changed_paths is None:
- revpaths = {"": ('A', None, -1)}
+ revpaths = changes.REV0_CHANGES
elif isinstance(changed_paths, dict):
revpaths = strip_slashes(changed_paths)
else:
@@ -503,7 +503,7 @@
"""
# To make the existing code happy:
if revnum == 0:
- return {'': ('A', None, -1)}
+ return changes.REV0_CHANGES
try:
return strip_slashes(
=== modified file 'repository.py'
--- a/repository.py 2008-11-30 15:28:28 +0000
+++ b/repository.py 2008-11-30 22:17:51 +0000
@@ -31,6 +31,7 @@
from bzrlib.transport import Transport, get_transport
from bzrlib.trace import info
+from collections import defaultdict
from itertools import chain
import os
import subvertpy
@@ -204,15 +205,15 @@
return self._cached_revnum
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
- fileids = {}
+ fileids = defaultdict(set)
for count, (revid, d) in enumerate(zip(revision_ids, self.get_deltas_for_revisions(self.get_revisions(revision_ids)))):
if _files_pb is not None:
_files_pb.update("fetch revisions for texts", count, len(revision_ids))
for c in d.added + d.modified:
- fileids.setdefault(c[1], set()).add(revid)
+ fileids[c[1]].add(revid)
for c in d.renamed:
- fileids.setdefault(c[2], set()).add(revid)
+ fileids[c[2]].add(revid)
for fileid, altered_versions in fileids.iteritems():
yield ("file", fileid, altered_versions)
=== modified file 'revmeta.py'
--- a/revmeta.py 2008-11-30 21:56:52 +0000
+++ b/revmeta.py 2008-11-30 22:17:51 +0000
@@ -47,6 +47,7 @@
)
import bisect
+from collections import defaultdict
from functools import partial
from itertools import ifilter, imap
@@ -483,13 +484,13 @@
def consider_bzr_fileprops(self):
if self._consider_bzr_fileprops is not None:
return self._consider_bzr_fileprops
- self._consider_bzr_fileprops = (self.metabranch is None or self.metabranch.consider_bzr_fileprops(self))
+ self._consider_bzr_fileprops = True # FIXME
return self._consider_bzr_fileprops
def consider_svk_fileprops(self):
if self._consider_svk_fileprops is not None:
return self._consider_svk_fileprops
- self._consider_svk_fileprops = (self.metabranch is None or self.metabranch.consider_svk_fileprops(self))
+ self._consider_svk_fileprops = True # FIXME
return self._consider_svk_fileprops
def get_roundtrip_ancestor_revids(self):
@@ -632,28 +633,6 @@
assert i == len(self._revs) or self._revs[i] == revmeta
return i
- def consider_bzr_fileprops(self, revmeta):
- """Check whether bzr file properties should be analysed for
- this revmeta.
- """
- i = self._index(revmeta)
- for desc in reversed(self._revs[:i]):
- if desc.knows_fileprops():
- return (desc.estimate_bzr_fileprop_ancestors() > 0)
- # assume the worst
- return True
-
- def consider_svk_fileprops(self, revmeta):
- """Check whether svk file propertise should be analysed for
- this revmeta.
- """
- i = self._index(revmeta)
- for desc in reversed(self._revs[:i]):
- if desc.knows_fileprops():
- return (desc.estimate_svk_fileprop_ancestors() > 0)
- # assume the worst
- return True
-
def get_lhs_parent(self, revmeta):
"""Find the left hand side of a revision using revision metadata.
@@ -720,8 +699,8 @@
return ret
def do(self, project=None, pb=None):
- unusual_history = {}
- metabranches_history = {}
+ unusual_history = defaultdict(set)
+ metabranches_history = defaultdict(dict)
unusual = set()
for (paths, revnum, revprops) in self._provider._log.iter_changes(
self.prefixes, self.from_revnum, self.to_revnum, pb=pb):
@@ -731,8 +710,8 @@
pb.update("discovering revisions", revnum-self.to_revnum,
self.from_revnum-self.to_revnum)
- self._metabranches.update(metabranches_history.get(revnum, {}))
- unusual.update(unusual_history.get(revnum, set()))
+ self._metabranches.update(metabranches_history[revnum])
+ unusual.update(unusual_history[revnum])
for p in sorted(paths):
action = paths[p][0]
@@ -769,9 +748,9 @@
else:
data = self._get_metabranch(new_name)
del self._metabranches[new_name]
- metabranches_history.setdefault(old_rev, {})[old_name] = data
+ metabranches_history[old_rev][old_name] = data
if not self.layout.is_branch_or_tag(old_name, project):
- unusual_history.setdefault(old_rev, set()).add(old_name)
+ unusual_history[old_rev].add(old_name)
for bp in bps:
revmeta = self._provider.get_revision(bp, revnum, paths,
@@ -782,7 +761,7 @@
# Make sure commit 0 is processed
if self.to_revnum == 0 and self.layout.is_branch_or_tag("", project):
bps[""] = self._get_metabranch("")
- revmeta = self._provider.get_revision("", 0, {"": ('A', None, -1)}, {}, metabranch=bps[""])
+ revmeta = self._provider.get_revision("", 0, changes.REV0_CHANGES, {}, metabranch=bps[""])
bps[""].finished = True
yield "revision", revmeta
@@ -907,7 +886,8 @@
def convert((bp, paths, revnum, revprops)):
ret = self.get_revision(bp, revnum, paths, revprops,
metabranch=metabranch)
- ret.children.add(metabranch._revs[-1])
+ if metabranch._revs:
+ ret.children.add(metabranch._revs[-1])
metabranch.append(ret)
return ret
metabranch = RevisionMetadataBranch(self, limit)
=== modified file 'workingtree.py'
--- a/workingtree.py 2008-11-29 16:26:45 +0000
+++ b/workingtree.py 2008-11-30 22:17:51 +0000
@@ -473,7 +473,7 @@
if not file_list:
# no paths supplied: add the entire tree.
file_list = [u'.']
- ignored = {}
+ ignored = defaultdict(list)
added = []
for file_path in file_list:
@@ -495,7 +495,7 @@
c_path = os.path.join(file_path, c)
ignore_glob = self.is_ignored(c)
if ignore_glob is not None:
- ignored.setdefault(ignore_glob, []).append(c_path)
+ ignored[ignore_glob].append(c_path)
todo.append(c_path)
finally:
wc.close()
More information about the bazaar-commits
mailing list