[Updated] D11420: dirstate: extract the logic to check file/dirname collision when adding a file

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Thu Sep 16 08:03:37 UTC 2021


Closed by commit rHG2e0ff3947b05: dirstate: extract the logic to check file/dirname collision when adding a file (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11420?vs=30250&id=30258

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11420/new/

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -676,20 +676,7 @@
     ):
         entry = self._map.get(f)
         if added or entry is not None and entry.removed:
-            scmutil.checkfilename(f)
-            if self._map.hastrackeddir(f):
-                msg = _(b'directory %r already in dirstate')
-                msg %= pycompat.bytestr(f)
-                raise error.Abort(msg)
-            # shadows
-            for d in pathutil.finddirs(f):
-                if self._map.hastrackeddir(d):
-                    break
-                entry = self._map.get(d)
-                if entry is not None and not entry.removed:
-                    msg = _(b'file %r in dirstate clashes with %r')
-                    msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
-                    raise error.Abort(msg)
+            self._check_new_tracked_filename(f)
         self._dirty = True
         self._updatedfiles.add(f)
         self._map.addfile(
@@ -703,6 +690,22 @@
             possibly_dirty=possibly_dirty,
         )
 
+    def _check_new_tracked_filename(self, filename):
+        scmutil.checkfilename(filename)
+        if self._map.hastrackeddir(filename):
+            msg = _(b'directory %r already in dirstate')
+            msg %= pycompat.bytestr(filename)
+            raise error.Abort(msg)
+        # shadows
+        for d in pathutil.finddirs(filename):
+            if self._map.hastrackeddir(d):
+                break
+            entry = self._map.get(d)
+            if entry is not None and not entry.removed:
+                msg = _(b'file %r in dirstate clashes with %r')
+                msg %= (pycompat.bytestr(d), pycompat.bytestr(filename))
+                raise error.Abort(msg)
+
     def _get_filedata(self, filename):
         """returns"""
         s = os.lstat(self._join(filename))



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210916/4402c8d4/attachment-0002.html>


More information about the Mercurial-patches mailing list