aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-18 12:27:16 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-18 12:27:16 -0500
commit3624886b80b506a9140cda1877c05c8fb831ac3d (patch)
tree606ac19b670e7f591bf8f700e307b7d53dc8cb2c /libbe
parent7ae29f930fe73adada5174a2ce74266411809ac7 (diff)
downloadbugseverywhere-3624886b80b506a9140cda1877c05c8fb831ac3d.tar.gz
Optimized libbe.diff.Diff._changed when old bugdir is a RevisionedBugDir
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bugdir.py58
-rw-r--r--libbe/diff.py78
2 files changed, 68 insertions, 68 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index 90c21e1..5967a7e 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -307,6 +307,7 @@ class RevisionedBugDir (BugDir):
def __init__(self, storage, default_revision):
self.s = storage
self.sget = self.s.get
+ self.sancestors = self.s.ancestors
self.schildren = self.s.children
self.schanged = self.s.changed
self.r = default_revision
@@ -314,6 +315,13 @@ class RevisionedBugDir (BugDir):
if not 'revision' in kwargs or kwargs['revision'] == None:
kwargs['revision'] = self.r
return self.sget(*args, **kwargs)
+ def ancestors(self, *args, **kwargs):
+ print 'getting ancestors', args, kwargs
+ if not 'revision' in kwargs or kwargs['revision'] == None:
+ kwargs['revision'] = self.r
+ ret = self.sancestors(*args, **kwargs)
+ print 'got ancestors', ret
+ return ret
def children(self, *args, **kwargs):
if not 'revision' in kwargs or kwargs['revision'] == None:
kwargs['revision'] = self.r
@@ -324,57 +332,13 @@ class RevisionedBugDir (BugDir):
return self.schanged(*args, **kwargs)
rs = RevisionedStorage(s, revision)
s.get = rs.get
+ s.ancestors = rs.ancestors
s.children = rs.children
s.changed = rs.changed
BugDir.__init__(self, s, from_storage=True)
self.revision = revision
-# dbd = copy.copy(self)
-# dbd.storage = copy.copy(self.storage)
-# dbd._bug_map = copy.copy(self._bug_map)
-# dbd.storage.writeable = False
-# added,changed,removed = self.storage.changed_since(revision)
-# for id in added:
-# pass
-# for id in removed:
-# pass
-# for id in changed:
-# parsed = libbe.util.id.parse_id(id)
-# if parsed['type'] == 'bugdir':
-# assert parsed['remaining'] == ['settings'], parsed['remaining']
-# dbd._settings = copy.copy(self._settings)
-# mf = self.storage.get(self.id.storage('settings'), default='\n',
-# revision=revision)
-# dbd.load_settings(mf)
-# else:
-# if parsed['bug'] not in self:
-# self._load_bug(parsed['bug'])
-# dbd._load_bug(parsed['bug'])
-# else:
-# bug = copy.copy(self._bug_map[parsed['bug']])
-# bug.settings = copy.copy(bug.settings)
-# dbd._bug_map[parsed['bug']] = bug
-# if parsed['type'] == 'bug':
-# assert parsed['remaining'] == ['values'], parsed['remaining']
-# mf = self.storage.get(self.id.storage('values'), default='\n',
-# revision=revision)
-# bug.load_settings(mf)
-# elif parsed['type'] == 'comment':
-# assert parsed['remaining'] in [['values'], ['body']], \
-# parsed['remaining']
-# bug.comment_root = copy.deepcopy(bug.comment_root)
-# comment = bug.comment_from_uuid(parsed['comment'])
-# if parsed['remaining'] == ['values']:
-# mf = self.storage.get(self.id.storage('values'), default='\n',
-# revision=revision)
-# comment.load_settings(mf)
-# else:
-# body = self.storage.get(self.id.storage('body'), default='\n',
-# revision=revision)
-# comment.body = body
-# else:
-# assert 1==0, 'Unkown type "%s" for id "%s"' % (type, id)
-# dbd.storage.readable = False # so we won't read in added bugs, etc.
-# return dbd
+ def changed(self):
+ return self.storage.changed()
if libbe.TESTING == True:
diff --git a/libbe/diff.py b/libbe/diff.py
index b325c5d..5632267 100644
--- a/libbe/diff.py
+++ b/libbe/diff.py
@@ -367,32 +367,68 @@ class Diff (object):
old_uuids.extend([s for s in subscribed_bugs
if self.old_bugdir.has_bug(s)])
old_uuids = sorted(set(old_uuids))
+
added = []
removed = []
modified = []
- for uuid in new_uuids:
- new_bug = self.new_bugdir.bug_from_uuid(uuid)
- try:
- old_bug = self.old_bugdir.bug_from_uuid(uuid)
- except KeyError:
+ if hasattr(self.old_bugdir, 'changed'):
+ # take advantage of a RevisionedBugDir-style changed() method
+ new_ids,mod_ids,rem_ids = self.old_bugdir.changed()
+ for id in new_ids:
+ for a_id in self.new_bugdir.storage.ancestors(id):
+ if a_id.count('/') == 0:
+ if a_id in [b.id.storage() for b in added]:
+ break
+ try:
+ bug = self.new_bugdir.bug_from_uuid(a_id)
+ added.append(bug)
+ except libbe.bugdir.NoBugMatches:
+ pass
+ for id in rem_ids:
+ for a_id in self.old_bugdir.storage.ancestors(id):
+ if a_id.count('/') == 0:
+ if a_id in [b.id.storage() for b in removed]:
+ break
+ try:
+ bug = self.old_bugdir.bug_from_uuid(a_id)
+ removed.append(bug)
+ except libbe.bugdir.NoBugMatches:
+ pass
+ for id in mod_ids:
+ for a_id in self.new_bugdir.storage.ancestors(id):
+ if a_id.count('/') == 0:
+ if a_id in [b.id.storage() for b in modified]:
+ break
+ try:
+ new_bug = self.new_bugdir.bug_from_uuid(a_id)
+ old_bug = self.old_bugdir.bug_from_uuid(a_id)
+ modified.append((old_bug, new_bug))
+ except libbe.bugdir.NoBugMatches:
+ pass
+ else:
+ for uuid in new_uuids:
+ new_bug = self.new_bugdir.bug_from_uuid(uuid)
+ try:
+ old_bug = self.old_bugdir.bug_from_uuid(uuid)
+ except KeyError:
+ if BUGDIR_TYPE_ALL in bugdir_types \
+ or BUGDIR_TYPE_NEW in bugdir_types \
+ or uuid in subscribed_bugs:
+ added.append(new_bug)
+ continue
if BUGDIR_TYPE_ALL in bugdir_types \
- or BUGDIR_TYPE_NEW in bugdir_types \
+ or BUGDIR_TYPE_MOD in bugdir_types \
or uuid in subscribed_bugs:
- added.append(new_bug)
- continue
- if BUGDIR_TYPE_ALL in bugdir_types \
- or BUGDIR_TYPE_MOD in bugdir_types \
- or uuid in subscribed_bugs:
- if old_bug.storage != None and old_bug.storage.is_readable():
- old_bug.load_comments()
- if new_bug.storage != None and new_bug.storage.is_readable():
- new_bug.load_comments()
- if old_bug != new_bug:
- modified.append((old_bug, new_bug))
- for uuid in old_uuids:
- if not self.new_bugdir.has_bug(uuid):
- old_bug = self.old_bugdir.bug_from_uuid(uuid)
- removed.append(old_bug)
+ if old_bug.storage != None and old_bug.storage.is_readable():
+ old_bug.load_comments()
+ if new_bug.storage != None and new_bug.storage.is_readable():
+ new_bug.load_comments()
+ if old_bug != new_bug:
+ modified.append((old_bug, new_bug))
+ for uuid in old_uuids:
+ if not self.new_bugdir.has_bug(uuid):
+ old_bug = self.old_bugdir.bug_from_uuid(uuid)
+ removed.append(old_bug)
added.sort()
removed.sort()
modified.sort(self._bug_modified_cmp)