changeset 45708:60c46cc28bf4

commit: pass ChangingFiles object as argument to _process_files Instead of returning it, we pass it as an argument. This makes the whole if-else in `_prepare_files` a bit simpler. Else each if-else branch was creating the object. Differential Revision: https://phab.mercurial-scm.org/D9194
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 10 Oct 2020 13:19:25 +0530
parents 035302e6bb38
children 91fafafd5a68
files mercurial/commit.py
diffstat 1 files changed, 6 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commit.py	Sat Oct 10 13:15:20 2020 +0530
+++ b/mercurial/commit.py	Sat Oct 10 13:19:25 2020 +0530
@@ -114,14 +114,16 @@
     p1 = ctx.p1()
 
     writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
+    files = metadata.ChangingFiles()
     ms = mergestate.mergestate.read(repo)
     salvaged = _get_salvaged(repo, ms, ctx)
+    for s in salvaged:
+        files.mark_salvaged(s)
 
     if ctx.manifestnode():
         # reuse an existing manifest revision
         repo.ui.debug(b'reusing known manifest\n')
         mn = ctx.manifestnode()
-        files = metadata.ChangingFiles()
         files.update_touched(ctx.files())
         if writechangesetcopy:
             files.update_added(ctx.filesadded())
@@ -129,9 +131,8 @@
     elif not ctx.files():
         repo.ui.debug(b'reusing manifest from p1 (no file change)\n')
         mn = p1.manifestnode()
-        files = metadata.ChangingFiles()
     else:
-        mn, files = _process_files(tr, ctx, ms, error=error)
+        mn = _process_files(tr, ctx, ms, files, error=error)
 
     if origctx and origctx.manifestnode() == mn:
         origfiles = origctx.files()
@@ -142,9 +143,6 @@
         files.update_copies_from_p1(ctx.p1copies())
         files.update_copies_from_p2(ctx.p2copies())
 
-    for s in salvaged:
-        files.mark_salvaged(s)
-
     return mn, files
 
 
@@ -165,7 +163,7 @@
     return salvaged
 
 
-def _process_files(tr, ctx, ms, error=False):
+def _process_files(tr, ctx, ms, files, error=False):
     repo = ctx.repo()
     p1 = ctx.p1()
     p2 = ctx.p2()
@@ -180,8 +178,6 @@
     m1 = m1ctx.read()
     m2 = m2ctx.read()
 
-    files = metadata.ChangingFiles()
-
     # check in files
     added = []
     removed = list(ctx.removed())
@@ -231,7 +227,7 @@
 
     mn = _commit_manifest(tr, linkrev, ctx, mctx, m, files.touched, added, drop)
 
-    return mn, files
+    return mn
 
 
 def _filecommit(