[PATCH] patch: check length of git index header only if integer is specified
Yuya Nishihara
yuya at tcha.org
Sun Jan 15 07:58:54 UTC 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1484465595 -32400
# Sun Jan 15 16:33:15 2017 +0900
# Node ID 486f1b62e698c24dfde1d3130f5fda6392da7316
# Parent 7a50d3fb633a1ef3b80485a1947047898f1a24b7
patch: check length of git index header only if integer is specified
Otherwise TypeError would be raised. Follows up d1901c4c8ec0.
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2184,6 +2184,9 @@ def difffeatureopts(ui, opts=None, untru
# the hash config could be an integer (for length of hash) or a
# word (e.g. short, full, none)
hlen = int(hconf)
+ if hlen < 0 or hlen > 40:
+ msg = _("invalid length for extendedheader.index: '%d'\n")
+ ui.warn(msg % hlen)
except ValueError:
# default value
if hconf == 'short' or hconf == '':
@@ -2194,9 +2197,6 @@ def difffeatureopts(ui, opts=None, untru
msg = _("invalid value for extendedheader.index: '%s'\n")
ui.warn(msg % hconf)
finally:
- if hlen < 0 or hlen > 40:
- msg = _("invalid length for extendedheader.index: '%d'\n")
- ui.warn(msg % hlen)
buildopts['index'] = hlen
if whitespace:
diff --git a/tests/test-diff-unified.t b/tests/test-diff-unified.t
--- a/tests/test-diff-unified.t
+++ b/tests/test-diff-unified.t
@@ -243,6 +243,28 @@ Git diff, adding extended headers
-a
+b
+ $ hg diff --git --config experimental.extendedheader.index=-1
+ invalid length for extendedheader.index: '-1'
+ diff --git a/f1 b/f 1
+ rename from f1
+ rename to f 1
+ --- a/f1
+ +++ b/f 1
+ @@ -1,1 +1,1 @@
+ -a
+ +b
+
+ $ hg diff --git --config experimental.extendedheader.index=whatever
+ invalid value for extendedheader.index: 'whatever'
+ diff --git a/f1 b/f 1
+ rename from f1
+ rename to f 1
+ --- a/f1
+ +++ b/f 1
+ @@ -1,1 +1,1 @@
+ -a
+ +b
+
Git diff with noprefix
$ hg --config diff.noprefix=True diff --git --nodates
More information about the Mercurial-devel
mailing list