record.py
175 lines
| 5.1 KiB
| text/x-python
|
PythonLexer
/ hgext / record.py
Bryan O'Sullivan
|
r5037 | # record.py | ||
# | ||||
# Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> | ||||
# | ||||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
Bryan O'Sullivan
|
r5037 | |||
Pierre-Yves David
|
r28697 | '''commands to interactively select changes for commit/qrefresh (DEPRECATED) | ||
The feature provided by this extension has been moved into core Mercurial as | ||||
:hg:`commit --interactive`.''' | ||||
timeless
|
r28381 | from __future__ import absolute_import | ||
Bryan O'Sullivan
|
r5037 | |||
Yuya Nishihara
|
r29205 | from mercurial.i18n import _ | ||
timeless
|
r28381 | from mercurial import ( | ||
cmdutil, | ||||
commands, | ||||
error, | ||||
extensions, | ||||
Yuya Nishihara
|
r32337 | registrar, | ||
timeless
|
r28381 | ) | ||
Bryan O'Sullivan
|
r5037 | |||
Idan Kamara
|
r14408 | cmdtable = {} | ||
Yuya Nishihara
|
r32337 | command = registrar.command(cmdtable) | ||
Augie Fackler
|
r29841 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||
Augie Fackler
|
r25186 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | ||
# be specifying the version(s) of Mercurial they are tested with, or | ||||
# leave the attribute unspecified. | ||||
Augie Fackler
|
r43347 | testedwith = b'ships-with-hg-core' | ||
Idan Kamara
|
r14408 | |||
Bryan O'Sullivan
|
r5037 | |||
Augie Fackler
|
r43346 | @command( | ||
Augie Fackler
|
r43347 | b"record", | ||
Augie Fackler
|
r43346 | # same options as commit + white space diff options | ||
Augie Fackler
|
r43347 | [c for c in commands.table[b'commit|ci'][1][:] if c[1] != b"interactive"] | ||
Augie Fackler
|
r43346 | + cmdutil.diffwsopts, | ||
Augie Fackler
|
r43347 | _(b'hg record [OPTION]... [FILE]...'), | ||
Augie Fackler
|
r43346 | helpcategory=command.CATEGORY_COMMITTING, | ||
) | ||||
Bryan O'Sullivan
|
r5037 | def record(ui, repo, *pats, **opts): | ||
Bryan O'Sullivan
|
r5154 | '''interactively select changes to commit | ||
Martin Geisler
|
r10973 | If a list of files is omitted, all changes reported by :hg:`status` | ||
Martin Geisler
|
r9272 | will be candidates for recording. | ||
Bryan O'Sullivan
|
r5154 | |||
Martin Geisler
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
Thomas Arendsen Hein
|
r6163 | |||
eloimorlaas
|
r31065 | If using the text interface (see :hg:`help config`), | ||
you will be prompted for whether to record changes to each | ||||
Martin Geisler
|
r9272 | modified file, and for files with multiple changes, for each | ||
change to use. For each query, the following responses are | ||||
possible:: | ||||
Bryan O'Sullivan
|
r5154 | |||
Martin Geisler
|
r9157 | y - record this change | ||
n - skip this change | ||||
A. S. Budden
|
r16324 | e - edit this change manually | ||
Bryan O'Sullivan
|
r5154 | |||
Martin Geisler
|
r9157 | s - skip remaining changes to this file | ||
f - record remaining changes to this file | ||||
Bryan O'Sullivan
|
r5154 | |||
Martin Geisler
|
r9157 | d - done, skip remaining changes and files | ||
a - record all changes to all remaining files | ||||
q - quit, recording no changes | ||||
Bryan O'Sullivan
|
r5154 | |||
Nicolas Dumazet
|
r11237 | ? - display help | ||
This command is not available when committing a merge.''' | ||||
Bryan O'Sullivan
|
r5037 | |||
FUJIWARA Katsunori
|
r25796 | if not ui.interactive(): | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Augie Fackler
|
r43347 | _(b'running non-interactively, use %s instead') % b'commit' | ||
Augie Fackler
|
r43346 | ) | ||
FUJIWARA Katsunori
|
r25796 | |||
Augie Fackler
|
r43809 | opts["interactive"] = True | ||
Augie Fackler
|
r43347 | overrides = {(b'experimental', b'crecord'): False} | ||
with ui.configoverride(overrides, b'record'): | ||||
Philippe Pepiot
|
r30158 | return commands.commit(ui, repo, *pats, **opts) | ||
Kirill Smelkov
|
r5830 | |||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r15184 | def qrefresh(origfn, ui, repo, *pats, **opts): | ||
Augie Fackler
|
r43906 | if not opts['interactive']: | ||
Matt Mackall
|
r15184 | return origfn(ui, repo, *pats, **opts) | ||
Augie Fackler
|
r43347 | mq = extensions.find(b'mq') | ||
Idan Kamara
|
r14426 | |||
def committomq(ui, repo, *pats, **opts): | ||||
# At this point the working copy contains only changes that | ||||
# were accepted. All other changes were reverted. | ||||
# We can't pass *pats here since qrefresh will undo all other | ||||
# changed files in the patch that aren't in pats. | ||||
mq.refresh(ui, repo, **opts) | ||||
# backup all changed files | ||||
Augie Fackler
|
r43346 | cmdutil.dorecord( | ||
ui, repo, committomq, None, True, cmdutil.recordfilter, *pats, **opts | ||||
) | ||||
Kirill Smelkov
|
r5830 | |||
Gregory Szorc
|
r21251 | # This command registration is replaced during uisetup(). | ||
Augie Fackler
|
r43346 | @command( | ||
Augie Fackler
|
r43347 | b'qrecord', | ||
Gregory Szorc
|
r21787 | [], | ||
Augie Fackler
|
r43347 | _(b'hg qrecord [OPTION]... PATCH [FILE]...'), | ||
rdamazio@google.com
|
r40329 | helpcategory=command.CATEGORY_COMMITTING, | ||
Augie Fackler
|
r43346 | inferrepo=True, | ||
) | ||||
Kirill Smelkov
|
r5932 | def qrecord(ui, repo, patch, *pats, **opts): | ||
'''interactively record a new patch | ||||
Kirill Smelkov
|
r5830 | |||
Martin Geisler
|
r10973 | See :hg:`help qnew` & :hg:`help record` for more information and | ||
Martin Geisler
|
r9272 | usage. | ||
Kirill Smelkov
|
r5830 | ''' | ||
Augie Fackler
|
r43347 | return _qrecord(b'qnew', ui, repo, patch, *pats, **opts) | ||
Kirill Smelkov
|
r5830 | |||
Augie Fackler
|
r43346 | |||
FUJIWARA Katsunori
|
r25797 | def _qrecord(cmdsuggest, ui, repo, patch, *pats, **opts): | ||
Kirill Smelkov
|
r5830 | try: | ||
Augie Fackler
|
r43347 | mq = extensions.find(b'mq') | ||
Kirill Smelkov
|
r5830 | except KeyError: | ||
Augie Fackler
|
r43347 | raise error.Abort(_(b"'mq' extension not loaded")) | ||
Kirill Smelkov
|
r5830 | |||
Idan Kamara
|
r14424 | repo.mq.checkpatchname(patch) | ||
Dan Villiom Podlaski Christiansen
|
r10323 | def committomq(ui, repo, *pats, **opts): | ||
Augie Fackler
|
r43906 | opts['checkname'] = False | ||
Kirill Smelkov
|
r5932 | mq.new(ui, repo, patch, *pats, **opts) | ||
Kirill Smelkov
|
r5830 | |||
Augie Fackler
|
r43347 | overrides = {(b'experimental', b'crecord'): False} | ||
with ui.configoverride(overrides, b'record'): | ||||
Navaneeth Suresh
|
r41956 | cmdutil.checkunfinished(repo) | ||
Augie Fackler
|
r43346 | cmdutil.dorecord( | ||
ui, | ||||
repo, | ||||
committomq, | ||||
cmdsuggest, | ||||
False, | ||||
cmdutil.recordfilter, | ||||
*pats, | ||||
**opts | ||||
) | ||||
Kirill Smelkov
|
r5827 | |||
Matt Mackall
|
r15184 | def qnew(origfn, ui, repo, patch, *args, **opts): | ||
Augie Fackler
|
r43906 | if opts['interactive']: | ||
FUJIWARA Katsunori
|
r25797 | return _qrecord(None, ui, repo, patch, *args, **opts) | ||
Matt Mackall
|
r15184 | return origfn(ui, repo, patch, *args, **opts) | ||
Bryan O'Sullivan
|
r5037 | |||
Martin Geisler
|
r9710 | def uisetup(ui): | ||
Kirill Smelkov
|
r5830 | try: | ||
Augie Fackler
|
r43347 | mq = extensions.find(b'mq') | ||
Kirill Smelkov
|
r5830 | except KeyError: | ||
return | ||||
Augie Fackler
|
r43347 | cmdtable[b"qrecord"] = ( | ||
Augie Fackler
|
r41925 | qrecord, | ||
# same options as qnew, but copy them so we don't get | ||||
# -i/--interactive for qrecord and add white space diff options | ||||
Augie Fackler
|
r43347 | mq.cmdtable[b'qnew'][1][:] + cmdutil.diffwsopts, | ||
_(b'hg qrecord [OPTION]... PATCH [FILE]...'), | ||||
Augie Fackler
|
r43346 | ) | ||
Idan Kamara
|
r14426 | |||
Augie Fackler
|
r43347 | _wrapcmd(b'qnew', mq.cmdtable, qnew, _(b"interactively record a new patch")) | ||
Augie Fackler
|
r43346 | _wrapcmd( | ||
Augie Fackler
|
r43347 | b'qrefresh', | ||
Augie Fackler
|
r43346 | mq.cmdtable, | ||
qrefresh, | ||||
Augie Fackler
|
r43347 | _(b"interactively select changes to refresh"), | ||
Augie Fackler
|
r43346 | ) | ||
Idan Kamara
|
r14426 | |||
def _wrapcmd(cmd, table, wrapfn, msg): | ||||
Matt Mackall
|
r15184 | entry = extensions.wrapcommand(table, cmd, wrapfn) | ||
Augie Fackler
|
r43347 | entry[1].append((b'i', b'interactive', None, msg)) | ||