Patchwork update: fix bug when update tries to modify folder symlink

login
register
mail settings
Submitter Kostia Balytskyi
Date July 21, 2016, 10:56 p.m.
Message ID <3d5d3b8471ebed15fc8c.1469141797@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/15967/
State Accepted
Headers show

Comments

Kostia Balytskyi - July 21, 2016, 10:56 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1469141747 25200
#      Thu Jul 21 15:55:47 2016 -0700
# Branch stable
# Node ID 3d5d3b8471ebed15fc8c1fd8243afe64a3908591
# Parent  53e80179bd6ad4e03a0d1cc19dcb2deed8d2fbf5
update: fix bug when update tries to modify folder symlink

In 1e4512eac59e0114bc60ecbcdc4157fc0fa0439d, I introduced a new bug:
when a symlink points to a folder in commit A and to another folder
in commit B, while updating from A to B, Mercurial will try to use
removedir on this symlink, which will fail. This is a very bad bug,
since it basically renders symlinks to folders unusable in repos.

Added test case fails without a fix and passes with it.
Matt Mackall - July 21, 2016, 11:15 p.m.
On Thu, 2016-07-21 at 15:56 -0700, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1469141747 25200
> #      Thu Jul 21 15:55:47 2016 -0700
> # Branch stable
> # Node ID 3d5d3b8471ebed15fc8c1fd8243afe64a3908591
> # Parent  53e80179bd6ad4e03a0d1cc19dcb2deed8d2fbf5
> update: fix bug when update tries to modify folder symlink

Queued for stable, thanks.

-- 
Mathematics is the supreme nostalgia of our time.
Yuya Nishihara - July 26, 2016, 12:19 p.m.
On Thu, 21 Jul 2016 15:56:37 -0700, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1469141747 25200
> #      Thu Jul 21 15:55:47 2016 -0700
> # Branch stable
> # Node ID 3d5d3b8471ebed15fc8c1fd8243afe64a3908591
> # Parent  53e80179bd6ad4e03a0d1cc19dcb2deed8d2fbf5
> update: fix bug when update tries to modify folder symlink

> --- a/tests/test-update-names.t
> +++ b/tests/test-update-names.t
> @@ -53,3 +53,19 @@ make sure that this does not erase untra
>    abort: *: '$TESTTMP/r1/r2/name' (glob)
>    [255]
>    $ cd ..

I've added "#if symlink" in flight.

> +Test update when two commits have symlinks that point to different folders
> +  $ hg init r3 && cd r3
> +  $ echo root > root && hg ci -Am root
> +  adding root
> +  $ mkdir folder1 && mkdir folder2
> +  $ ln -s folder1 folder
> +  $ hg ci -Am "symlink to folder1"
> +  adding folder
> +  $ rm folder
> +  $ ln -s folder2 folder
> +  $ hg ci -Am "symlink to folder2"
> +  $ hg up 1
> +  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ cd ..

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1082,7 +1082,7 @@  def batchget(repo, mctx, actions):
                     if e.errno != errno.ENOENT:
                         raise
 
-            if repo.wvfs.isdir(f):
+            if repo.wvfs.isdir(f) and not repo.wvfs.islink(f):
                 repo.wvfs.removedirs(f)
             wwrite(f, fctx(f).data(), flags, backgroundclose=True)
             if i == 100:
diff --git a/tests/test-update-names.t b/tests/test-update-names.t
--- a/tests/test-update-names.t
+++ b/tests/test-update-names.t
@@ -53,3 +53,19 @@  make sure that this does not erase untra
   abort: *: '$TESTTMP/r1/r2/name' (glob)
   [255]
   $ cd ..
+
+Test update when two commits have symlinks that point to different folders
+  $ hg init r3 && cd r3
+  $ echo root > root && hg ci -Am root
+  adding root
+  $ mkdir folder1 && mkdir folder2
+  $ ln -s folder1 folder
+  $ hg ci -Am "symlink to folder1"
+  adding folder
+  $ rm folder
+  $ ln -s folder2 folder
+  $ hg ci -Am "symlink to folder2"
+  $ hg up 1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ..
+