commitctx: create the ChangingFiles object directly in the various case
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Jul 2020 16:13:32 +0200
changeset 45328 e52031f5e046
parent 45327 6de4c5647db3
child 45329 dcbad0f17d76
commitctx: create the ChangingFiles object directly in the various case No need to compute all data then create the object, we can create it early and directly store data in it. We start simple by moving create higher in the function, but the end goal is to eventually move the creation inside the `_process_files` function to take advantage of the object there.
mercurial/commit.py
--- a/mercurial/commit.py	Sat Jul 25 16:13:17 2020 +0200
+++ b/mercurial/commit.py	Sat Jul 25 16:13:32 2020 +0200
@@ -115,36 +115,36 @@
 
     writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
 
-    filesadded, filesremoved = None, None
     if ctx.manifestnode():
         # reuse an existing manifest revision
         repo.ui.debug(b'reusing known manifest\n')
         mn = ctx.manifestnode()
-        touched = ctx.files()
+        files = metadata.ChangingFiles()
+        files.update_touched(ctx.files())
         if writechangesetcopy:
-            filesadded = ctx.filesadded()
-            filesremoved = ctx.filesremoved()
+            files.update_added(ctx.filesadded())
+            files.update_removed(ctx.filesremoved())
     elif not ctx.files():
         repo.ui.debug(b'reusing manifest from p1 (no file change)\n')
         mn = p1.manifestnode()
-        touched = []
+        files = metadata.ChangingFiles()
     else:
-        r = _process_files(tr, ctx, error=error)
-        mn, touched, filesadded, filesremoved = r
+        mn, touched, added, removed = _process_files(tr, ctx, error=error)
+        files = metadata.ChangingFiles()
+        files.update_touched(touched)
+        if added:
+            files.update_added(added)
+        if removed:
+            files.update_removed(removed)
 
     if origctx and origctx.manifestnode() == mn:
-        touched = origctx.files()
+        origfiles = origctx.files()
+        assert files.touched.issubset(origfiles)
+        files.update_touched(origfiles)
 
-    files = metadata.ChangingFiles()
-    if touched:
-        files.update_touched(touched)
     if writechangesetcopy:
         files.update_copies_from_p1(ctx.p1copies())
         files.update_copies_from_p2(ctx.p2copies())
-    if filesadded:
-        files.update_added(filesadded)
-    if filesremoved:
-        files.update_removed(filesremoved)
 
     return mn, files