Patchwork D626: merge: move cwd-missing detection to helper functions

login
register
mail settings
Submitter phabricator
Date Sept. 13, 2017, 2:31 a.m.
Message ID <29200abc004625627f528ddf9e2abbc3@localhost.localdomain>
Download mbox | patch
Permalink /patch/23822/
State Not Applicable
Headers show

Comments

phabricator - Sept. 13, 2017, 2:31 a.m.
phillco updated this revision to Diff 1775.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D626?vs=1606&id=1775

REVISION DETAIL
  https://phab.mercurial-scm.org/D626

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: phillco, #hg-reviewers, quark, pulkit
Cc: martinvonz, quark, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1084,18 +1084,21 @@ 
 
     return prunedactions, diverge, renamedelete
 
+def _getcwd():
+    try:
+        return pycompat.getcwd()
+    except OSError as err:
+        if err.errno == errno.ENOENT:
+            return None
+        raise
+
 def batchremove(repo, wctx, actions):
     """apply removes to the working directory
 
     yields tuples for progress updates
     """
     verbose = repo.ui.verbose
-    try:
-        cwd = pycompat.getcwd()
-    except OSError as err:
-        if err.errno != errno.ENOENT:
-            raise
-        cwd = None
+    cwd = _getcwd()
     i = 0
     for f, args, msg in actions:
         repo.ui.debug(" %s: %s -> r\n" % (f, msg))
@@ -1113,18 +1116,12 @@ 
         i += 1
     if i > 0:
         yield i, f
-    if cwd:
-        # cwd was present before we started to remove files
-        # let's check if it is present after we removed them
-        try:
-            pycompat.getcwd()
-        except OSError as err:
-            if err.errno != errno.ENOENT:
-                raise
-            # Print a warning if cwd was deleted
-            repo.ui.warn(_("current directory was removed\n"
-                           "(consider changing to repo root: %s)\n") %
-                         repo.root)
+
+    if cwd and not _getcwd():
+        # cwd was removed in the course of removing files; print a helpful
+        # warning.
+        repo.ui.warn(_("current directory was removed\n"
+                       "(consider changing to repo root: %s)\n") % repo.root)
 
     # It's necessary to flush here in case we're inside a worker fork and will
     # quit after this function.