[PATCH stable?] import: respect diff.noprefix config (issue4639)
Ryan McElroy
rm at fb.com
Fri Jan 22 14:51:36 UTC 2016
# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1453473839 28800
# Fri Jan 22 06:43:59 2016 -0800
# Branch stable
# Node ID 40555a31b98b027c91b1ccf61477151b3307deb2
# Parent 158bdc8965720ca4061f8f8d806563cfc7cdb62e
import: respect diff.noprefix config (issue4639)
Previously export-import round-trips would not work if diff.nopreofix was
truthy, because import did not pay attention to that setting. Now we inspect
that setting unless an explicit strip level is specified.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -878,6 +878,9 @@ def tryimportone(ui, repo, hunk, parents
importbranch = opts.get('import_branch')
update = not opts.get('bypass')
strip = opts["strip"]
+ if strip == patch.STRIPUNSET:
+ noprefix = ui.configbool('diff', 'noprefix')
+ strip = 0 if noprefix else 1
prefix = opts["prefix"]
sim = float(opts.get('similarity') or 0)
if not tmpname:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4582,7 +4582,7 @@ def identify(ui, repo, source=None, rev=
ui.write("%s\n" % ' '.join(output))
@command('import|patch',
- [('p', 'strip', 1,
+ [('p', 'strip', patch.STRIPUNSET,
_('directory strip option for patch. This has the same '
'meaning as the corresponding patch option'), _('NUM')),
('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')),
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -37,6 +37,8 @@ from . import (
util,
)
+STRIPUNSET = -1 # a flag that means strip has not been explicitly set
+
gitre = re.compile('diff --git a/(.*) b/(.*)')
tabsplitter = re.compile(r'(\t+|[^\t]+)')
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -1763,3 +1763,19 @@ Importing some extra header
$ hg log --debug -r . | grep extra
extra: branch=default
extra: foo=bar
+
+Exporting then importing with diff.noprefix=True
+
+ $ hg expor . --config diff.noprefix=True > $TESTTMP/patch
+ $ hg import $TESTTMP/patch
+ applying $TESTTMP/patch (glob)
+ abort: unable to strip away 1 of 1 dirs from a
+ [255]
+ $ hg import $TESTTMP/patch --config diff.noprefix=True --strip 1
+ applying $TESTTMP/patch (glob)
+ abort: unable to strip away 1 of 1 dirs from a
+ [255]
+ $ hg import $TESTTMP/patch --strip 0
+ applying $TESTTMP/patch (glob)
+ $ hg import $TESTTMP/patch --config diff.noprefix=True
+ applying $TESTTMP/patch (glob)
More information about the Mercurial-devel
mailing list