comparison mercurial/cmdutil.py @ 45942:89a2afe31e82

formating: upgrade to black 20.8b1 This required a couple of small tweaks to un-confuse black, but now it works. Big formatting changes come from: * Dramatically improved collection-splitting logic upstream * Black having a strong (correct IMO) opinion that """ is better than ''' Differential Revision: https://phab.mercurial-scm.org/D9430
author Augie Fackler <raf@durin42.com>
date Fri, 27 Nov 2020 17:03:29 -0500
parents 96ca817ec192
children 012e25abc603
comparison
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
397 397
398 return patch.filterpatch(ui, originalhunks, match, operation) 398 return patch.filterpatch(ui, originalhunks, match, operation)
399 399
400 400
401 def recordfilter(ui, originalhunks, match, operation=None): 401 def recordfilter(ui, originalhunks, match, operation=None):
402 """ Prompts the user to filter the originalhunks and return a list of 402 """Prompts the user to filter the originalhunks and return a list of
403 selected hunks. 403 selected hunks.
404 *operation* is used for to build ui messages to indicate the user what 404 *operation* is used for to build ui messages to indicate the user what
405 kind of filtering they are doing: reverting, committing, shelving, etc. 405 kind of filtering they are doing: reverting, committing, shelving, etc.
406 (see patch.filterpatch). 406 (see patch.filterpatch).
407 """ 407 """
1076 1076
1077 return p 1077 return p
1078 1078
1079 1079
1080 def bailifchanged(repo, merge=True, hint=None): 1080 def bailifchanged(repo, merge=True, hint=None):
1081 """ enforce the precondition that working directory must be clean. 1081 """enforce the precondition that working directory must be clean.
1082 1082
1083 'merge' can be set to false if a pending uncommitted merge should be 1083 'merge' can be set to false if a pending uncommitted merge should be
1084 ignored (such as when 'update --check' runs). 1084 ignored (such as when 'update --check' runs).
1085 1085
1086 'hint' is the usual hint given to Abort exception. 1086 'hint' is the usual hint given to Abort exception.
2182 fntemplate=b'hg-%h.patch', 2182 fntemplate=b'hg-%h.patch',
2183 switch_parent=False, 2183 switch_parent=False,
2184 opts=None, 2184 opts=None,
2185 match=None, 2185 match=None,
2186 ): 2186 ):
2187 '''export changesets as hg patches 2187 """export changesets as hg patches
2188 2188
2189 Args: 2189 Args:
2190 repo: The repository from which we're exporting revisions. 2190 repo: The repository from which we're exporting revisions.
2191 revs: A list of revisions to export as revision numbers. 2191 revs: A list of revisions to export as revision numbers.
2192 basefm: A formatter to which patches should be written. 2192 basefm: A formatter to which patches should be written.
2203 "HG Changeset Patch" data is emitted to one of the following 2203 "HG Changeset Patch" data is emitted to one of the following
2204 destinations: 2204 destinations:
2205 fntemplate specified: Each rev is written to a unique file named using 2205 fntemplate specified: Each rev is written to a unique file named using
2206 the given template. 2206 the given template.
2207 Otherwise: All revs will be written to basefm. 2207 Otherwise: All revs will be written to basefm.
2208 ''' 2208 """
2209 _prefetchchangedfiles(repo, revs, match) 2209 _prefetchchangedfiles(repo, revs, match)
2210 2210
2211 if not fntemplate: 2211 if not fntemplate:
2212 _exportfile( 2212 _exportfile(
2213 repo, revs, basefm, b'<unnamed>', switch_parent, opts, match 2213 repo, revs, basefm, b'<unnamed>', switch_parent, opts, match
3474 prefetch = scmutil.prefetchfiles 3474 prefetch = scmutil.prefetchfiles
3475 matchfiles = scmutil.matchfiles( 3475 matchfiles = scmutil.matchfiles(
3476 repo, [f for sublist in oplist for f in sublist] 3476 repo, [f for sublist in oplist for f in sublist]
3477 ) 3477 )
3478 prefetch( 3478 prefetch(
3479 repo, [(ctx.rev(), matchfiles)], 3479 repo,
3480 [(ctx.rev(), matchfiles)],
3480 ) 3481 )
3481 match = scmutil.match(repo[None], pats) 3482 match = scmutil.match(repo[None], pats)
3482 _performrevert( 3483 _performrevert(
3483 repo, 3484 repo,
3484 ctx, 3485 ctx,
3722 # - (desturl, destbranch, destpeer, outgoing) 3723 # - (desturl, destbranch, destpeer, outgoing)
3723 summaryremotehooks = util.hooks() 3724 summaryremotehooks = util.hooks()
3724 3725
3725 3726
3726 def checkunfinished(repo, commit=False, skipmerge=False): 3727 def checkunfinished(repo, commit=False, skipmerge=False):
3727 '''Look for an unfinished multistep operation, like graft, and abort 3728 """Look for an unfinished multistep operation, like graft, and abort
3728 if found. It's probably good to check this right before 3729 if found. It's probably good to check this right before
3729 bailifchanged(). 3730 bailifchanged().
3730 ''' 3731 """
3731 # Check for non-clearable states first, so things like rebase will take 3732 # Check for non-clearable states first, so things like rebase will take
3732 # precedence over update. 3733 # precedence over update.
3733 for state in statemod._unfinishedstates: 3734 for state in statemod._unfinishedstates:
3734 if ( 3735 if (
3735 state._clearable 3736 state._clearable
3751 if s.isunfinished(repo): 3752 if s.isunfinished(repo):
3752 raise error.StateError(s.msg(), hint=s.hint()) 3753 raise error.StateError(s.msg(), hint=s.hint())
3753 3754
3754 3755
3755 def clearunfinished(repo): 3756 def clearunfinished(repo):
3756 '''Check for unfinished operations (as above), and clear the ones 3757 """Check for unfinished operations (as above), and clear the ones
3757 that are clearable. 3758 that are clearable.
3758 ''' 3759 """
3759 for state in statemod._unfinishedstates: 3760 for state in statemod._unfinishedstates:
3760 if state._reportonly: 3761 if state._reportonly:
3761 continue 3762 continue
3762 if not state._clearable and state.isunfinished(repo): 3763 if not state._clearable and state.isunfinished(repo):
3763 raise error.StateError(state.msg(), hint=state.hint()) 3764 raise error.StateError(state.msg(), hint=state.hint())
3768 if s._clearable and s.isunfinished(repo): 3769 if s._clearable and s.isunfinished(repo):
3769 util.unlink(repo.vfs.join(s._fname)) 3770 util.unlink(repo.vfs.join(s._fname))
3770 3771
3771 3772
3772 def getunfinishedstate(repo): 3773 def getunfinishedstate(repo):
3773 ''' Checks for unfinished operations and returns statecheck object 3774 """Checks for unfinished operations and returns statecheck object
3774 for it''' 3775 for it"""
3775 for state in statemod._unfinishedstates: 3776 for state in statemod._unfinishedstates:
3776 if state.isunfinished(repo): 3777 if state.isunfinished(repo):
3777 return state 3778 return state
3778 return None 3779 return None
3779 3780
3780 3781
3781 def howtocontinue(repo): 3782 def howtocontinue(repo):
3782 '''Check for an unfinished operation and return the command to finish 3783 """Check for an unfinished operation and return the command to finish
3783 it. 3784 it.
3784 3785
3785 statemod._unfinishedstates list is checked for an unfinished operation 3786 statemod._unfinishedstates list is checked for an unfinished operation
3786 and the corresponding message to finish it is generated if a method to 3787 and the corresponding message to finish it is generated if a method to
3787 continue is supported by the operation. 3788 continue is supported by the operation.
3788 3789
3789 Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is 3790 Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is
3790 a boolean. 3791 a boolean.
3791 ''' 3792 """
3792 contmsg = _(b"continue: %s") 3793 contmsg = _(b"continue: %s")
3793 for state in statemod._unfinishedstates: 3794 for state in statemod._unfinishedstates:
3794 if not state._continueflag: 3795 if not state._continueflag:
3795 continue 3796 continue
3796 if state.isunfinished(repo): 3797 if state.isunfinished(repo):
3799 return contmsg % _(b"hg commit"), False 3800 return contmsg % _(b"hg commit"), False
3800 return None, None 3801 return None, None
3801 3802
3802 3803
3803 def checkafterresolved(repo): 3804 def checkafterresolved(repo):
3804 '''Inform the user about the next action after completing hg resolve 3805 """Inform the user about the next action after completing hg resolve
3805 3806
3806 If there's a an unfinished operation that supports continue flag, 3807 If there's a an unfinished operation that supports continue flag,
3807 howtocontinue will yield repo.ui.warn as the reporter. 3808 howtocontinue will yield repo.ui.warn as the reporter.
3808 3809
3809 Otherwise, it will yield repo.ui.note. 3810 Otherwise, it will yield repo.ui.note.
3810 ''' 3811 """
3811 msg, warning = howtocontinue(repo) 3812 msg, warning = howtocontinue(repo)
3812 if msg is not None: 3813 if msg is not None:
3813 if warning: 3814 if warning:
3814 repo.ui.warn(b"%s\n" % msg) 3815 repo.ui.warn(b"%s\n" % msg)
3815 else: 3816 else:
3816 repo.ui.note(b"%s\n" % msg) 3817 repo.ui.note(b"%s\n" % msg)
3817 3818
3818 3819
3819 def wrongtooltocontinue(repo, task): 3820 def wrongtooltocontinue(repo, task):
3820 '''Raise an abort suggesting how to properly continue if there is an 3821 """Raise an abort suggesting how to properly continue if there is an
3821 active task. 3822 active task.
3822 3823
3823 Uses howtocontinue() to find the active task. 3824 Uses howtocontinue() to find the active task.
3824 3825
3825 If there's no task (repo.ui.note for 'hg commit'), it does not offer 3826 If there's no task (repo.ui.note for 'hg commit'), it does not offer
3826 a hint. 3827 a hint.
3827 ''' 3828 """
3828 after = howtocontinue(repo) 3829 after = howtocontinue(repo)
3829 hint = None 3830 hint = None
3830 if after[1]: 3831 if after[1]:
3831 hint = after[0] 3832 hint = after[0]
3832 raise error.StateError(_(b'no %s in progress') % task, hint=hint) 3833 raise error.StateError(_(b'no %s in progress') % task, hint=hint)