record.py
123 lines
| 3.9 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 | |||
Dirkjan Ochtman
|
r8934 | '''commands to interactively select changes for commit/qrefresh''' | ||
Bryan O'Sullivan
|
r5037 | |||
FUJIWARA Katsunori
|
r20266 | from mercurial.i18n import _ | ||
Laurent Charignon
|
r24272 | from mercurial import cmdutil, commands, extensions | ||
Bryan O'Sullivan
|
r5037 | from mercurial import util | ||
Idan Kamara
|
r14408 | cmdtable = {} | ||
command = cmdutil.command(cmdtable) | ||||
Augie Fackler
|
r16743 | testedwith = 'internal' | ||
Idan Kamara
|
r14408 | |||
Bryan O'Sullivan
|
r5037 | |||
Idan Kamara
|
r14408 | @command("record", | ||
Ingo Proetel
|
r14597 | # same options as commit + white space diff options | ||
Laurent Charignon
|
r24278 | [c for c in commands.table['^commit|ci'][1][:] | ||
if c[1] != "interactive"] + commands.diffwsopts, | ||||
Idan Kamara
|
r14408 | _('hg record [OPTION]... [FILE]...')) | ||
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 | |||
Martin Geisler
|
r9272 | You will be prompted for whether to record changes to each | ||
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 | |||
Laurent Charignon
|
r24307 | opts["interactive"] = True | ||
commands.commit(ui, repo, *pats, **opts) | ||||
Kirill Smelkov
|
r5830 | |||
Matt Mackall
|
r15184 | def qrefresh(origfn, ui, repo, *pats, **opts): | ||
if not opts['interactive']: | ||||
return origfn(ui, repo, *pats, **opts) | ||||
Idan Kamara
|
r14426 | mq = extensions.find('mq') | ||
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 | ||||
Laurent Charignon
|
r24309 | cmdutil.dorecord(ui, repo, committomq, 'qrefresh', True, | ||
cmdutil.recordfilter, *pats, **opts) | ||||
Kirill Smelkov
|
r5830 | |||
Gregory Szorc
|
r21251 | # This command registration is replaced during uisetup(). | ||
Gregory Szorc
|
r21787 | @command('qrecord', | ||
[], | ||||
_('hg qrecord [OPTION]... PATCH [FILE]...'), | ||||
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 | ''' | ||
try: | ||||
mq = extensions.find('mq') | ||||
except KeyError: | ||||
raise util.Abort(_("'mq' extension not loaded")) | ||||
Idan Kamara
|
r14424 | repo.mq.checkpatchname(patch) | ||
Dan Villiom Podlaski Christiansen
|
r10323 | def committomq(ui, repo, *pats, **opts): | ||
Idan Kamara
|
r14424 | opts['checkname'] = False | ||
Kirill Smelkov
|
r5932 | mq.new(ui, repo, patch, *pats, **opts) | ||
Kirill Smelkov
|
r5830 | |||
Laurent Charignon
|
r24309 | cmdutil.dorecord(ui, repo, committomq, 'qnew', False, | ||
cmdutil.recordfilter, *pats, **opts) | ||||
Kirill Smelkov
|
r5827 | |||
Matt Mackall
|
r15184 | def qnew(origfn, ui, repo, patch, *args, **opts): | ||
if opts['interactive']: | ||||
return qrecord(ui, repo, patch, *args, **opts) | ||||
return origfn(ui, repo, patch, *args, **opts) | ||||
Bryan O'Sullivan
|
r5037 | |||
Martin Geisler
|
r9710 | def uisetup(ui): | ||
Kirill Smelkov
|
r5830 | try: | ||
mq = extensions.find('mq') | ||||
except KeyError: | ||||
return | ||||
Idan Kamara
|
r14408 | cmdtable["qrecord"] = \ | ||
Idan Kamara
|
r14427 | (qrecord, | ||
# same options as qnew, but copy them so we don't get | ||||
Ingo Proetel
|
r14597 | # -i/--interactive for qrecord and add white space diff options | ||
Jordi GutiƩrrez Hermoso
|
r20300 | mq.cmdtable['^qnew'][1][:] + commands.diffwsopts, | ||
Idan Kamara
|
r14408 | _('hg qrecord [OPTION]... PATCH [FILE]...')) | ||
Idan Kamara
|
r14426 | |||
Matt Mackall
|
r15184 | _wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch")) | ||
Idan Kamara
|
r14426 | _wrapcmd('qrefresh', mq.cmdtable, qrefresh, | ||
_("interactively select changes to refresh")) | ||||
def _wrapcmd(cmd, table, wrapfn, msg): | ||||
Matt Mackall
|
r15184 | entry = extensions.wrapcommand(table, cmd, wrapfn) | ||
Idan Kamara
|
r14426 | entry[1].append(('i', 'interactive', None, msg)) | ||