mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
Let --unified default to diff.unified (issue 1076)
This commit is contained in:
parent
95639b6467
commit
8e0cbccd26
@ -3028,7 +3028,7 @@ table = {
|
||||
_('ignore changes in the amount of white space')),
|
||||
('B', 'ignore-blank-lines', None,
|
||||
_('ignore changes whose lines are all blank')),
|
||||
('U', 'unified', 3,
|
||||
('U', 'unified', '',
|
||||
_('number of lines of context to show'))
|
||||
] + walkopts,
|
||||
_('hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]...')),
|
||||
|
@ -5,6 +5,7 @@
|
||||
# This software may be used and distributed according to the terms
|
||||
# of the GNU General Public License, incorporated herein by reference.
|
||||
|
||||
from i18n import _
|
||||
import bdiff, mpatch, re, struct, util, md5
|
||||
|
||||
def splitnewlines(text):
|
||||
@ -47,6 +48,12 @@ class diffopts(object):
|
||||
v = self.defaults[k]
|
||||
setattr(self, k, v)
|
||||
|
||||
try:
|
||||
self.context = int(self.context)
|
||||
except ValueError:
|
||||
raise util.Abort(_('diff context lines count must be '
|
||||
'an integer, not %r') % self.context)
|
||||
|
||||
defaultopts = diffopts()
|
||||
|
||||
def wsclean(opts, text):
|
||||
|
@ -1055,9 +1055,9 @@ def applydiff(ui, fp, changed, strip=1, sourcefile=None, reverse=False,
|
||||
return err
|
||||
|
||||
def diffopts(ui, opts={}, untrusted=False):
|
||||
def get(key, name=None):
|
||||
def get(key, name=None, getter=ui.configbool):
|
||||
return (opts.get(key) or
|
||||
ui.configbool('diff', name or key, None, untrusted=untrusted))
|
||||
getter('diff', name or key, None, untrusted=untrusted))
|
||||
return mdiff.diffopts(
|
||||
text=opts.get('text'),
|
||||
git=get('git'),
|
||||
@ -1066,7 +1066,7 @@ def diffopts(ui, opts={}, untrusted=False):
|
||||
ignorews=get('ignore_all_space', 'ignorews'),
|
||||
ignorewsamount=get('ignore_space_change', 'ignorewsamount'),
|
||||
ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'),
|
||||
context=get('unified'))
|
||||
context=get('unified', getter=ui.config))
|
||||
|
||||
def updatedir(ui, repo, patches):
|
||||
'''Update dirstate after patch application according to metadata'''
|
||||
|
49
tests/test-diff-unified
Executable file
49
tests/test-diff-unified
Executable file
@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
|
||||
hg init repo
|
||||
cd repo
|
||||
cat > a <<EOF
|
||||
c
|
||||
c
|
||||
a
|
||||
a
|
||||
b
|
||||
a
|
||||
a
|
||||
c
|
||||
c
|
||||
EOF
|
||||
hg ci -Am adda
|
||||
cat > a <<EOF
|
||||
c
|
||||
c
|
||||
a
|
||||
a
|
||||
dd
|
||||
a
|
||||
a
|
||||
c
|
||||
c
|
||||
EOF
|
||||
|
||||
echo '% default context'
|
||||
hg diff --nodates
|
||||
|
||||
echo '% invalid --unified'
|
||||
hg diff --nodates -U foo
|
||||
|
||||
echo '% --unified=2'
|
||||
hg diff --nodates -U 2
|
||||
|
||||
echo '% diff.unified=2'
|
||||
hg --config diff.unified=2 diff --nodates
|
||||
|
||||
echo '% diff.unified=2 --unified=1'
|
||||
hg diff --nodates -U 1
|
||||
|
||||
echo '% invalid diff.unified'
|
||||
hg --config diff.unified=foo diff --nodates
|
||||
|
||||
exit 0
|
||||
|
||||
|
49
tests/test-diff-unified.out
Normal file
49
tests/test-diff-unified.out
Normal file
@ -0,0 +1,49 @@
|
||||
adding a
|
||||
% default context
|
||||
diff -r cf9f4ba66af2 a
|
||||
--- a/a
|
||||
+++ b/a
|
||||
@@ -2,7 +2,7 @@
|
||||
c
|
||||
a
|
||||
a
|
||||
-b
|
||||
+dd
|
||||
a
|
||||
a
|
||||
c
|
||||
% invalid --unified
|
||||
abort: diff context lines count must be an integer, not 'foo'
|
||||
% --unified=2
|
||||
diff -r cf9f4ba66af2 a
|
||||
--- a/a
|
||||
+++ b/a
|
||||
@@ -3,5 +3,5 @@
|
||||
a
|
||||
a
|
||||
-b
|
||||
+dd
|
||||
a
|
||||
a
|
||||
% diff.unified=2
|
||||
diff -r cf9f4ba66af2 a
|
||||
--- a/a
|
||||
+++ b/a
|
||||
@@ -3,5 +3,5 @@
|
||||
a
|
||||
a
|
||||
-b
|
||||
+dd
|
||||
a
|
||||
a
|
||||
% diff.unified=2 --unified=1
|
||||
diff -r cf9f4ba66af2 a
|
||||
--- a/a
|
||||
+++ b/a
|
||||
@@ -4,3 +4,3 @@
|
||||
a
|
||||
-b
|
||||
+dd
|
||||
a
|
||||
% invalid diff.unified
|
||||
abort: diff context lines count must be an integer, not 'foo'
|
@ -205,7 +205,7 @@ options:
|
||||
-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
|
||||
-U --unified number of lines of context to show (default: 3)
|
||||
-U --unified number of lines of context to show
|
||||
-I --include include names matching the given patterns
|
||||
-X --exclude exclude names matching the given patterns
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user