diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -967,10 +967,7 @@ class queue: self.ui.write("No patches applied\n") return qp = self.qparents(repo, top) - if opts.get('git'): - self.diffopts().git = True - if opts.get('unified') is not None: - self.diffopts().context = opts['unified'] + self._diffopts = patch.diffopts(self.ui, opts) self.printdiff(repo, qp, files=pats, opts=opts) def refresh(self, repo, pats=None, **opts): @@ -2355,10 +2352,8 @@ cmdtable = { _('hg qcommit [OPTION]... [FILE]...')), "^qdiff": (diff, - [('g', 'git', None, _('use git extended diff format')), - ('U', 'unified', 3, _('number of lines of context to show')), - ] + commands.walkopts, - _('hg qdiff [-I] [-X] [-U NUM] [-g] [FILE]...')), + commands.diffopts + commands.diffopts2 + commands.walkopts, + _('hg qdiff [OPTION]... [FILE]...')), "qdelete|qremove|qrm": (delete, [('k', 'keep', None, _('keep patch file')), diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2932,6 +2932,23 @@ logopts = [ ('M', 'no-merges', None, _('do not show merges')), ] + templateopts +diffopts = [ + ('a', 'text', None, _('treat all files as text')), + ('g', 'git', None, _('use git extended diff format')), + ('', 'nodates', None, _("don't include dates in diff headers")) +] + +diffopts2 = [ + ('p', 'show-function', None, _('show which function each change is in')), + ('w', 'ignore-all-space', None, + _('ignore white space when comparing lines')), + ('b', 'ignore-space-change', None, + _('ignore changes in the amount of white space')), + ('B', 'ignore-blank-lines', None, + _('ignore changes whose lines are all blank')), + ('U', 'unified', '', _('number of lines of context to show')) +] + table = { "^add": (add, walkopts + dryrunopts, _('hg add [OPTION]... [FILE]...')), "addremove": @@ -3071,29 +3088,14 @@ table = { "debugwalk": (debugwalk, walkopts, _('hg debugwalk [OPTION]... [FILE]...')), "^diff": (diff, - [('r', 'rev', [], _('revision')), - ('a', 'text', None, _('treat all files as text')), - ('p', 'show-function', None, - _('show which function each change is in')), - ('g', 'git', None, _('use git extended diff format')), - ('', 'nodates', None, _("don't include dates in diff headers")), - ('w', 'ignore-all-space', None, - _('ignore white space when comparing lines')), - ('b', 'ignore-space-change', None, - _('ignore changes in the amount of white space')), - ('B', 'ignore-blank-lines', None, - _('ignore changes whose lines are all blank')), - ('U', 'unified', '', - _('number of lines of context to show')) - ] + walkopts, + [('r', 'rev', [], _('revision')) + ] + diffopts + diffopts2 + walkopts, _('hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]...')), "^export": (export, [('o', 'output', '', _('print output to file with formatted name')), - ('a', 'text', None, _('treat all files as text')), - ('g', 'git', None, _('use git extended diff format')), - ('', 'nodates', None, _("don't include dates in diff headers")), - ('', 'switch-parent', None, _('diff against the second parent'))], + ('', 'switch-parent', None, _('diff against the second parent')) + ] + diffopts, _('hg export [OPTION]... [-o OUTFILESPEC] REV...')), "grep": (grep, diff --git a/tests/test-help.out b/tests/test-help.out --- a/tests/test-help.out +++ b/tests/test-help.out @@ -201,9 +201,9 @@ options: -r --rev revision -a --text treat all files as text - -p --show-function show which function each change is in -g --git use git extended diff format --nodates don't include dates in diff headers + -p --show-function show which function each change is in -w --ignore-all-space ignore white space when comparing lines -b --ignore-space-change ignore changes in the amount of white space -B --ignore-blank-lines ignore changes whose lines are all blank diff --git a/tests/test-mq-qdiff b/tests/test-mq-qdiff --- a/tests/test-mq-qdiff +++ b/tests/test-mq-qdiff @@ -25,3 +25,35 @@ hg qdiff | sed -e "s/\(+++ [a-zA-Z0-9_/. echo % qdiff dirname hg qdiff . | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" + +echo % qdiff filename +hg qdiff --nodates base + +echo % revert +hg revert -a + +echo % qpop +hg qpop + +echo % qdelete mqbase +hg qdelete mqbase + +echo % commit 2 +printf '1\n2\n3\n4\nhello world\ngoodbye world\n7\n8\n9\n' > lines +hg ci -Amlines -d '2 0' + +echo % qnew 2 +hg qnew -mmqbase2 mqbase2 +printf '\n\n1\n2\n3\n4\nhello world\n goodbye world\n7\n8\n9\n' > lines + +echo % qdiff -U 1 +hg qdiff --nodates -U 1 + +echo % qdiff -b +hg qdiff --nodates -b + +echo % qdiff -U 1 -B +hg qdiff --nodates -U 1 -B + +echo qdiff -w +hg qdiff --nodates -w diff --git a/tests/test-mq-qdiff.out b/tests/test-mq-qdiff.out --- a/tests/test-mq-qdiff.out +++ b/tests/test-mq-qdiff.out @@ -17,3 +17,71 @@ diff -r 67e992f2c4f3 base @@ -1,1 +1,1 @@ -base +patched +% qdiff filename +diff -r 67e992f2c4f3 base +--- a/base ++++ b/base +@@ -1,1 +1,1 @@ +-base ++patched +% revert +% qpop +Patch queue now empty +% qdelete mqbase +% commit 2 +adding lines +% qnew 2 +% qdiff -U 1 +diff -r 35fb829491c1 lines +--- a/lines ++++ b/lines +@@ -1,1 +1,3 @@ ++ ++ + 1 +@@ -4,4 +6,4 @@ + 4 +-hello world +-goodbye world ++hello world ++ goodbye world + 7 +% qdiff -b +diff -r 35fb829491c1 lines +--- a/lines ++++ b/lines +@@ -1,9 +1,11 @@ ++ ++ + 1 + 2 + 3 + 4 +-hello world +-goodbye world ++hello world ++ goodbye world + 7 + 8 + 9 +% qdiff -U 1 -B +diff -r 35fb829491c1 lines +--- a/lines ++++ b/lines +@@ -4,4 +6,4 @@ + 4 +-hello world +-goodbye world ++hello world ++ goodbye world + 7 +qdiff -w +diff -r 35fb829491c1 lines +--- a/lines ++++ b/lines +@@ -1,3 +1,5 @@ ++ ++ + 1 + 2 + 3