# HG changeset patch # User Siddharth Agarwal # Date 2015-03-10 01:22:24 # Node ID 5ac8ce04baa24a1cbbda879ceef2f9bda8554e7e # Parent 093e8a5e995f10415f47344d34c5a0f94aa9dc2b cmdutil.tryimportone: allow importing relative patches into the working dir This makes hg import --prefix dir/ (without bypass) work. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -615,6 +615,7 @@ def tryimportone(ui, repo, hunk, parents update = not opts.get('bypass') strip = opts["strip"] + prefix = opts["prefix"] sim = float(opts.get('similarity') or 0) if not tmpname: return (None, None, False) @@ -674,8 +675,8 @@ def tryimportone(ui, repo, hunk, parents partial = opts.get('partial', False) files = set() try: - patch.patch(ui, repo, tmpname, strip=strip, files=files, - eolmode=None, similarity=sim / 100.0) + patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix, + files=files, eolmode=None, similarity=sim / 100.0) except patch.PatchError, e: if not partial: raise util.Abort(str(e)) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1533,7 +1533,7 @@ def patchrepo(ui, repo, ctx, store, patc backend = repobackend(ui, repo, ctx, store) return patchbackend(ui, backend, patchobj, strip, '', files, eolmode) -def patch(ui, repo, patchname, strip=1, files=None, eolmode='strict', +def patch(ui, repo, patchname, strip=1, prefix='', files=None, eolmode='strict', similarity=0): """Apply to the working directory. @@ -1552,7 +1552,7 @@ def patch(ui, repo, patchname, strip=1, if patcher: return _externalpatch(ui, repo, patcher, patchname, strip, files, similarity) - return internalpatch(ui, repo, patchname, strip, '', files, eolmode, + return internalpatch(ui, repo, patchname, strip, prefix, files, eolmode, similarity) def changedfiles(ui, repo, patchpath, strip=1): diff --git a/tests/test-import-git.t b/tests/test-import-git.t --- a/tests/test-import-git.t +++ b/tests/test-import-git.t @@ -612,12 +612,64 @@ Renames and strip a R a -Renames, similarity and git diff +Prefix with strip, renames, creates etc $ hg revert -aC undeleting a forgetting b $ rm b + $ mkdir -p dir/dir2 + $ echo b > dir/dir2/b + $ echo c > dir/dir2/c + $ echo d > dir/d + $ hg ci -Am addbcd + adding dir/d + adding dir/dir2/b + adding dir/dir2/c +(test that prefixes are relative to the root) + $ mkdir tmpdir + $ cd tmpdir + $ hg import --no-commit -p2 --prefix dir/ - < diff --git a/foo/a b/foo/a + > new file mode 100644 + > --- /dev/null + > +++ b/foo/a + > @@ -0,0 +1 @@ + > +a + > diff --git a/foo/dir2/b b/foo/dir2/b2 + > rename from foo/dir2/b + > rename to foo/dir2/b2 + > diff --git a/foo/dir2/c b/foo/dir2/c + > --- a/foo/dir2/c + > +++ b/foo/dir2/c + > @@ -0,0 +1 @@ + > +cc + > diff --git a/foo/d b/foo/d + > deleted file mode 100644 + > --- a/foo/d + > +++ /dev/null + > @@ -1,1 +0,0 @@ + > -d + > EOF + applying patch from stdin + $ hg st --copies + M dir/dir2/c + A dir/a + A dir/dir2/b2 + dir/dir2/b + R dir/d + R dir/dir2/b + $ cd .. + +Renames, similarity and git diff + + $ hg revert -aC + forgetting dir/a (glob) + undeleting dir/d (glob) + undeleting dir/dir2/b (glob) + forgetting dir/dir2/b2 (glob) + reverting dir/dir2/c (glob) + $ rm dir/a dir/dir2/b2 $ hg import --similarity 90 --no-commit - < diff --git a/a b/b > rename from a diff --git a/tests/test-import.t b/tests/test-import.t --- a/tests/test-import.t +++ b/tests/test-import.t @@ -670,6 +670,25 @@ test -p0 $ hg status $ cat a bb + +test --prefix + + $ mkdir -p dir/dir2 + $ echo b > dir/dir2/b + $ hg ci -Am b + adding dir/dir2/b + $ hg import -p2 --prefix dir - << EOF + > foobar + > --- drop1/drop2/dir2/b + > +++ drop1/drop2/dir2/b + > @@ -1,1 +1,1 @@ + > -b + > +cc + > EOF + applying patch from stdin + $ hg status + $ cat dir/dir2/b + cc $ cd ..