From patchwork Thu Mar 19 17:19:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [on-crew] patch._applydiff: normalize prefix . to empty string From: Siddharth Agarwal X-Patchwork-Id: 8173 Message-Id: To: Cc: raf@durin42.com Date: Thu, 19 Mar 2015 10:19:53 -0700 # HG changeset patch # User Siddharth Agarwal # Date 1426785485 25200 # Thu Mar 19 10:18:05 2015 -0700 # Node ID fbae66bb86e6f4433996e5787e276eb79299fc46 # Parent 7262bbef2ba80ce3ccfc726a19c0e33a419aff04 patch._applydiff: normalize prefix . to empty string This is kind of an edge case, but it'd be nice for tools that use --prefix to not have to special case . themselves. (I made sure to put in the (glob) annotations this time!) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1796,7 +1796,11 @@ if prefix: # clean up double slashes, lack of trailing slashes, etc - prefix = util.normpath(prefix) + '/' + prefix = util.normpath(prefix) + if prefix == '.': + prefix = '' + else: + prefix += '/' def pstrip(p): return pathtransform(p, strip - 1, prefix)[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 @@ -626,6 +626,33 @@ adding dir/d adding dir/dir2/b adding dir/dir2/c + +prefix '.' is the same as no prefix + $ hg import --no-commit --prefix . - < diff --git a/dir/a b/dir/a + > --- /dev/null + > +++ b/dir/a + > @@ -0,0 +1 @@ + > +aaaa + > diff --git a/dir/d b/dir/d + > --- a/dir/d + > +++ b/dir/d + > @@ -1,1 +1,2 @@ + > d + > +dddd + > EOF + applying patch from stdin + $ cat dir/a + aaaa + $ cat dir/d + d + dddd + $ hg revert -aC + forgetting dir/a (glob) + reverting dir/d (glob) + $ rm dir/a + +prefix with default strip $ hg import --no-commit --prefix dir/ - < diff --git a/a b/a > --- /dev/null