diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -9,6 +9,7 @@ import difflib import errno +import inspect import os import re import sys @@ -132,6 +133,49 @@ # Commands start here, listed alphabetically +@command('abort', + [('', 'no-backup', False, _('do not save backup copies of files')), + ] + dryrunopts, helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, + helpbasic=True) +def abort(ui, repo, **opts): + """abort an unfinished operation + + This function is the first prototype for hg abort command. + It first checks the state and checks which command is active + then calls then returns the respective logic for aborting the + command. + 'hg abort --no-backup' is used when no backup copies of files + are needed when an operation is aborted. + 'hg abort --no-backup --fry-run' can be used. In such cases dry + run will be given priority. + """ + abortstate = None + dryrun = opts.get('dry_run') + nobackup = opts.get('no_backup') + for state in statemod._unfinishedstates: + if state.isunfinished(repo): + abortstate = state + break + if not abortstate: + raise error.Abort(_('no operation in progress')) + + if not abortstate.abortfunc: + raise error.Abort((_("%s does not support 'hg abort'") % + (abortstate._opname)), hint=abortstate.hint()) + + if nobackup: + arglist = inspect.getargspec(abortstate.abortfunc)[0] + if not 'nobackup' in arglist: + raise error.Abort(_("%s does not support no-backup") % + (abortstate._opname)) + + if dryrun: + raise error.Abort(_('aborting %s') % (abortstate._opname)) + + if nobackup: + return abortstate.abortfunc(ui, repo, nobackup=True) + return abortstate.abortfunc(ui, repo) + @command('add', walkopts + subrepoopts + dryrunopts, _('[OPTION]... [FILE]...'), diff --git a/mercurial/state.py b/mercurial/state.py --- a/mercurial/state.py +++ b/mercurial/state.py @@ -98,7 +98,8 @@ """ def __init__(self, opname, fname, clearable, allowcommit, reportonly, - continueflag, stopflag, cmdmsg, cmdhint, statushint): + continueflag, stopflag, cmdmsg, cmdhint, statushint, + abortfunc): self._opname = opname self._fname = fname self._clearable = clearable @@ -109,6 +110,7 @@ self._cmdmsg = cmdmsg self._cmdhint = cmdhint self._statushint = statushint + self.abortfunc = abortfunc def statusmsg(self): """returns the hint message corresponding to the command for @@ -157,7 +159,7 @@ def addunfinished(opname, fname, clearable=False, allowcommit=False, reportonly=False, continueflag=False, stopflag=False, - cmdmsg="", cmdhint="", statushint=""): + cmdmsg="", cmdhint="", statushint="", abortfunc=None): """this registers a new command or operation to unfinishedstates opname is the name the command or operation fname is the file name in which data should be stored in .hg directory. @@ -181,10 +183,11 @@ statushint is used to pass a different status message in case standard message of the format ('To continue: hg cmdname --continue' 'To abort: hg cmdname --abort') is not desired + abortfunc stores the function required to abort an unfinished state. """ statecheckobj = _statecheck(opname, fname, clearable, allowcommit, reportonly, continueflag, stopflag, cmdmsg, - cmdhint, statushint) + cmdhint, statushint, abortfunc) if opname == 'merge': _unfinishedstates.append(statecheckobj) else: diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t --- a/tests/test-commandserver.t +++ b/tests/test-commandserver.t @@ -62,6 +62,7 @@ basic commands: + abort abort an unfinished operation add add the specified files on the next commit annotate show changeset information by line for each file clone make a copy of an existing repository diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -1,5 +1,6 @@ Show all commands except debug commands $ hg debugcomplete + abort add addremove annotate @@ -59,6 +60,7 @@ Show all commands that start with "a" $ hg debugcomplete a + abort add addremove annotate @@ -235,6 +237,7 @@ Show all commands + options $ hg debugcommands + abort: no-backup, dry-run add: include, exclude, subrepos, dry-run addremove: similarity, subrepos, include, exclude, dry-run annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, skip, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, include, exclude, template diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t --- a/tests/test-globalopts.t +++ b/tests/test-globalopts.t @@ -317,6 +317,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory @@ -449,6 +450,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory diff --git a/tests/test-help-hide.t b/tests/test-help-hide.t --- a/tests/test-help-hide.t +++ b/tests/test-help-hide.t @@ -21,6 +21,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory @@ -157,6 +158,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -5,6 +5,7 @@ basic commands: + abort abort an unfinished operation add add the specified files on the next commit annotate show changeset information by line for each file clone make a copy of an existing repository @@ -26,6 +27,7 @@ (use 'hg help' for the full list of commands or 'hg -v' for details) $ hg -q + abort abort an unfinished operation add add the specified files on the next commit annotate show changeset information by line for each file clone make a copy of an existing repository @@ -73,6 +75,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory @@ -201,6 +204,7 @@ Change manipulation: + abort abort an unfinished operation backout reverse effect of earlier changeset graft copy changes from other branches onto the current branch merge merge another revision into working directory @@ -402,6 +406,7 @@ basic commands: + abort abort an unfinished operation add add the specified files on the next commit annotate, blame show changeset information by line for each file @@ -2353,6 +2358,13 @@

Main Commands

+ + abort + + + abort an unfinished operation + + add diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t --- a/tests/test-hgweb-json.t +++ b/tests/test-hgweb-json.t @@ -1875,6 +1875,10 @@ { "earlycommands": [ { + "summary": "abort an unfinished operation", + "topic": "abort" + }, + { "summary": "add the specified files on the next commit", "topic": "add" },