예제 #1
0
파일: githelp.py 프로젝트: x414e54/eden
def parseoptions(ui, cmdoptions, args):
    cmdoptions = list(cmdoptions)
    opts = {}
    args = list(args)
    while True:
        try:
            args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
            break
        except getopt.GetoptError as ex:
            flag = None
            if "requires argument" in ex.msg:
                raise
            if ("--" + ex.opt) in ex.msg:
                flag = "--" + ex.opt
            elif ("-" + ex.opt) in ex.msg:
                flag = "-" + ex.opt
            else:
                raise GitUnknownError(ui, "unknown option %s" % ex.opt)
            try:
                args.remove(flag)
            except Exception:
                raise GitUnknownError(
                    ui,
                    "unknown option {0} packed with other options\n"
                    "Please try passing the option as it's own flag: -{0}".
                    format(ex.opt),
                )

            ui.warn(_("ignoring unknown option %s\n") % flag)

    args = list([convert(x) for x in args])
    opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)
                 for k, v in pycompat.iteritems(opts)])

    return args, opts
예제 #2
0
def redo(ui, repo, *args, **opts):
    """undo the last undo

    Reverse the effects of an :hg:`undo` operation.

    You can run :hg:`redo` multiple times to undo a series of :hg:`undo`
    commands. Alternatively, you can explicitly specify the number of
    :hg:`undo` commands to undo by providing a number as a positional argument.

    Specify --preview to see a graphical display that shows what your smartlog
    will look like after you run the command.

    For an interactive interface, run :hg:`undo --interactive`. This command
    enables you to visually step backwards and forwards in the undo history.
    Run :hg:`help undo` for more information.

    """
    shiftedindex = _computerelative(repo, 0)
    preview = opts.get("preview")

    branch = ""
    reverseindex = 0
    redocount = 0
    done = False
    while not done:
        # we step back the linear undo log
        # redoes cancel out undoes, if we have one more undo, we should undo
        # there, otherwise we continue looking
        # we are careful to not redo past absolute undoes (bc we loose undoredo
        # log info)
        # if we run into something that isn't undo or redo, we Abort (including
        # gaps in the log)
        # we extract the --index arguments out of undoes to make sure we update
        # the undoredo index correctly
        nodedict = _readindex(repo, reverseindex)
        commandstr = _readnode(repo, "command.i", nodedict["command"])
        commandlist = commandstr.split("\0")

        if "True" == nodedict["unfinished"]:
            # don't want to redo to an interupted state
            reverseindex += 1
        elif commandlist[0] == "undo":
            undoopts = {}
            fancyopts.fancyopts(
                commandlist,
                cmdtable["undo"][1] + commands.globalopts,
                undoopts,
                gnu=True,
            )
            if redocount == 0:
                # want to go to state before the undo (not after)
                toshift = undoopts["step"]
                shiftedindex -= toshift
                reverseindex += 1
                branch = undoopts.get("branch")
                done = True
            else:
                if undoopts["absolute"]:
                    raise error.Abort(_("can't redo past absolute undo"))
                reverseindex += 1
                redocount -= 1
        elif commandlist[0] == "redo":
            redocount += 1
            reverseindex += 1
        else:
            raise error.Abort(_("nothing to redo"))

    if preview:
        _preview(ui, repo, reverseindex)
        return

    with repo.wlock(), repo.lock(), repo.transaction("redo"):
        cmdutil.checkunfinished(repo)
        cmdutil.bailifchanged(repo)
        repo = repo.unfiltered()
        _undoto(ui, repo, reverseindex)
        # update undredo by removing what the given undo added
        _logundoredoindex(repo, shiftedindex, branch)