[PATCH 1/4] Speed improvement in fetch/clone: file_involved( ) function
Goffredo Baroncelli
kreijack at alice.it
Thu Dec 15 22:29:16 GMT 2005
This patch add the methods fileid_involved*( ) to the branch class. Tank to Robert Collins
for the suggestions
Goffredo
( you can see the diff at
http://goffredo-baroncelli.homelinux.net/bazaar-dev/bzr-fileid-involved?cmd=diff;otherrevid=mbp@sourcefrog.net-20051208071308-3a71ecddda863fa8;rev=;pathrevid=ghigo@therra.bhome-20051215205928-ee0dbb06205ab6a1;path=bzrlib/branch.py
)
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py
+++ bzrlib/branch.py
@@ -486,6 +486,27 @@
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
raise NotImplementedError('store_revision_signature is abstract')
+
+ def fileid_involved_between_revs(self, from_revid, to_revid):
+ """ This function returns the file_id(s) involved in the
+ changes between the from_revid revision and the to_revid
+ revision
+ """
+ raise NotImplementedError('fileid_involved_between_revs is abstract')
+
+ def fileid_involved(self, last_revid=None):
+ """ This function returns the file_id(s) involved in the
+ changes up to the revision last_revid
+ If no parametr is passed, then all file_id[s] present in the
+ repository are returned
+ """
+ raise NotImplementedError('fileid_involved is abstract')
+
+ def fileid_involved_by_set(self, changes):
+ """ This function returns the file_id(s) involved in the
+ changes present in the set 'changes'
+ """
+ raise NotImplementedError('fileid_involved_by_set is abstract')
class BzrBranch(Branch):
"""A branch stored in the actual filesystem.
@@ -1091,6 +1112,67 @@
self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)),
revision_id, "sig")
+ def fileid_involved_between_revs(self, from_revid, to_revid):
+ """ This function returns the file_id(s) involved in the
+ changes between the from_revid revision and the to_revid
+ revision
+ """
+ w = self._get_inventory_weave( )
+ from_set = set(w.inclusions([w.lookup(from_revid)]))
+ to_set = set(w.inclusions([w.lookup(to_revid)]))
+ included = to_set.difference(from_set)
+ changed = map(w.idx_to_name,included)
+ return self._fileid_involved_by_set(changed)
+
+ def fileid_involved(self, last_revid=None):
+ """ This function returns the file_id(s) involved in the
+ changes up to the revision last_revid
+ If no parametr is passed, then all file_id[s] present in the
+ repository are returned
+ """
+ w = self._get_inventory_weave( )
+ if not last_revid:
+ changed = set(w._names)
+ else:
+ included = w.inclusions([w.lookup(last_revid)])
+ changed = map(w.idx_to_name, included)
+ return self._fileid_involved_by_set(changed)
+
+ def fileid_involved_by_set(self, changes):
+ """ This function returns the file_id(s) involved in the
+ changese present in the set changes
+ """
+ w = self._get_inventory_weave( )
+ return self._fileid_involved_by_set(changes)
+
+ def _fileid_involved_by_set(self, changes):
+ w = self._get_inventory_weave( )
+ file_ids = set( )
+ for line in w._weave:
+
+ # it is ugly, but it is due to the weave structure
+ if not isinstance(line,basestring): continue
+
+ start = line.find('file_id="')+9
+ if start < 9: continue
+ end = line.find('"',start)
+ assert end>= 0
+ file_id = line[start:end]
+
+ # check if file_id is already present
+ if file_id in file_ids: continue
+
+ start = line.find('revision="')+10
+ if start < 10: continue
+ end = line.find('"',start)
+ assert end>= 0
+ revision_id = line[start:end]
+
+ if revision_id in changes:
+ file_ids.add(file_id)
+
+ return file_ids
+
class ScratchBranch(BzrBranch):
"""Special test class: a branch that cleans up after itself.
--
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack @ inwind.it>
Key fingerprint = CE3C 7E01 6782 30A3 5B87 87C0 BB86 505C 6B2A CFF9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051215/7779ce45/attachment.pgp
More information about the bazaar
mailing list