D12114: merge-actions: make merge action a full featured object

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This open the way for having "smarter" value as action, making the usage code
  simpler and more flexible.
  
  We have to explicitly use __bytes__ call in a couple of place because Python2…

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12114

AFFECTED FILES
  hgext/largefiles/overrides.py
  mercurial/merge.py
  mercurial/mergestate.py

CHANGE DETAILS

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -98,29 +98,59 @@
 LEGACY_MERGE_DRIVER_MERGE = b'D'
 
 
-ACTION_FORGET = b'f'
-ACTION_REMOVE = b'r'
-ACTION_ADD = b'a'
-ACTION_GET = b'g'
-ACTION_PATH_CONFLICT = b'p'
-ACTION_PATH_CONFLICT_RESOLVE = b'pr'
-ACTION_ADD_MODIFIED = b'am'
-ACTION_CREATED = b'c'
-ACTION_DELETED_CHANGED = b'dc'
-ACTION_CHANGED_DELETED = b'cd'
-ACTION_MERGE = b'm'
-ACTION_LOCAL_DIR_RENAME_GET = b'dg'
-ACTION_DIR_RENAME_MOVE_LOCAL = b'dm'
-ACTION_KEEP = b'k'
+class MergeAction(object):
+"""represent an "action" merge need to take for a given file
+
+Attributes:
+
+_short: internal representation used to identify each action
+"""
+
+def __init__(self, short):
+self._short = short
+
+def __hash__(self):
+return hash(self._short)
+
+def __repr__(self):
+return 'MergeAction<%s>' % self._short.decode('ascii')
+
+def __bytes__(self):
+return self._short
+
+def __eq__(self, other):
+if other is None:
+return False
+assert isinstance(other, MergeAction)
+return self._short == other._short
+
+def __lt__(self, other):
+return self._short < other._short
+
+
+ACTION_FORGET = MergeAction(b'f')
+ACTION_REMOVE = MergeAction(b'r')
+ACTION_ADD = MergeAction(b'a')
+ACTION_GET = MergeAction(b'g')
+ACTION_PATH_CONFLICT = MergeAction(b'p')
+ACTION_PATH_CONFLICT_RESOLVE = MergeAction('pr')
+ACTION_ADD_MODIFIED = MergeAction(b'am')
+ACTION_CREATED = MergeAction(b'c')
+ACTION_DELETED_CHANGED = MergeAction(b'dc')
+ACTION_CHANGED_DELETED = MergeAction(b'cd')
+ACTION_MERGE = MergeAction(b'm')
+ACTION_LOCAL_DIR_RENAME_GET = MergeAction(b'dg')
+ACTION_DIR_RENAME_MOVE_LOCAL = MergeAction(b'dm')
+ACTION_KEEP = MergeAction(b'k')
 # the file was absent on local side before merge and we should
 # keep it absent (absent means file not present, it can be a result
 # of file deletion, rename etc.)
-ACTION_KEEP_ABSENT = b'ka'
+ACTION_KEEP_ABSENT = MergeAction(b'ka')
 # the file is absent on the ancestor and remote side of the merge
 # hence this file is new and we should keep it
-ACTION_KEEP_NEW = b'kn'
-ACTION_EXEC = b'e'
-ACTION_CREATED_MERGE = b'cm'
+ACTION_KEEP_NEW = MergeAction(b'kn')
+ACTION_EXEC = MergeAction(b'e')
+ACTION_CREATED_MERGE = MergeAction(b'cm')
 
 # actions which are no op
 NO_OP_ACTIONS = (
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1201,7 +1201,7 @@
 
 for f, a in mresult1.filemap(sort=True):
 m, args, msg = a
-repo.ui.debug(b' %s: %s -> %s\n' % (f, msg, m))
+repo.ui.debug(b' %s: %s -> %s\n' % (f, msg, m.__bytes__()))
 if f in fbids:
 d = fbids[f]
 if m in d:
@@ -1222,13 +1222,15 @@
 repo.ui.debug(b" list of bids for %s:\n" % f)
 for m, l in sorted(bids.items()):
 for _f, args, msg in l:
-repo.ui.debug(b'   %s -> %s\n' % (msg, m))
+repo.ui.debug(b'   %s -> %s\n' % (msg, m.__bytes__()))
 # bids is a mapping from action method to list af actions
 # Consensus?
 if len(bids) == 1:  # all bids are the same kind of method
 m, l = list(bids.items())[0]
 if all(a == l[0] for a in l[1:]):  # len(bids) is > 1
-repo.ui.note(_(b" %s: consensus for %s\n") % (f, m))
+repo.ui.note(
+_(b" %s: consensus for %s\n") % (f, m.__bytes__())
+)
 mresult.addfile(f, *l[0])
 continue
 # If keep is an option, just do it.
@@ -1286,11 +1288,12 @@
 repo.ui.note(_(b' %s: multiple bids for merge action:\n') % f)
 for m, l in sorted(bids.items()):
 for _f, args, msg in l:
-repo.ui.note(b'  %s -> %s\n' % (msg, m))
+repo.ui.note(b'  %s -> %s\n' % (msg, m.__bytes__()))
 # Pick random action. TODO: Instead, prompt user when resolving
 m, l = list(bids.items())[0]
 repo.ui.warn(
-_(b' %s: ambiguous merge - picked %s action\n') % (f, m)
+_(b' %s: ambiguous merge - picked %s action\n')
+

D12116: merge-actions: add an explicite "no_op" attribute

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This make the MergeAction smarter and able to describe themself. This is 
useful
  to help introducing more MergeAction object that better the complexity of the
  situation.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12116

AFFECTED FILES
  mercurial/merge.py
  mercurial/mergestate.py
  mercurial/sparse.py

CHANGE DETAILS

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -396,7 +396,7 @@
 temporaryfiles.append(file)
 prunedactions[file] = action
 elif branchmerge:
-if type not in mergestatemod.NO_OP_ACTIONS:
+if not type.no_op:
 temporaryfiles.append(file)
 prunedactions[file] = action
 elif type == mergestatemod.ACTION_FORGET:
diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -105,13 +105,19 @@
 Attributes:
 
 _short: internal representation used to identify each action
+
+no_op:  True if the action does affect the file content or tracking status
 """
 
 ALL_ACTIONS = weakref.WeakSet()
+NO_OP_ACTIONS = weakref.WeakSet()
 
-def __init__(self, short):
+def __init__(self, short, no_op=False):
 self._short = short
 self.ALL_ACTIONS.add(self)
+self.no_op = no_op
+if self.no_op:
+self.NO_OP_ACTIONS.add(self)
 
 def __hash__(self):
 return hash(self._short)
@@ -145,23 +151,17 @@
 ACTION_MERGE = MergeAction(b'm')
 ACTION_LOCAL_DIR_RENAME_GET = MergeAction(b'dg')
 ACTION_DIR_RENAME_MOVE_LOCAL = MergeAction(b'dm')
-ACTION_KEEP = MergeAction(b'k')
+ACTION_KEEP = MergeAction(b'k', no_op=True)
 # the file was absent on local side before merge and we should
 # keep it absent (absent means file not present, it can be a result
 # of file deletion, rename etc.)
-ACTION_KEEP_ABSENT = MergeAction(b'ka')
+ACTION_KEEP_ABSENT = MergeAction(b'ka', no_op=True)
 # the file is absent on the ancestor and remote side of the merge
 # hence this file is new and we should keep it
-ACTION_KEEP_NEW = MergeAction(b'kn')
+ACTION_KEEP_NEW = MergeAction(b'kn', no_op=True)
 ACTION_EXEC = MergeAction(b'e')
 ACTION_CREATED_MERGE = MergeAction(b'cm')
 
-# actions which are no op
-NO_OP_ACTIONS = (
-ACTION_KEEP,
-ACTION_KEEP_ABSENT,
-ACTION_KEEP_NEW,
-)
 
 # Used by concert to detect situation it does not like, not sure what the exact
 # criteria is
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -527,7 +527,7 @@
 pass
 elif not branchmerge:
 mresult.removefile(f)  # just updating, ignore changes outside 
clone
-elif action[0] in mergestatemod.NO_OP_ACTIONS:
+elif action[0].no_op:
 mresult.removefile(f)  # merge does not affect file
 elif action[0] in nonconflicttypes:
 msg = _(
@@ -699,7 +699,7 @@
 mergestatemod.ACTION_PATH_CONFLICT_RESOLVE,
 )
 and self._actionmapping[a]
-and a not in mergestatemod.NO_OP_ACTIONS
+and not a.no_op
 ):
 return True
 
@@ -1520,7 +1520,8 @@
 # mergestate so that it can be reused on commit
 ms.addcommitinfo(f, op)
 
-numupdates = mresult.len() - mresult.len(mergestatemod.NO_OP_ACTIONS)
+num_no_op = mresult.len(mergestatemod.MergeAction.NO_OP_ACTIONS)
+numupdates = mresult.len() - num_no_op
 progress = repo.ui.makeprogress(
 _(b'updating'), unit=_(b'files'), total=numupdates
 )
@@ -1624,7 +1625,7 @@
 progress.increment(item=f)
 
 # keep (noop, just log it)
-for a in mergestatemod.NO_OP_ACTIONS:
+for a in mergestatemod.MergeAction.NO_OP_ACTIONS:
 for f, args, msg in mresult.getactions((a,), sort=True):
 repo.ui.debug(b" %s: %s -> %s\n" % (f, msg, a.__bytes__()))
 # no progress



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12115: merge-actions: gather all created action into a set

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is mostly to demonstrate we can do this before we start adding more
  specialized set.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12115

AFFECTED FILES
  mercurial/mergestate.py

CHANGE DETAILS

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -4,6 +4,7 @@
 import errno
 import shutil
 import struct
+import weakref
 
 from .i18n import _
 from .node import (
@@ -106,8 +107,11 @@
 _short: internal representation used to identify each action
 """
 
+ALL_ACTIONS = weakref.WeakSet()
+
 def __init__(self, short):
 self._short = short
+self.ALL_ACTIONS.add(self)
 
 def __hash__(self):
 return hash(self._short)



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12113: convert: use the merge action constant

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The constant exists, lets use them. Otherwise we cannot make these constant 
more
  powerful.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12113

AFFECTED FILES
  hgext/convert/hg.py
  mercurial/mergestate.py

CHANGE DETAILS

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -129,6 +129,15 @@
 ACTION_KEEP_NEW,
 )
 
+# Used by concert to detect situation it does not like, not sure what the exact
+# criteria is
+CONVERT_MERGE_ACTIONS = (
+ACTION_MERGE,
+ACTION_DIR_RENAME_MOVE_LOCAL,
+ACTION_CHANGED_DELETED,
+ACTION_DELETED_CHANGED,
+)
+
 
 class _mergestate_base(object):
 """track 3-way merge state of individual files
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -38,6 +38,7 @@
 lock as lockmod,
 logcmdutil,
 merge as mergemod,
+mergestate,
 phases,
 pycompat,
 util,
@@ -241,7 +242,7 @@
 
 # If the file requires actual merging, abort. We don't have enough
 # context to resolve merges correctly.
-if action in [b'm', b'dm', b'cd', b'dc']:
+if action in mergestate.CONVERT_MERGE_ACTIONS:
 raise error.Abort(
 _(
 b"unable to convert merge commit "
@@ -250,7 +251,7 @@
 )
 % (file, p1ctx, p2ctx)
 )
-elif action == b'k':
+elif action == mergestate.ACTION_KEEP:
 # 'keep' means nothing changed from p1
 continue
 else:



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12112: large-file: use the merge action constant

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The constant exists, lets use them. Otherwise we cannot make these constant 
more
  powerful.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12112

AFFECTED FILES
  hgext/largefiles/overrides.py

CHANGE DETAILS

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -51,6 +51,12 @@
 storefactory,
 )
 
+ACTION_ADD = mergestatemod.ACTION_ADD
+ACTION_DELETED_CHANGED = mergestatemod.ACTION_DELETED_CHANGED
+ACTION_GET = mergestatemod.ACTION_GET
+ACTION_KEEP = mergestatemod.ACTION_KEEP
+ACTION_REMOVE = mergestatemod.ACTION_REMOVE
+
 eh = exthelper.exthelper()
 
 lfstatus = lfutil.lfstatus
@@ -563,8 +569,9 @@
 standin = lfutil.standin(lfile)
 (lm, largs, lmsg) = mresult.getfile(lfile, (None, None, None))
 (sm, sargs, smsg) = mresult.getfile(standin, (None, None, None))
-if sm in (b'g', b'dc') and lm != b'r':
-if sm == b'dc':
+
+if sm in (ACTION_GET, ACTION_DELETED_CHANGED) and lm != ACTION_REMOVE:
+if sm == ACTION_DELETED_CHANGED:
 f1, f2, fa, move, anc = sargs
 sargs = (p2[f2].flags(), False)
 # Case 1: normal file in the working copy, largefile in
@@ -578,26 +585,28 @@
 % lfile
 )
 if repo.ui.promptchoice(usermsg, 0) == 0:  # pick remote largefile
-mresult.addfile(lfile, b'r', None, b'replaced by standin')
-mresult.addfile(standin, b'g', sargs, b'replaces standin')
+mresult.addfile(
+lfile, ACTION_REMOVE, None, b'replaced by standin'
+)
+mresult.addfile(standin, ACTION_GET, sargs, b'replaces 
standin')
 else:  # keep local normal file
-mresult.addfile(lfile, b'k', None, b'replaces standin')
+mresult.addfile(lfile, ACTION_KEEP, None, b'replaces standin')
 if branchmerge:
 mresult.addfile(
 standin,
-b'k',
+ACTION_KEEP,
 None,
 b'replaced by non-standin',
 )
 else:
 mresult.addfile(
 standin,
-b'r',
+ACTION_REMOVE,
 None,
 b'replaced by non-standin',
 )
-elif lm in (b'g', b'dc') and sm != b'r':
-if lm == b'dc':
+if lm in (ACTION_GET, ACTION_DELETED_CHANGED) and sm != ACTION_REMOVE:
+if lm == ACTION_DELETED_CHANGED:
 f1, f2, fa, move, anc = largs
 largs = (p2[f2].flags(), False)
 # Case 2: largefile in the working copy, normal file in
@@ -615,11 +624,13 @@
 # largefile can be restored from standin safely
 mresult.addfile(
 lfile,
-b'k',
+ACTION_KEEP,
 None,
 b'replaced by standin',
 )
-mresult.addfile(standin, b'k', None, b'replaces standin')
+mresult.addfile(
+standin, ACTION_KEEP, None, b'replaces standin'
+)
 else:
 # "lfile" should be marked as "removed" without
 # removal of itself
@@ -631,12 +642,12 @@
 )
 
 # linear-merge should treat this largefile as 're-added'
-mresult.addfile(standin, b'a', None, b'keep standin')
+mresult.addfile(standin, ACTION_ADD, None, b'keep standin')
 else:  # pick remote normal file
-mresult.addfile(lfile, b'g', largs, b'replaces standin')
+mresult.addfile(lfile, ACTION_GET, largs, b'replaces standin')
 mresult.addfile(
 standin,
-b'r',
+ACTION_REMOVE,
 None,
 b'replaced by non-standin',
 )



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12111: merge: stop using merge action for pathconflict option

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is not the b'r' you are looking for.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12111

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -488,7 +488,7 @@
 mresult.addfile(
 p,
 mergestatemod.ACTION_PATH_CONFLICT,
-(pnew, mergestatemod.ACTION_REMOVE),
+(pnew, b'r'),
 b'path conflict',
 )
 remoteconflicts.remove(p)



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12110: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12110

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2368,9 +2368,8 @@
 def back_out(ctx, parent=None, wc=None):
 if parent is None:
 if ctx.p2() is not None:
-raise error.ProgrammingError(
-b"must specify parent of merge commit to back out"
-)
+msg = b"must specify parent of merge commit to back out"
+raise error.ProgrammingError(msg)
 parent = ctx.p1()
 return _update(
 ctx.repo(),



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12109: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12109

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1931,10 +1931,9 @@
 hint = _(b"use 'hg update' or check 'hg heads'")
 raise error.Abort(msg, hint=hint)
 if not force and (wc.files() or wc.deleted()):
-raise error.StateError(
-_(b"uncommitted changes"),
-hint=_(b"use 'hg status' to list changes"),
-)
+msg = _(b"uncommitted changes")
+hint = _(b"use 'hg status' to list changes")
+raise error.StateError(msg, hint=hint)
 if not wc.isinmemory():
 for s in sorted(wc.substate):
 wc.sub(s).bailifchanged()



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12108: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12108

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1927,10 +1927,9 @@
 raise error.Abort(m_a)
 elif pas == [p1]:
 if not mergeancestor and wc.branch() == p2.branch():
-raise error.Abort(
-_(b"nothing to merge"),
-hint=_(b"use 'hg update' or check 'hg heads'"),
-)
+msg = _(b"nothing to merge")
+hint = _(b"use 'hg update' or check 'hg heads'")
+raise error.Abort(msg, hint=hint)
 if not force and (wc.files() or wc.deleted()):
 raise error.StateError(
 _(b"uncommitted changes"),



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12107: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12107

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1922,13 +1922,9 @@
 hint = _(b"use 'hg resolve' to resolve")
 raise error.StateError(msg, hint=hint)
 if branchmerge:
+m_a = _(b"merging with a working directory ancestor has no effect")
 if pas == [p2]:
-raise error.Abort(
-_(
-b"merging with a working directory ancestor"
-b" has no effect"
-)
-)
+raise error.Abort(m_a)
 elif pas == [p1]:
 if not mergeancestor and wc.branch() == p2.branch():
 raise error.Abort(



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12106: merge: break up two not-so-one-liner for extra readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12106

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1885,22 +1885,11 @@
 # updatecheck='abort' to better suppport some of these callers.
 if updatecheck is None:
 updatecheck = UPDATECHECK_LINEAR
-if updatecheck not in (
-UPDATECHECK_NONE,
-UPDATECHECK_LINEAR,
-UPDATECHECK_NO_CONFLICT,
-):
-raise ValueError(
-r'Invalid updatecheck %r (can accept %r)'
-% (
-updatecheck,
-(
-UPDATECHECK_NONE,
-UPDATECHECK_LINEAR,
-UPDATECHECK_NO_CONFLICT,
-),
-)
-)
+okay = (UPDATECHECK_NONE, UPDATECHECK_LINEAR, UPDATECHECK_NO_CONFLICT)
+if updatecheck not in okay:
+msg = r'Invalid updatecheck %r (can accept %r)'
+msg %= (updatecheck, okay)
+raise ValueError(msg)
 if wc is not None and wc.isinmemory():
 maybe_wlock = util.nullcontextmanager()
 else:
@@ -1929,10 +1918,9 @@
 raise error.StateError(_(b"outstanding uncommitted merge"))
 ms = wc.mergestate()
 if ms.unresolvedcount():
-raise error.StateError(
-_(b"outstanding merge conflicts"),
-hint=_(b"use 'hg resolve' to resolve"),
-)
+msg = _(b"outstanding merge conflicts")
+hint = _(b"use 'hg resolve' to resolve")
+raise error.StateError(msg, hint=hint)
 if branchmerge:
 if pas == [p2]:
 raise error.Abort(



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12105: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12105

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -537,9 +537,8 @@
 hint = _(b'merging in the other direction may work')
 raise error.Abort(msg % f, hint=hint)
 else:
-raise error.StateError(
-_(b'conflict in file \'%s\' is outside narrow clone') % f
-)
+msg = _(b'conflict in file \'%s\' is outside narrow clone')
+raise error.StateError(msg % f)
 
 
 class mergeresult(object):



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12104: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  (even if not fully satisfied this time)

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12104

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -530,14 +530,12 @@
 elif action[0] in mergestatemod.NO_OP_ACTIONS:
 mresult.removefile(f)  # merge does not affect file
 elif action[0] in nonconflicttypes:
-raise error.Abort(
-_(
-b'merge affects file \'%s\' outside narrow, '
-b'which is not yet supported'
-)
-% f,
-hint=_(b'merging in the other direction may work'),
+msg = _(
+b'merge affects file \'%s\' outside narrow, '
+b'which is not yet supported'
 )
+hint = _(b'merging in the other direction may work')
+raise error.Abort(msg % f, hint=hint)
 else:
 raise error.StateError(
 _(b'conflict in file \'%s\' is outside narrow clone') % f



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12103: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12103

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -346,10 +346,9 @@
 for fold, f in sorted(foldmap.items()):
 if fold.startswith(foldprefix) and not f.startswith(unfoldprefix):
 # the folded prefix matches but actual casing is different
-raise error.StateError(
-_(b"case-folding collision between %s and directory of %s")
-% (lastfull, f)
-)
+msg = _(b"case-folding collision between %s and directory of %s")
+msg %= (lastfull, f)
+raise error.StateError(msg)
 foldprefix = fold + b'/'
 unfoldprefix = f + b'/'
 lastfull = f



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12102: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12102

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -336,10 +336,9 @@
 for f in pmmf:
 fold = util.normcase(f)
 if fold in foldmap:
-raise error.StateError(
-_(b"case-folding collision between %s and %s")
-% (f, foldmap[fold])
-)
+msg = _(b"case-folding collision between %s and %s")
+msg %= (f, foldmap[fold])
+raise error.StateError(msg)
 foldmap[fold] = f
 
 # check case-folding of directories



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D12101: merge: break up a not-so-one-liner for readability

2022-01-29 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12101

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -41,10 +41,9 @@
 valid = [b'abort', b'ignore', b'warn']
 if config not in valid:
 validstr = b', '.join([b"'" + v + b"'" for v in valid])
-raise error.ConfigError(
-_(b"%s.%s not valid ('%s' is none of %s)")
-% (section, name, config, validstr)
-)
+msg = _(b"%s.%s not valid ('%s' is none of %s)")
+msg %= (section, name, config, validstr)
+raise error.ConfigError(msg)
 return config
 
 



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel