dirstate: extract the logic to check file/dirname collision when adding a file
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 02 Sep 2021 04:03:20 +0200
changeset 47973 2e0ff3947b05
parent 47972 5a6c1ef4bcac
child 47974 4e6f27230aee
dirstate: extract the logic to check file/dirname collision when adding a file Differential Revision: https://phab.mercurial-scm.org/D11420
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Thu Sep 02 02:53:47 2021 +0200
+++ b/mercurial/dirstate.py	Thu Sep 02 04:03:20 2021 +0200
@@ -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))