Patchwork [FOLLOWUP] mergestate: define NO_OP_ACTION in module scope instead of inside mergeresult

login
register
mail settings
Submitter Pulkit Goyal
Date Sept. 18, 2020, 11:22 a.m.
Message ID <dfb65ba955b4fddf86dd.1600428174@workspace>
Download mbox | patch
Permalink /patch/47216/
State New
Headers show

Comments

Pulkit Goyal - Sept. 18, 2020, 11:22 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1600259972 -19800
#      Wed Sep 16 18:09:32 2020 +0530
# Node ID dfb65ba955b4fddf86dd79cf8263989eb905ee3d
# Parent  bf0ed472c2b88c2fdf60a8c3c4aa3cd58a3a258c
# EXP-Topic merge-newnode
mergestate: define NO_OP_ACTION in module scope instead of inside mergeresult

This makes sure it isn't intended to be overridden by subclasses.
Thanks to Yuya for the nice suggestion.

Differential Revision: https://phab.mercurial-scm.org/D9025
Yuya Nishihara - Sept. 19, 2020, 2:39 a.m.
On Fri, 18 Sep 2020 16:52:54 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1600259972 -19800
> #      Wed Sep 16 18:09:32 2020 +0530
> # Node ID dfb65ba955b4fddf86dd79cf8263989eb905ee3d
> # Parent  bf0ed472c2b88c2fdf60a8c3c4aa3cd58a3a258c
> # EXP-Topic merge-newnode
> mergestate: define NO_OP_ACTION in module scope instead of inside mergeresult

> -    NO_OP_ACTIONS = (
> -        mergestatemod.ACTION_KEEP,
> -        mergestatemod.ACTION_KEEP_ABSENT,
> -        mergestatemod.ACTION_KEEP_NEW,
> -    )

Can't apply. Maybe some intermediate patches would be missing.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -540,7 +540,7 @@  def _filternarrowactions(narrowmatch, br
             pass
         elif not branchmerge:
             mresult.removefile(f)  # just updating, ignore changes outside clone
-        elif action[0] in mergeresult.NO_OP_ACTIONS:
+        elif action[0] in mergestatemod.NO_OP_ACTIONS:
             mresult.removefile(f)  # merge does not affect file
         elif action[0] in nonconflicttypes:
             raise error.Abort(
@@ -563,12 +563,6 @@  class mergeresult(object):
     It has information about what actions need to be performed on dirstate
     mapping of divergent renames and other such cases. '''
 
-    NO_OP_ACTIONS = (
-        mergestatemod.ACTION_KEEP,
-        mergestatemod.ACTION_KEEP_ABSENT,
-        mergestatemod.ACTION_KEEP_NEW,
-    )
-
     def __init__(self):
         """
         filemapping: dict of filename as keys and action related info as values
@@ -721,7 +715,7 @@  class mergeresult(object):
                     mergestatemod.ACTION_PATH_CONFLICT_RESOLVE,
                 )
                 and self._actionmapping[a]
-                and a not in self.NO_OP_ACTIONS
+                and a not in mergestatemod.NO_OP_ACTIONS
             ):
                 return True
 
@@ -1465,7 +1459,7 @@  def applyupdates(
         # mergestate so that it can be reused on commit
         ms.addcommitinfo(f, op)
 
-    numupdates = mresult.len() - mresult.len(mergeresult.NO_OP_ACTIONS)
+    numupdates = mresult.len() - mresult.len(mergestatemod.NO_OP_ACTIONS)
     progress = repo.ui.makeprogress(
         _(b'updating'), unit=_(b'files'), total=numupdates
     )
@@ -1569,7 +1563,7 @@  def applyupdates(
         progress.increment(item=f)
 
     # keep (noop, just log it)
-    for a in mergeresult.NO_OP_ACTIONS:
+    for a in mergestatemod.NO_OP_ACTIONS:
         for f, args, msg in mresult.getactions((a,), sort=True):
             repo.ui.debug(b" %s: %s -> %s\n" % (f, msg, a))
         # no progress
diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -129,6 +129,13 @@  ACTION_KEEP_NEW = b'kn'
 ACTION_EXEC = b'e'
 ACTION_CREATED_MERGE = b'cm'
 
+# actions which are no op
+NO_OP_ACTIONS = (
+    ACTION_KEEP,
+    ACTION_KEEP_ABSENT,
+    ACTION_KEEP_NEW,
+)
+
 
 class _mergestate_base(object):
     '''track 3-way merge state of individual files
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -399,7 +399,7 @@  def filterupdatesactions(repo, wctx, mct
             temporaryfiles.append(file)
             prunedactions[file] = action
         elif branchmerge:
-            if type not in mergemod.mergeresult.NO_OP_ACTIONS:
+            if type not in mergestatemod.NO_OP_ACTIONS:
                 temporaryfiles.append(file)
                 prunedactions[file] = action
         elif type == mergestatemod.ACTION_FORGET: