Patchwork patch.pathtransform: prepend prefix even if strip is 0

login
register
mail settings
Submitter Siddharth Agarwal
Date March 19, 2015, 4 a.m.
Message ID <7262bbef2ba80ce3ccfc.1426737608@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8158/
State Accepted
Commit 885a573fa619cceca33663ce3b02d988c45bcf38
Headers show

Comments

Siddharth Agarwal - March 19, 2015, 4 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1426737546 25200
#      Wed Mar 18 20:59:06 2015 -0700
# Node ID 7262bbef2ba80ce3ccfc726a19c0e33a419aff04
# Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
patch.pathtransform: prepend prefix even if strip is 0

Silly oversight by me.
Augie Fackler - March 19, 2015, 1:23 p.m.
On Wed, Mar 18, 2015 at 09:00:08PM -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1426737546 25200
> #      Wed Mar 18 20:59:06 2015 -0700
> # Node ID 7262bbef2ba80ce3ccfc726a19c0e33a419aff04
> # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
> patch.pathtransform: prepend prefix even if strip is 0

Queued, thanks.

>
> Silly oversight by me.
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -1465,6 +1465,8 @@
>      ('', '   a/b/c')
>      >>> pathtransform('   a/b/c   ', 2, '')
>      ('a/b/', 'c')
> +    >>> pathtransform('a/b/c', 0, 'd/e/')
> +    ('', 'd/e/a/b/c')
>      >>> pathtransform('   a//b/c   ', 2, 'd/e/')
>      ('a//b/', 'd/e/c')
>      >>> pathtransform('a/b/c', 3, '')
> @@ -1474,7 +1476,7 @@
>      pathlen = len(path)
>      i = 0
>      if strip == 0:
> -        return '', path.rstrip()
> +        return '', prefix + path.rstrip()
>      count = strip
>      while count > 0:
>          i = path.find('/', i)
> 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,29 @@
>    adding dir/d
>    adding dir/dir2/b
>    adding dir/dir2/c
> +  $ hg import --no-commit --prefix dir/ - <<EOF
> +  > diff --git a/a b/a
> +  > --- /dev/null
> +  > +++ b/a
> +  > @@ -0,0 +1 @@
> +  > +aaa
> +  > diff --git a/d b/d
> +  > --- a/d
> +  > +++ b/d
> +  > @@ -1,1 +1,2 @@
> +  >  d
> +  > +dd
> +  > EOF
> +  applying patch from stdin
> +  $ cat dir/a
> +  aaa
> +  $ cat dir/d
> +  d
> +  dd
> +  $ hg revert -aC
> +  forgetting dir/a
> +  reverting dir/d
> +  $ rm dir/a
>  (test that prefixes are relative to the root)
>    $ mkdir tmpdir
>    $ cd tmpdir
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Augie Fackler - March 19, 2015, 1:48 p.m.
On Thu, Mar 19, 2015 at 09:23:06AM -0400, Augie Fackler wrote:
> On Wed, Mar 18, 2015 at 09:00:08PM -0700, Siddharth Agarwal wrote:
> > # HG changeset patch
> > # User Siddharth Agarwal <sid0@fb.com>
> > # Date 1426737546 25200
> > #      Wed Mar 18 20:59:06 2015 -0700
> > # Node ID 7262bbef2ba80ce3ccfc726a19c0e33a419aff04
> > # Parent  5cb459dc32d209653a3e5d77749cf989ab9a51e4
> > patch.pathtransform: prepend prefix even if strip is 0
>
> Queued, thanks.

Oh, and check-code sends festive spring greetings.

>
> >
> > Silly oversight by me.
> >
> > diff --git a/mercurial/patch.py b/mercurial/patch.py
> > --- a/mercurial/patch.py
> > +++ b/mercurial/patch.py
> > @@ -1465,6 +1465,8 @@
> >      ('', '   a/b/c')
> >      >>> pathtransform('   a/b/c   ', 2, '')
> >      ('a/b/', 'c')
> > +    >>> pathtransform('a/b/c', 0, 'd/e/')
> > +    ('', 'd/e/a/b/c')
> >      >>> pathtransform('   a//b/c   ', 2, 'd/e/')
> >      ('a//b/', 'd/e/c')
> >      >>> pathtransform('a/b/c', 3, '')
> > @@ -1474,7 +1476,7 @@
> >      pathlen = len(path)
> >      i = 0
> >      if strip == 0:
> > -        return '', path.rstrip()
> > +        return '', prefix + path.rstrip()
> >      count = strip
> >      while count > 0:
> >          i = path.find('/', i)
> > 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,29 @@
> >    adding dir/d
> >    adding dir/dir2/b
> >    adding dir/dir2/c
> > +  $ hg import --no-commit --prefix dir/ - <<EOF
> > +  > diff --git a/a b/a
> > +  > --- /dev/null
> > +  > +++ b/a
> > +  > @@ -0,0 +1 @@
> > +  > +aaa
> > +  > diff --git a/d b/d
> > +  > --- a/d
> > +  > +++ b/d
> > +  > @@ -1,1 +1,2 @@
> > +  >  d
> > +  > +dd
> > +  > EOF
> > +  applying patch from stdin
> > +  $ cat dir/a
> > +  aaa
> > +  $ cat dir/d
> > +  d
> > +  dd
> > +  $ hg revert -aC
> > +  forgetting dir/a
> > +  reverting dir/d
> > +  $ rm dir/a
> >  (test that prefixes are relative to the root)
> >    $ mkdir tmpdir
> >    $ cd tmpdir
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel@selenic.com
> > http://selenic.com/mailman/listinfo/mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1465,6 +1465,8 @@ 
     ('', '   a/b/c')
     >>> pathtransform('   a/b/c   ', 2, '')
     ('a/b/', 'c')
+    >>> pathtransform('a/b/c', 0, 'd/e/')
+    ('', 'd/e/a/b/c')
     >>> pathtransform('   a//b/c   ', 2, 'd/e/')
     ('a//b/', 'd/e/c')
     >>> pathtransform('a/b/c', 3, '')
@@ -1474,7 +1476,7 @@ 
     pathlen = len(path)
     i = 0
     if strip == 0:
-        return '', path.rstrip()
+        return '', prefix + path.rstrip()
     count = strip
     while count > 0:
         i = path.find('/', i)
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,29 @@ 
   adding dir/d
   adding dir/dir2/b
   adding dir/dir2/c
+  $ hg import --no-commit --prefix dir/ - <<EOF
+  > diff --git a/a b/a
+  > --- /dev/null
+  > +++ b/a
+  > @@ -0,0 +1 @@
+  > +aaa
+  > diff --git a/d b/d
+  > --- a/d
+  > +++ b/d
+  > @@ -1,1 +1,2 @@
+  >  d
+  > +dd
+  > EOF
+  applying patch from stdin
+  $ cat dir/a
+  aaa
+  $ cat dir/d
+  d
+  dd
+  $ hg revert -aC
+  forgetting dir/a
+  reverting dir/d
+  $ rm dir/a
 (test that prefixes are relative to the root)
   $ mkdir tmpdir
   $ cd tmpdir