Patchwork [11,of,15] commitctx: create the ChangingFiles object directly in the various case

login
register
mail settings
Submitter Pierre-Yves David
Date July 29, 2020, 4:57 p.m.
Message ID <3bcb3b9adf1f0b5eb0ab.1596041861@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/46932/
State Accepted
Headers show

Comments

Pierre-Yves David - July 29, 2020, 4:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1595686412 -7200
#      Sat Jul 25 16:13:32 2020 +0200
# Node ID 3bcb3b9adf1f0b5eb0ab6b4964b756162cc269b5
# Parent  9d1d1cb2d9583aaf7c34d51808b309df9a55a12c
# EXP-Topic files-change
# Available At https://foss.heptapod.net/octobus/mercurial-devel/
#              hg pull https://foss.heptapod.net/octobus/mercurial-devel/ -r 3bcb3b9adf1f
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.

Patch

diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -115,36 +115,36 @@  def _prepare_files(tr, ctx, error=False,
 
     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