[Patch] Support for multiple revisions for diff command
Michael Ellerman
michael+bazaar at ellerman.id.au
Tue May 10 17:25:18 BST 2005
Hi Martin,
This is a implementation of 'bzr diff -r foo -r2 bar'. I opted against using
the -r option twice because it's kind of ambiguous, and it seemed kind of
hard given the current option parsing scheme :D
Hmm, is it a feature or a "feature" that diff accepts (some) negative values
for revision number? It is kind of cool.
It's a little counter intertuitive (perhaps) but to get the diff for revno
440 you have to run 'bzr diff -r 439 -r2 440'.
cheers
*** modified file 'bzrlib/commands.py'
--- bzrlib/commands.py
+++ bzrlib/commands.py
@@ -425,8 +425,6 @@
If files are listed, only the changes in those files are listed.
Otherwise, all changes for the tree are listed.
- TODO: Given two revision arguments, show the difference between them.
-
TODO: Allow diff across branches.
TODO: Option to use external diff command; could be GNU diff, wdiff,
@@ -444,13 +442,13 @@
"""
takes_args = ['file*']
- takes_options = ['revision']
+ takes_options = ['revision', 'target-revision']
aliases = ['di']
- def run(self, revision=None, file_list=None):
+ def run(self, revision=None, target_revision=None, file_list=None):
from bzrlib.diff import show_diff
- show_diff(Branch('.'), revision, file_list)
+ show_diff(Branch('.'), revision, target_revision, file_list)
@@ -861,7 +859,6 @@
######################################################################
# main routine
-
# list of all available options; the rhs can be either None for an
# option that takes no argument, or a constructor function that checks
# the type.
@@ -872,6 +869,7 @@
'message': unicode,
'profile': None,
'revision': int,
+ 'target-revision': int,
'show-ids': None,
'timezone': str,
'verbose': None,
@@ -883,6 +881,7 @@
'm': 'message',
'F': 'file',
'r': 'revision',
+ 'r2': 'target-revision',
'v': 'verbose',
}
*** modified file 'bzrlib/diff.py'
--- bzrlib/diff.py
+++ bzrlib/diff.py
@@ -140,15 +140,18 @@
-def show_diff(b, revision, file_list):
+def show_diff(b, revision, target_revision, file_list):
import difflib, sys, types
if revision == None:
old_tree = b.basis_tree()
else:
old_tree = b.revision_tree(b.lookup_revision(revision))
-
- new_tree = b.working_tree()
+
+ if target_revision == None:
+ new_tree = b.working_tree()
+ else:
+ new_tree = b.revision_tree(b.lookup_revision(target_revision))
# TODO: Options to control putting on a prefix or suffix, perhaps as a format string
old_label = ''
*** modified file 'testbzr'
--- testbzr
+++ testbzr
@@ -281,6 +281,11 @@
f.close()
runcmd('bzr commit -F msg.tmp')
+
+ runcmd('bzr diff -r 0 -r2 1')
+
+ out = backtick('bzr diff -r 0 -r2 1').split('\n')[0]
+ assert out == "*** added file 'hello.txt'"
assert backtick('bzr revno') == '5\n'
runcmd('bzr export -r 5 export-5.tmp')
More information about the bazaar
mailing list