[RFC][PATCH 1/4] Speed improvement in fetch/clone: file_involved( ) function

Goffredo Baroncelli kreijack at inwind.it
Sat Dec 10 18:15:14 GMT 2005


This patch add the function file involved( )

=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py
+++ bzrlib/branch.py
@@ -1090,6 +1090,55 @@
         self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)),
                                 revision_id, "sig")

+    def file_involved(self, arg1=None, arg2=None):
+        """ This function returns the file_id(s) involved in the
+            changese between two revisions, or in the changes
+
+            The revisions are expressed as revision_id
+
+            if two args are passed,the changes are searched between
+                'rev-arg1'..'rev-arg2'
+            if one arg is passed, the changes are searched up to rev-arg1 or
+                if it is a set, inside this set
+            if no args is passed, all files_id are returned
+        """
+
+        w = self._get_inventory_weave( )
+        file_id = set( )
+
+        if arg2:
+            from_set = set(w.inclusions([w.lookup(arg1)]))
+            to_set = set(w.inclusions([w.lookup(arg2)]))
+            changed = to_set.difference(from_set)
+        elif arg1:
+            if isinstance(arg1, set):
+                changed = map(w.lookup, arg1 )
+            else:
+                changed = w.inclusions([w.lookup(arg1)])
+        else:
+            changed = set(w.inclusions([w.numversions( )-1]))
+
+        for lineno, insert, deleteset, line in w._walk():
+            if insert in changed:
+
+                start = line.find('file_id="')+9
+                if start < 9: continue
+                end = line.find('"',start)
+                assert end>= 0
+                fid = line[start:end]
+
+                start = line.find('revision="')+10
+                if start < 10: continue
+                end = line.find('"',start)
+                assert end>= 0
+                rev = line[start:end]
+
+                if w.lookup(rev) != insert: continue
+
+                file_id.add(fid)
+
+        return file_id
+

 class ScratchBranch(BzrBranch):
     """Special test class: a branch that cleans up after itself.


-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack at inwind_DOT_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/20051210/22362373/attachment.pgp 


More information about the bazaar mailing list