[PATCH on-crew] patch._applydiff: normalize prefix . to empty string

Augie Fackler raf at durin42.com
Thu Mar 19 12:31:10 CDT 2015


On Thu, Mar 19, 2015 at 10:19:53AM -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0 at fb.com>
> # Date 1426785485 25200
> #      Thu Mar 19 10:18:05 2015 -0700
> # Node ID fbae66bb86e6f4433996e5787e276eb79299fc46
> # Parent  7262bbef2ba80ce3ccfc726a19c0e33a419aff04
> patch._applydiff: normalize prefix . to empty string

I'm a little conflicted about this. What if I'm sitting in dir/ and
say --prefix=.? Shouldn't that work out to --prefix=dir?

>
> 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 . - <<EOF
> +  > 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/ - <<EOF
>    > diff --git a/a b/a
>    > --- /dev/null


More information about the Mercurial-devel mailing list