Patchwork [5,of,5] commit: pass ChangingFiles object as argument to _process_files

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 13, 2020, 7:33 a.m.
Message ID <0f38f9c9c4c83caa269a.1602574411@workspace>
Download mbox | patch
Permalink /patch/47441/
State Accepted
Headers show

Comments

Pulkit Goyal - Oct. 13, 2020, 7:33 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1602316165 -19800
#      Sat Oct 10 13:19:25 2020 +0530
# Node ID 0f38f9c9c4c83caa269a9fcdf6ad2a17d52f14e9
# Parent  104b104df7d9515967b87135977f434fb3560431
# EXP-Topic merge-newnode-final
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

Patch

diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -114,14 +114,16 @@  def _prepare_files(tr, ctx, error=False,
     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 @@  def _prepare_files(tr, ctx, error=False,
     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 @@  def _prepare_files(tr, ctx, error=False,
         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 @@  def _get_salvaged(repo, ms, ctx):
     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 @@  def _process_files(tr, ctx, ms, error=Fa
     m1 = m1ctx.read()
     m2 = m2ctx.read()
 
-    files = metadata.ChangingFiles()
-
     # check in files
     added = []
     removed = list(ctx.removed())
@@ -231,7 +227,7 @@  def _process_files(tr, ctx, ms, error=Fa
 
     mn = _commit_manifest(tr, linkrev, ctx, mctx, m, files.touched, added, drop)
 
-    return mn, files
+    return mn
 
 
 def _filecommit(