Patchwork [1,of,3,V2] localrepo.status: ignore empty symlink placeholders

login
register
mail settings
Submitter Siddharth Agarwal
Date Aug. 31, 2013, 8:14 p.m.
Message ID <47ca48b126a916927160.1377980059@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2295/
State Superseded
Commit 36f48c7d594456b4ef7809230507518de2b958ce
Headers show

Comments

Siddharth Agarwal - Aug. 31, 2013, 8:14 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1377969366 25200
#      Sat Aug 31 10:16:06 2013 -0700
# Node ID 47ca48b126a91692716003fc904b27be519bcdcf
# Parent  d61b5370569659bd54a6de324655a0bb11d2af73
localrepo.status: ignore empty symlink placeholders

A symlink's target should never be empty in normal use. Solaris and some BSDs
do allow empty symlinks to be created (with varying semantics on dereference),
but a symlink placeholder that started off as empty is either

- going to be empty, in which case ignoring it is fine, since it's unchanged, or
- going to not be empty, in which case this check is irrelevant.
Augie Fackler - Sept. 3, 2013, 6:55 p.m.
On Sat, Aug 31, 2013 at 01:14:19PM -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1377969366 25200
> #      Sat Aug 31 10:16:06 2013 -0700
> # Node ID 47ca48b126a91692716003fc904b27be519bcdcf
> # Parent  d61b5370569659bd54a6de324655a0bb11d2af73
> localrepo.status: ignore empty symlink placeholders

> Solaris and some BSDs
> do allow empty symlinks to be created (with varying semantics on dereference),

I just made myself sad.

(patch lgtm, will finish reviewing series)

> but a symlink placeholder that started off as empty is either
>
> - going to be empty, in which case ignoring it is fine, since it's unchanged, or
> - going to not be empty, in which case this check is irrelevant.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1561,7 +1561,7 @@
>              for f in modified:
>                  if ctx2.flags(f) == 'l':
>                      d = ctx2[f].data()
> -                    if len(d) >= 1024 or '\n' in d or util.binary(d):
> +                    if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
>                          self.ui.debug('ignoring suspect symlink placeholder'
>                                        ' "%s"\n' % f)
>                          continue
> diff --git a/tests/test-symlink-placeholder.t b/tests/test-symlink-placeholder.t
> --- a/tests/test-symlink-placeholder.t
> +++ b/tests/test-symlink-placeholder.t
> @@ -41,6 +41,13 @@
>    a (no-eol)
>    $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
>
> +Empty placeholder:
> +
> +  $ rm b
> +  $ touch b
> +  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
> +  ignoring suspect symlink placeholder "b"
> +
>  Write binary data to the placeholder:
>
>    >>> open('b', 'w').write('this is a binary\0')
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1561,7 +1561,7 @@ 
             for f in modified:
                 if ctx2.flags(f) == 'l':
                     d = ctx2[f].data()
-                    if len(d) >= 1024 or '\n' in d or util.binary(d):
+                    if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
                         self.ui.debug('ignoring suspect symlink placeholder'
                                       ' "%s"\n' % f)
                         continue
diff --git a/tests/test-symlink-placeholder.t b/tests/test-symlink-placeholder.t
--- a/tests/test-symlink-placeholder.t
+++ b/tests/test-symlink-placeholder.t
@@ -41,6 +41,13 @@ 
   a (no-eol)
   $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
 
+Empty placeholder:
+
+  $ rm b
+  $ touch b
+  $ hg --config extensions.n=$TESTTMP/nolink.py st --debug
+  ignoring suspect symlink placeholder "b"
+
 Write binary data to the placeholder:
 
   >>> open('b', 'w').write('this is a binary\0')