How to get the diff between two arbitrary remote revisions?

Matthieu Moy Matthieu.Moy at imag.fr
Wed Nov 9 16:27:50 GMT 2005


Martin Pool <mbp at sourcefrog.net> writes:

> OK, so perhaps
>
>   bzr diff [--from BRANCH] FILE...

I think it can be interesting to have it in addition to an extension
of the namespace. But changing the namespace has the big advantage of
solving the problem "I want to talk about /this/ particular remote
revision" for all the commands having a -r option at a time (including
external plugins on which you don't have any control, and code that is
not yet written).

I think being able to designate any revision is a basic property that
the revisionspec namespace should anyway verify.

I've done this as a Python exercice (be warned that I'm a complete
beginner in Python, so my code is not supposed to be really good
quality ... that's cut-and-paste from "branch:" plus some kind of
personal heuristics to make this work).

It adds the possibility to do revno:N:/path/to/branch.

=== modified file 'bzrlib/revisionspec.py'
--- bzrlib/revisionspec.py
+++ bzrlib/revisionspec.py
@@ -189,10 +189,25 @@
 
     def _match_on(self, branch, revs):
         """Lookup a revision by revision number"""
-        try:
-            return RevisionInfo(branch, int(self.spec))
-        except ValueError:
-            return RevisionInfo(branch, None)
+        if self.spec.find(':') == -1:
+            try:
+                return RevisionInfo(branch, int(self.spec))
+            except ValueError:
+                return RevisionInfo(branch, None)
+        else:
+            from branch import Branch
+            from fetch import greedy_fetch
+            revname = self.spec[self.spec.find(':')+1:]
+            other_branch = Branch.open_containing(revname)[0]
+            try:
+                revno = int(self.spec[:self.spec.find(':')])
+            except ValueError:
+                return RevisionInfo(other_branch, None)
+            revid = other_branch.get_rev_id(revno)
+            revision_b = other_branch.get_revision(revid)
+            # pull in the remote revisions so we can diff
+            greedy_fetch(branch, other_branch, revision=revid)
+            return RevisionInfo(other_branch, revno)
 
 SPEC_TYPES.append(RevisionSpec_revno)
 


-- 
Matthieu




More information about the bazaar mailing list