Patchwork copies: document hack for adding '' to set of dirs

login
register
mail settings
Submitter Martin von Zweigbergk
Date May 22, 2015, 9:06 p.m.
Message ID <d25b0f4d22dd272f7f09.1432328813@waste.org>
Download mbox | patch
Permalink /patch/9246/
State Accepted
Headers show

Comments

Martin von Zweigbergk - May 22, 2015, 9:06 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1432328524 25200
#      Fri May 22 14:02:04 2015 -0700
# Node ID d25b0f4d22dd272f7f0921345d2979b3ab221836
# Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
copies: document hack for adding '' to set of dirs

The root directory is not normally added to 'dirs' instances (although
I think it should be). In copies.mergecopies, we call dirname() to get
the directory of a path and then check for containment in the 'dirs'
instances ('d1' and 'd2'). In order to easily handle files in the root
directory, '/' is added to d1/d2. This results in the empty string
being added to the sets, since what comes before the slash in '/' is
an empty string. This seems less than obvious, so let's document it.
Martin von Zweigbergk - May 22, 2015, 9:09 p.m.
+CC:durham

Your patch reminded me of this. Should technically be applied after your
patches, since I've referred to your function name.

On Fri, May 22, 2015 at 2:07 PM Martin von Zweigbergk <martinvonz@google.com>
wrote:

> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1432328524 25200
> #      Fri May 22 14:02:04 2015 -0700
> # Node ID d25b0f4d22dd272f7f0921345d2979b3ab221836
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> copies: document hack for adding '' to set of dirs
>
> The root directory is not normally added to 'dirs' instances (although
> I think it should be). In copies.mergecopies, we call dirname() to get
> the directory of a path and then check for containment in the 'dirs'
> instances ('d1' and 'd2'). In order to easily handle files in the root
> directory, '/' is added to d1/d2. This results in the empty string
> being added to the sets, since what comes before the slash in '/' is
> an empty string. This seems less than obvious, so let's document it.
>
> diff --git a/mercurial/copies.py b/mercurial/copies.py
> --- a/mercurial/copies.py
> +++ b/mercurial/copies.py
> @@ -376,6 +376,7 @@
>
>      # generate a directory move map
>      d1, d2 = c1.dirs(), c2.dirs()
> +    # Hack for adding '', which is not otherwise added, to d1 and d2
>      d1.addpath('/')
>      d2.addpath('/')
>      invalid = set()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
Augie Fackler - May 26, 2015, 6:46 p.m.
On Fri, May 22, 2015 at 04:06:53PM -0500, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1432328524 25200
> #      Fri May 22 14:02:04 2015 -0700
> # Node ID d25b0f4d22dd272f7f0921345d2979b3ab221836
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> copies: document hack for adding '' to set of dirs

Looks useful, queued.

>
> The root directory is not normally added to 'dirs' instances (although
> I think it should be). In copies.mergecopies, we call dirname() to get
> the directory of a path and then check for containment in the 'dirs'
> instances ('d1' and 'd2'). In order to easily handle files in the root
> directory, '/' is added to d1/d2. This results in the empty string
> being added to the sets, since what comes before the slash in '/' is
> an empty string. This seems less than obvious, so let's document it.
>
> diff --git a/mercurial/copies.py b/mercurial/copies.py
> --- a/mercurial/copies.py
> +++ b/mercurial/copies.py
> @@ -376,6 +376,7 @@
>
>      # generate a directory move map
>      d1, d2 = c1.dirs(), c2.dirs()
> +    # Hack for adding '', which is not otherwise added, to d1 and d2
>      d1.addpath('/')
>      d2.addpath('/')
>      invalid = set()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -376,6 +376,7 @@ 
 
     # generate a directory move map
     d1, d2 = c1.dirs(), c2.dirs()
+    # Hack for adding '', which is not otherwise added, to d1 and d2
     d1.addpath('/')
     d2.addpath('/')
     invalid = set()