Patchwork [2,of,5] commit: refactor salvage calculation to a different function

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

Comments

Pulkit Goyal - Oct. 13, 2020, 7:33 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1602314615 -19800
#      Sat Oct 10 12:53:35 2020 +0530
# Node ID d3df36bcf4a885038d5df6302f18008945ce48e7
# Parent  ca34efec098e04ef39341ef181c038f4a4522148
# EXP-Topic merge-newnode-final
commit: refactor salvage calculation to a different function

Differential Revision: https://phab.mercurial-scm.org/D9191
Yuya Nishihara - Oct. 13, 2020, 10:57 a.m.
On Tue, 13 Oct 2020 13:03:28 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1602314615 -19800
> #      Sat Oct 10 12:53:35 2020 +0530
> # Node ID d3df36bcf4a885038d5df6302f18008945ce48e7
> # Parent  ca34efec098e04ef39341ef181c038f4a4522148
> # EXP-Topic merge-newnode-final
> commit: refactor salvage calculation to a different function

Queued 2-5, thanks.

Patch

diff --git a/mercurial/commit.py b/mercurial/commit.py
--- a/mercurial/commit.py
+++ b/mercurial/commit.py
@@ -140,20 +140,29 @@  def _prepare_files(tr, ctx, error=False,
         files.update_copies_from_p1(ctx.p1copies())
         files.update_copies_from_p2(ctx.p2copies())
 
-    copy_sd = ctx.repo().filecopiesmode == b'changeset-sidedata'
+    ms = mergestate.mergestate.read(repo)
+    salvaged = _get_salvaged(ctx.repo(), ms, ctx)
+    for s in salvaged:
+        files.mark_salvaged(s)
+
+    return mn, files
+
+
+def _get_salvaged(repo, ms, ctx):
+    """ returns a list of salvaged files
+
+    returns empty list if config option which process salvaged files are
+    not enabled """
+    salvaged = []
+    copy_sd = repo.filecopiesmode == b'changeset-sidedata'
     if copy_sd and len(ctx.parents()) > 1:
-        # XXX this `mergestate.read` could be duplicated with a the merge state
-        # reading in _process_files So we could refactor further to reuse it in
-        # some cases.
-        ms = mergestate.mergestate.read(repo)
         if ms.active():
             for fname in sorted(ms.extras().keys()):
                 might_removed = ms.extras(fname).get(b'merge-removal-candidate')
                 if might_removed == b'yes':
                     if fname in ctx:
-                        files.mark_salvaged(fname)
-
-    return mn, files
+                        salvaged.append(fname)
+    return salvaged
 
 
 def _process_files(tr, ctx, error=False):