Mercurial > hg-stable
changeset 42972:1ad3ebb39c61
merge: replace magic strings with NAMED_CONSTANTS (API)
.. api::
`mercurial.hg.update*` and `mercurial.merge.update` now expect a value
from a set of NAMED_CONSTANTS (`merge.UPDATECHECK_*` constants)
rather than a collection of magic strings. As of now, the values
are the same, but code should be prepared for these values to
change in the future.
Differential Revision: https://phab.mercurial-scm.org/D6877
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 25 Sep 2019 10:53:10 -0400 |
parents | 76608f9f27f6 |
children | ee1ef76d7339 |
files | mercurial/hg.py mercurial/merge.py |
diffstat | 2 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hg.py Wed Sep 25 12:59:26 2019 +0200 +++ b/mercurial/hg.py Wed Sep 25 10:53:10 2019 -0400 @@ -897,21 +897,26 @@ :clean: whether changes in the working directory can be discarded :updatecheck: how to deal with a dirty working directory - Valid values for updatecheck are (None => linear): + Valid values for updatecheck are the UPDATECHECK_* constants + defined in the merge module. Passing `None` will result in using the + configured default. - * abort: abort if the working directory is dirty - * none: don't check (merge working directory changes into destination) - * linear: check that update is linear before merging working directory + * ABORT: abort if the working directory is dirty + * NONE: don't check (merge working directory changes into destination) + * LINEAR: check that update is linear before merging working directory changes into destination - * noconflict: check that the update does not result in file merges + * NO_CONFLICT: check that the update does not result in file merges This returns whether conflict is detected at updating or not. """ if updatecheck is None: updatecheck = ui.config('commands', 'update.check') - if updatecheck not in ('abort', 'none', 'linear', 'noconflict'): + if updatecheck not in (mergemod.UPDATECHECK_ABORT, + mergemod.UPDATECHECK_NONE, + mergemod.UPDATECHECK_LINEAR, + mergemod.UPDATECHECK_NO_CONFLICT): # If not configured, or invalid value configured - updatecheck = 'linear' + updatecheck = mergemod.UPDATECHECK_LINEAR with repo.wlock(): movemarkfrom = None warndest = False @@ -923,9 +928,9 @@ if clean: ret = _clean(repo, checkout) else: - if updatecheck == 'abort': + if updatecheck == mergemod.UPDATECHECK_ABORT: cmdutil.bailifchanged(repo, merge=False) - updatecheck = 'none' + updatecheck = mergemod.UPDATECHECK_NONE ret = _update(repo, checkout, updatecheck=updatecheck) if not ret and movemarkfrom:
--- a/mercurial/merge.py Wed Sep 25 12:59:26 2019 +0200 +++ b/mercurial/merge.py Wed Sep 25 10:53:10 2019 -0400 @@ -1926,6 +1926,11 @@ else: repo.dirstate.normal(f) +UPDATECHECK_ABORT = 'abort' # handled at higher layers +UPDATECHECK_NONE = 'none' +UPDATECHECK_LINEAR = 'linear' +UPDATECHECK_NO_CONFLICT = 'noconflict' + def update(repo, node, branchmerge, force, ancestor=None, mergeancestor=False, labels=None, matcher=None, mergeforce=False, updatecheck=None, wc=None): @@ -1992,8 +1997,11 @@ # and force=False pass a value for updatecheck. We may want to allow # updatecheck='abort' to better suppport some of these callers. if updatecheck is None: - updatecheck = 'linear' - assert updatecheck in ('none', 'linear', 'noconflict') + updatecheck = UPDATECHECK_LINEAR + assert updatecheck in (UPDATECHECK_NONE, + UPDATECHECK_LINEAR, + UPDATECHECK_NO_CONFLICT, + ) # If we're doing a partial update, we need to skip updating # the dirstate, so make a note of any partial-ness to the # update here. @@ -2050,7 +2058,7 @@ repo.hook('update', parent1=xp2, parent2='', error=0) return updateresult(0, 0, 0, 0) - if (updatecheck == 'linear' and + if (updatecheck == UPDATECHECK_LINEAR and pas not in ([p1], [p2])): # nonlinear dirty = wc.dirty(missing=True) if dirty: @@ -2087,7 +2095,7 @@ repo, wc, p2, pas, branchmerge, force, mergeancestor, followcopies, matcher=matcher, mergeforce=mergeforce) - if updatecheck == 'noconflict': + if updatecheck == UPDATECHECK_NO_CONFLICT: for f, (m, args, msg) in actionbyfile.iteritems(): if m not in (ACTION_GET, ACTION_KEEP, ACTION_EXEC, ACTION_REMOVE, ACTION_PATH_CONFLICT_RESOLVE):