Patchwork [V3] update: warn if cwd was deleted

login
register
mail settings
Submitter Stanislau Hlebik
Date Sept. 5, 2016, 10:32 a.m.
Message ID <b43aa94306b8f50852a8.1473071529@dev1918.lla1.facebook.com>
Download mbox | patch
Permalink /patch/16549/
State Changes Requested
Headers show

Comments

Stanislau Hlebik - Sept. 5, 2016, 10:32 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1473071480 25200
#      Mon Sep 05 03:31:20 2016 -0700
# Node ID b43aa94306b8f50852a8176afec3839aa3826467
# Parent  f148bfa40489269be2e48046734f81065129847a
update: warn if cwd was deleted

During update directories are deleted as soon as they have no entries.
But if current working directory is deleted then it cause problems
in complex commands like 'hg split'. This commit adds a warning
that will help users figure the problem faster.
timeless - Sept. 7, 2016, 7:35 p.m.
There should probably be a colon after "root"

On Sep 5, 2016 6:33 AM, "Stanislau Hlebik" <stash@fb.com> wrote:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1473071480 25200
> #      Mon Sep 05 03:31:20 2016 -0700
> # Node ID b43aa94306b8f50852a8176afec3839aa3826467
> # Parent  f148bfa40489269be2e48046734f81065129847a
> update: warn if cwd was deleted
>
> During update directories are deleted as soon as they have no entries.
> But if current working directory is deleted then it cause problems
> in complex commands like 'hg split'. This commit adds a warning
> that will help users figure the problem faster.
>
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -1043,7 +1043,20 @@
>              repo.ui.note(_("removing %s\n") % f)
>          audit(f)
>          try:
> -            unlink(wjoin(f), ignoremissing=True)
> +            try:
> +                cwd = os.getcwd()
> +            except OSError:
> +                cwd = None
> +            path = wjoin(f)
> +            unlink(path, ignoremissing=True)
> +            try:
> +                os.getcwd()
> +            except OSError:
> +                # Print a warning if cwd was deleted
> +                if cwd and path.startswith(cwd):
> +                    repo.ui.warn(_("cwd was deleted - consider "
> +                                   "changing cwd to repo root %s\n") %
> +                                 repo.root)
>          except OSError as inst:
>              repo.ui.warn(_("update failed to remove %s: %s!\n") %
>                           (f, inst.strerror))
> diff --git a/tests/test-rebase-scenario-global.t
> b/tests/test-rebase-scenario-global.t
> --- a/tests/test-rebase-scenario-global.t
> +++ b/tests/test-rebase-scenario-global.t
> @@ -758,6 +758,7 @@
>    $ hg commit -m 'second source with subdir'
>    $ hg rebase -b . -d 1 --traceback
>    rebasing 2:779a07b1b7a0 "first source commit"
> +  cwd was deleted - consider changing cwd to repo root * (glob)
>    rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
>    saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-
> backup/779a07b1b7a0-853e0073-backup.hg (glob)
>
> 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
> @@ -72,3 +72,14 @@
>    $ cd ..
>
>  #endif
> +
> +Test that warning is printed if cwd is deleted during update
> +  $ hg init r4 && cd r4
> +  $ mkdir dir
> +  $ cd dir
> +  $ echo a > a
> +  $ echo b > b
> +  $ hg add a b
> +  $ hg ci -m "file and dir"
> +  $ hg up -q null
> +  cwd was deleted - consider changing cwd to repo root * (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Bryan O'Sullivan - Sept. 8, 2016, 3:49 p.m.
You are performing these getcwd calls inside what should be a fast inner
loop. This is going to dramatically slow the common case down by doing a
whole lot of redundant work.

All you need to do to fix this is check getcwd once before the loop begins,
and then again after it ends.

On Mon, Sep 5, 2016 at 3:32 AM, Stanislau Hlebik <stash@fb.com> wrote:

> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1473071480 25200
> #      Mon Sep 05 03:31:20 2016 -0700
> # Node ID b43aa94306b8f50852a8176afec3839aa3826467
> # Parent  f148bfa40489269be2e48046734f81065129847a
> update: warn if cwd was deleted
>
> During update directories are deleted as soon as they have no entries.
> But if current working directory is deleted then it cause problems
> in complex commands like 'hg split'. This commit adds a warning
> that will help users figure the problem faster.
>
> diff --git a/mercurial/merge.py b/mercurial/merge.py
> --- a/mercurial/merge.py
> +++ b/mercurial/merge.py
> @@ -1043,7 +1043,20 @@
>              repo.ui.note(_("removing %s\n") % f)
>          audit(f)
>          try:
> -            unlink(wjoin(f), ignoremissing=True)
> +            try:
> +                cwd = os.getcwd()
> +            except OSError:
> +                cwd = None
> +            path = wjoin(f)
> +            unlink(path, ignoremissing=True)
> +            try:
> +                os.getcwd()
> +            except OSError:
> +                # Print a warning if cwd was deleted
> +                if cwd and path.startswith(cwd):
> +                    repo.ui.warn(_("cwd was deleted - consider "
> +                                   "changing cwd to repo root %s\n") %
> +                                 repo.root)
>          except OSError as inst:
>              repo.ui.warn(_("update failed to remove %s: %s!\n") %
>                           (f, inst.strerror))
> diff --git a/tests/test-rebase-scenario-global.t
> b/tests/test-rebase-scenario-global.t
> --- a/tests/test-rebase-scenario-global.t
> +++ b/tests/test-rebase-scenario-global.t
> @@ -758,6 +758,7 @@
>    $ hg commit -m 'second source with subdir'
>    $ hg rebase -b . -d 1 --traceback
>    rebasing 2:779a07b1b7a0 "first source commit"
> +  cwd was deleted - consider changing cwd to repo root * (glob)
>    rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
>    saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-
> backup/779a07b1b7a0-853e0073-backup.hg (glob)
>
> 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
> @@ -72,3 +72,14 @@
>    $ cd ..
>
>  #endif
> +
> +Test that warning is printed if cwd is deleted during update
> +  $ hg init r4 && cd r4
> +  $ mkdir dir
> +  $ cd dir
> +  $ echo a > a
> +  $ echo b > b
> +  $ hg add a b
> +  $ hg ci -m "file and dir"
> +  $ hg up -q null
> +  cwd was deleted - consider changing cwd to repo root * (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1043,7 +1043,20 @@ 
             repo.ui.note(_("removing %s\n") % f)
         audit(f)
         try:
-            unlink(wjoin(f), ignoremissing=True)
+            try:
+                cwd = os.getcwd()
+            except OSError:
+                cwd = None
+            path = wjoin(f)
+            unlink(path, ignoremissing=True)
+            try:
+                os.getcwd()
+            except OSError:
+                # Print a warning if cwd was deleted
+                if cwd and path.startswith(cwd):
+                    repo.ui.warn(_("cwd was deleted - consider "
+                                   "changing cwd to repo root %s\n") %
+                                 repo.root)
         except OSError as inst:
             repo.ui.warn(_("update failed to remove %s: %s!\n") %
                          (f, inst.strerror))
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -758,6 +758,7 @@ 
   $ hg commit -m 'second source with subdir'
   $ hg rebase -b . -d 1 --traceback
   rebasing 2:779a07b1b7a0 "first source commit"
+  cwd was deleted - consider changing cwd to repo root * (glob)
   rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
   saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-853e0073-backup.hg (glob)
 
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
@@ -72,3 +72,14 @@ 
   $ cd ..
 
 #endif
+
+Test that warning is printed if cwd is deleted during update
+  $ hg init r4 && cd r4
+  $ mkdir dir
+  $ cd dir
+  $ echo a > a
+  $ echo b > b
+  $ hg add a b
+  $ hg ci -m "file and dir"
+  $ hg up -q null
+  cwd was deleted - consider changing cwd to repo root * (glob)