record.py
152 lines
| 4.9 KiB
| text/x-python
|
PythonLexer
/ hgext / record.py
|
r5037 | # record.py | ||
# | ||||
# Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> | ||||
# | ||||
|
r8225 | # This software may be used and distributed according to the terms of the | ||
|
r10263 | # GNU General Public License version 2 or any later version. | ||
|
r5037 | |||
|
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`.''' | ||||
|
r28381 | from __future__ import absolute_import | ||
|
r5037 | |||
|
r29205 | from mercurial.i18n import _ | ||
|
r28381 | from mercurial import ( | ||
cmdutil, | ||||
commands, | ||||
error, | ||||
extensions, | ||||
) | ||||
|
r5037 | |||
|
r14408 | cmdtable = {} | ||
command = cmdutil.command(cmdtable) | ||||
|
r25186 | # Note for extension authors: ONLY specify testedwith = 'internal' for | ||
# 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. | ||||
|
r16743 | testedwith = 'internal' | ||
|
r14408 | |||
|
r5037 | |||
|
r14408 | @command("record", | ||
|
r14597 | # same options as commit + white space diff options | ||
|
r24278 | [c for c in commands.table['^commit|ci'][1][:] | ||
if c[1] != "interactive"] + commands.diffwsopts, | ||||
|
r14408 | _('hg record [OPTION]... [FILE]...')) | ||
|
r5037 | def record(ui, repo, *pats, **opts): | ||
|
r5154 | '''interactively select changes to commit | ||
|
r10973 | If a list of files is omitted, all changes reported by :hg:`status` | ||
|
r9272 | will be candidates for recording. | ||
|
r5154 | |||
|
r10973 | See :hg:`help dates` for a list of formats valid for -d/--date. | ||
|
r6163 | |||
|
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:: | ||||
|
r5154 | |||
|
r9157 | y - record this change | ||
n - skip this change | ||||
|
r16324 | e - edit this change manually | ||
|
r5154 | |||
|
r9157 | s - skip remaining changes to this file | ||
f - record remaining changes to this file | ||||
|
r5154 | |||
|
r9157 | d - done, skip remaining changes and files | ||
a - record all changes to all remaining files | ||||
q - quit, recording no changes | ||||
|
r5154 | |||
|
r11237 | ? - display help | ||
This command is not available when committing a merge.''' | ||||
|
r5037 | |||
|
r25796 | if not ui.interactive(): | ||
|
r26587 | raise error.Abort(_('running non-interactively, use %s instead') % | ||
|
r25796 | 'commit') | ||
|
r24307 | opts["interactive"] = True | ||
|
r25223 | backup = ui.backupconfig('experimental', 'crecord') | ||
try: | ||||
ui.setconfig('experimental', 'crecord', False, 'record') | ||||
commands.commit(ui, repo, *pats, **opts) | ||||
finally: | ||||
ui.restoreconfig(backup) | ||||
|
r5830 | |||
|
r15184 | def qrefresh(origfn, ui, repo, *pats, **opts): | ||
if not opts['interactive']: | ||||
return origfn(ui, repo, *pats, **opts) | ||||
|
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 | ||||
|
r25798 | cmdutil.dorecord(ui, repo, committomq, None, True, | ||
|
r24309 | cmdutil.recordfilter, *pats, **opts) | ||
|
r5830 | |||
|
r21251 | # This command registration is replaced during uisetup(). | ||
|
r21787 | @command('qrecord', | ||
[], | ||||
_('hg qrecord [OPTION]... PATCH [FILE]...'), | ||||
inferrepo=True) | ||||
|
r5932 | def qrecord(ui, repo, patch, *pats, **opts): | ||
'''interactively record a new patch | ||||
|
r5830 | |||
|
r10973 | See :hg:`help qnew` & :hg:`help record` for more information and | ||
|
r9272 | usage. | ||
|
r5830 | ''' | ||
|
r25797 | return _qrecord('qnew', ui, repo, patch, *pats, **opts) | ||
|
r5830 | |||
|
r25797 | def _qrecord(cmdsuggest, ui, repo, patch, *pats, **opts): | ||
|
r5830 | try: | ||
mq = extensions.find('mq') | ||||
except KeyError: | ||||
|
r26587 | raise error.Abort(_("'mq' extension not loaded")) | ||
|
r5830 | |||
|
r14424 | repo.mq.checkpatchname(patch) | ||
|
r10323 | def committomq(ui, repo, *pats, **opts): | ||
|
r14424 | opts['checkname'] = False | ||
|
r5932 | mq.new(ui, repo, patch, *pats, **opts) | ||
|
r5830 | |||
|
r25223 | backup = ui.backupconfig('experimental', 'crecord') | ||
try: | ||||
ui.setconfig('experimental', 'crecord', False, 'record') | ||||
|
r25797 | cmdutil.dorecord(ui, repo, committomq, cmdsuggest, False, | ||
|
r25223 | cmdutil.recordfilter, *pats, **opts) | ||
finally: | ||||
ui.restoreconfig(backup) | ||||
|
r5827 | |||
|
r15184 | def qnew(origfn, ui, repo, patch, *args, **opts): | ||
if opts['interactive']: | ||||
|
r25797 | return _qrecord(None, ui, repo, patch, *args, **opts) | ||
|
r15184 | return origfn(ui, repo, patch, *args, **opts) | ||
|
r5037 | |||
|
r9710 | def uisetup(ui): | ||
|
r5830 | try: | ||
mq = extensions.find('mq') | ||||
except KeyError: | ||||
return | ||||
|
r14408 | cmdtable["qrecord"] = \ | ||
|
r14427 | (qrecord, | ||
# same options as qnew, but copy them so we don't get | ||||
|
r14597 | # -i/--interactive for qrecord and add white space diff options | ||
|
r20300 | mq.cmdtable['^qnew'][1][:] + commands.diffwsopts, | ||
|
r14408 | _('hg qrecord [OPTION]... PATCH [FILE]...')) | ||
|
r14426 | |||
|
r15184 | _wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch")) | ||
|
r14426 | _wrapcmd('qrefresh', mq.cmdtable, qrefresh, | ||
_("interactively select changes to refresh")) | ||||
def _wrapcmd(cmd, table, wrapfn, msg): | ||||
|
r15184 | entry = extensions.wrapcommand(table, cmd, wrapfn) | ||
|
r14426 | entry[1].append(('i', 'interactive', None, msg)) | ||