commitctx: return "touched" status from _filecommit
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 06 Jul 2020 19:35:53 +0200
changeset 45192 509f5b6c0b7e
parent 45180 a6fde9d789d9
child 45193 e64c35dfc6cb
commitctx: return "touched" status from _filecommit Instead of mutating a list passed in argument, we simply return the information from the `_filecommit` function. This make for a cleaner API and allow for richer information to be returned. That richer information will be used in the next commit to avoid duplicated computation. This is part of a larger refactoring/cleanup of the commitctx code to clarify and augment the logic gathering metadata useful for copy tracing. The current code is a tad too long and entangled to make such update easy. We start with easy and small cleanup. Differential Revision: https://phab.mercurial-scm.org/D8702
mercurial/localrepo.py
tests/test-annotate.t
tests/test-fastannotate-hg.t
--- a/mercurial/localrepo.py	Sat Jul 18 18:38:46 2020 +0900
+++ b/mercurial/localrepo.py	Mon Jul 06 19:35:53 2020 +0200
@@ -2772,14 +2772,7 @@
         return self._currentlock(self._wlockref)
 
     def _filecommit(
-        self,
-        fctx,
-        manifest1,
-        manifest2,
-        linkrev,
-        tr,
-        changelist,
-        includecopymeta,
+        self, fctx, manifest1, manifest2, linkrev, tr, includecopymeta,
     ):
         """
         commit an individual file as part of a larger transaction
@@ -2791,19 +2784,23 @@
             manifest2:  manifest of changeset second parent
             linkrev:    revision number of the changeset being created
             tr:         current transation
-            changelist: list of file being changed (modified inplace)
             individual: boolean, set to False to skip storing the copy data
                         (only used by the Google specific feature of using
                         changeset extra as copy source of truth).
 
-        output:
-
-            The resulting filenode
+        output: (filenode, touched)
+
+            filenode: the filenode that should be used by this changeset
+            touched:  one of: None, 'added' or 'modified'
         """
 
         fname = fctx.path()
         fparent1 = manifest1.get(fname, nullid)
         fparent2 = manifest2.get(fname, nullid)
+        touched = None
+        if fparent1 == fparent2 == nullid:
+            touched = 'added'
+
         if isinstance(fctx, context.filectx):
             node = fctx.filenode()
             if node in [fparent1, fparent2]:
@@ -2815,12 +2812,14 @@
                     fparent2 != nullid
                     and manifest2.flags(fname) != fctx.flags()
                 ):
-                    changelist.append(fname)
-                return node
+                    touched = 'modified'
+                return node, touched
 
         flog = self.file(fname)
         meta = {}
         cfname = fctx.copysource()
+        fnode = None
+
         if cfname and cfname != fname:
             # Mark the new revision of this file as a copy of another
             # file.  This copy data will effectively act as a parent
@@ -2897,13 +2896,16 @@
         # is the file changed?
         text = fctx.data()
         if fparent2 != nullid or meta or flog.cmp(fparent1, text):
-            changelist.append(fname)
-            return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
+            if touched is None:  # do not overwrite added
+                touched = 'modified'
+            fnode = flog.add(text, meta, tr, linkrev, fparent1, fparent2)
         # are just the flags changed during merge?
         elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
-            changelist.append(fname)
-
-        return fparent1
+            touched = 'modified'
+            fnode = fparent1
+        else:
+            fnode = fparent1
+        return fnode, touched
 
     def checkcommitpatterns(self, wctx, match, status, fail):
         """check for commit arguments that aren't committable"""
@@ -3131,15 +3133,11 @@
                             removed.append(f)
                         else:
                             added.append(f)
-                            m[f] = self._filecommit(
-                                fctx,
-                                m1,
-                                m2,
-                                linkrev,
-                                trp,
-                                changed,
-                                writefilecopymeta,
+                            m[f], is_touched = self._filecommit(
+                                fctx, m1, m2, linkrev, trp, writefilecopymeta,
                             )
+                            if is_touched:
+                                changed.append(f)
                             m.setflag(f, fctx.flags())
                     except OSError:
                         self.ui.warn(
--- a/tests/test-annotate.t	Sat Jul 18 18:38:46 2020 +0900
+++ b/tests/test-annotate.t	Mon Jul 06 19:35:53 2020 +0200
@@ -483,7 +483,7 @@
   > def reposetup(ui, repo):
   >     class legacyrepo(repo.__class__):
   >         def _filecommit(self, fctx, manifest1, manifest2,
-  >                         linkrev, tr, changelist, includecopymeta):
+  >                         linkrev, tr, includecopymeta):
   >             fname = fctx.path()
   >             text = fctx.data()
   >             flog = self.file(fname)
@@ -494,9 +494,8 @@
   >             if copy and copy != fname:
   >                 raise error.Abort('copying is not supported')
   >             if fparent2 != node.nullid:
-  >                 changelist.append(fname)
   >                 return flog.add(text, meta, tr, linkrev,
-  >                                 fparent1, fparent2)
+  >                                 fparent1, fparent2), 'modified'
   >             raise error.Abort('only merging is supported')
   >     repo.__class__ = legacyrepo
   > EOF
--- a/tests/test-fastannotate-hg.t	Sat Jul 18 18:38:46 2020 +0900
+++ b/tests/test-fastannotate-hg.t	Mon Jul 06 19:35:53 2020 +0200
@@ -485,7 +485,7 @@
   > def reposetup(ui, repo):
   >     class legacyrepo(repo.__class__):
   >         def _filecommit(self, fctx, manifest1, manifest2,
-  >                         linkrev, tr, changelist, includecopymeta):
+  >                         linkrev, tr, includecopymeta):
   >             fname = fctx.path()
   >             text = fctx.data()
   >             flog = self.file(fname)
@@ -496,9 +496,8 @@
   >             if copy and copy[0] != fname:
   >                 raise error.Abort('copying is not supported')
   >             if fparent2 != node.nullid:
-  >                 changelist.append(fname)
   >                 return flog.add(text, meta, tr, linkrev,
-  >                                 fparent1, fparent2)
+  >                                 fparent1, fparent2), 'modified'
   >             raise error.Abort('only merging is supported')
   >     repo.__class__ = legacyrepo
   > EOF