def update_patch(ui, repo, rev, bug, update_patch, rename_patch, interactive):
    q = repo.mq
    try:
        rev = q.lookup(rev)
    except util.error.Abort:
        # If the patch is not coming from mq, don't complain that the name is not found
        update_patch = False
        rename_patch = False

    todo = []
    if rename_patch:
        todo.append("name")
    if update_patch:
        todo.append("description")
    if todo:
        if interactive and ui.prompt("Update patch " + " and ".join(todo) +
                                     " (y/n)?") != 'y':
            ui.write(_("Exiting without updating patch\n"))
            return

    if rename_patch:
        newname = str("bug-%s-%s" % (bug, re.sub(r'^bug-\d+-', '', rev)))
        if newname != rev:
            try:
                mq.rename(ui, repo, rev, newname)
            except:
                # mq.rename has a tendency to leave things in an inconsistent
                # state. Fix things up.
                q.invalidate()
                if os.path.exists(
                        q.join(newname)) and newname not in q.fullseries:
                    os.rename(q.join(newname), q.join(rev))
                raise
            rev = newname

    if update_patch:
        # Add "Bug nnnn - " to the beginning of the description
        ph = mq.patchheader(q.join(rev), q.plainmode)
        msg = [s.decode('utf-8') for s in ph.message]
        if not msg:
            msg = ["Bug %s patch" % bug]
        elif not BUG_RE.search(msg[0]):
            msg[0] = "Bug %s - %s" % (bug, msg[0])
        opts = {
            'git': True,
            'message': '\n'.join(msg).encode('utf-8'),
            'include': ["re:."]
        }
        mq.refresh(ui, repo, **opts)

    return rev
Exemple #2
0
def qrename_wrapper(self, repo, patch, name=None, **opts):
    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    mq.rename(self, repo, patch, name, **opts)

    if mqcommit and mqmessage:
        if not name:
            name = patch
            patch = q.lookup('qtip')
        mqmessage = mqmessage.replace("%p", patch)
        mqmessage = mqmessage.replace("%n", name)
        mqmessage = mqmessage.replace("%a", 'RENAME')
        commands.commit(r.ui, r, message=mqmessage)
def update_patch(ui, repo, rev, bug, update_patch, rename_patch, interactive):
    q = repo.mq
    try:
        rev = q.lookup(rev)
    except util.error.Abort:
        # If the patch is not coming from mq, don't complain that the name is not found
        update_patch = False
        rename_patch = False

    todo = []
    if rename_patch:
        todo.append("name")
    if update_patch:
        todo.append("description")
    if todo:
        if interactive and ui.prompt("Update patch " + " and ".join(todo) + " (y/n)?") != 'y':
            ui.write(_("Exiting without updating patch\n"))
            return

    if rename_patch:
        newname = str("bug-%s-%s" % (bug, re.sub(r'^bug-\d+-', '', rev)))
        if newname != rev:
            try:
                mq.rename(ui, repo, rev, newname)
            except:
                # mq.rename has a tendency to leave things in an inconsistent
                # state. Fix things up.
                q.invalidate()
                if os.path.exists(q.join(newname)) and newname not in q.fullseries:
                    os.rename(q.join(newname), q.join(rev))
                raise
            rev = newname

    if update_patch:
        # Add "Bug nnnn - " to the beginning of the description
        ph = mq.patchheader(q.join(rev), q.plainmode)
        msg = [s.decode('utf-8') for s in ph.message]
        if not msg:
            msg = ["Bug %s patch" % bug]
        elif not BUG_RE.search(msg[0]):
            msg[0] = "Bug %s - %s" % (bug, msg[0])
        opts = {'git': True, 'message': '\n'.join(msg).encode('utf-8'), 'include': ["re:."]}
        mq.refresh(ui, repo, **opts)

    return rev