Show More
@@ -1,153 +1,147 | |||||
1 | # record.py |
|
1 | # record.py | |
2 | # |
|
2 | # | |
3 | # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> |
|
3 | # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | '''commands to interactively select changes for commit/qrefresh (DEPRECATED) |
|
8 | '''commands to interactively select changes for commit/qrefresh (DEPRECATED) | |
9 |
|
9 | |||
10 | The feature provided by this extension has been moved into core Mercurial as |
|
10 | The feature provided by this extension has been moved into core Mercurial as | |
11 | :hg:`commit --interactive`.''' |
|
11 | :hg:`commit --interactive`.''' | |
12 |
|
12 | |||
13 | from __future__ import absolute_import |
|
13 | from __future__ import absolute_import | |
14 |
|
14 | |||
15 | from mercurial.i18n import _ |
|
15 | from mercurial.i18n import _ | |
16 | from mercurial import ( |
|
16 | from mercurial import ( | |
17 | cmdutil, |
|
17 | cmdutil, | |
18 | commands, |
|
18 | commands, | |
19 | error, |
|
19 | error, | |
20 | extensions, |
|
20 | extensions, | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
23 | cmdtable = {} |
|
23 | cmdtable = {} | |
24 | command = cmdutil.command(cmdtable) |
|
24 | command = cmdutil.command(cmdtable) | |
25 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
25 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | |
26 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
26 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
27 | # be specifying the version(s) of Mercurial they are tested with, or |
|
27 | # be specifying the version(s) of Mercurial they are tested with, or | |
28 | # leave the attribute unspecified. |
|
28 | # leave the attribute unspecified. | |
29 | testedwith = 'ships-with-hg-core' |
|
29 | testedwith = 'ships-with-hg-core' | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | @command("record", |
|
32 | @command("record", | |
33 | # same options as commit + white space diff options |
|
33 | # same options as commit + white space diff options | |
34 | [c for c in commands.table['^commit|ci'][1][:] |
|
34 | [c for c in commands.table['^commit|ci'][1][:] | |
35 | if c[1] != "interactive"] + commands.diffwsopts, |
|
35 | if c[1] != "interactive"] + commands.diffwsopts, | |
36 | _('hg record [OPTION]... [FILE]...')) |
|
36 | _('hg record [OPTION]... [FILE]...')) | |
37 | def record(ui, repo, *pats, **opts): |
|
37 | def record(ui, repo, *pats, **opts): | |
38 | '''interactively select changes to commit |
|
38 | '''interactively select changes to commit | |
39 |
|
39 | |||
40 | If a list of files is omitted, all changes reported by :hg:`status` |
|
40 | If a list of files is omitted, all changes reported by :hg:`status` | |
41 | will be candidates for recording. |
|
41 | will be candidates for recording. | |
42 |
|
42 | |||
43 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
43 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
44 |
|
44 | |||
45 | If using the text interface (see :hg:`help config`), |
|
45 | If using the text interface (see :hg:`help config`), | |
46 | you will be prompted for whether to record changes to each |
|
46 | you will be prompted for whether to record changes to each | |
47 | modified file, and for files with multiple changes, for each |
|
47 | modified file, and for files with multiple changes, for each | |
48 | change to use. For each query, the following responses are |
|
48 | change to use. For each query, the following responses are | |
49 | possible:: |
|
49 | possible:: | |
50 |
|
50 | |||
51 | y - record this change |
|
51 | y - record this change | |
52 | n - skip this change |
|
52 | n - skip this change | |
53 | e - edit this change manually |
|
53 | e - edit this change manually | |
54 |
|
54 | |||
55 | s - skip remaining changes to this file |
|
55 | s - skip remaining changes to this file | |
56 | f - record remaining changes to this file |
|
56 | f - record remaining changes to this file | |
57 |
|
57 | |||
58 | d - done, skip remaining changes and files |
|
58 | d - done, skip remaining changes and files | |
59 | a - record all changes to all remaining files |
|
59 | a - record all changes to all remaining files | |
60 | q - quit, recording no changes |
|
60 | q - quit, recording no changes | |
61 |
|
61 | |||
62 | ? - display help |
|
62 | ? - display help | |
63 |
|
63 | |||
64 | This command is not available when committing a merge.''' |
|
64 | This command is not available when committing a merge.''' | |
65 |
|
65 | |||
66 | if not ui.interactive(): |
|
66 | if not ui.interactive(): | |
67 | raise error.Abort(_('running non-interactively, use %s instead') % |
|
67 | raise error.Abort(_('running non-interactively, use %s instead') % | |
68 | 'commit') |
|
68 | 'commit') | |
69 |
|
69 | |||
70 | opts["interactive"] = True |
|
70 | opts["interactive"] = True | |
71 |
|
|
71 | overrides = {('experimental', 'crecord'): False} | |
72 | try: |
|
72 | with ui.configoverride(overrides, 'record'): | |
73 | ui.setconfig('experimental', 'crecord', False, 'record') |
|
|||
74 | return commands.commit(ui, repo, *pats, **opts) |
|
73 | return commands.commit(ui, repo, *pats, **opts) | |
75 | finally: |
|
|||
76 | ui.restoreconfig(backup) |
|
|||
77 |
|
74 | |||
78 | def qrefresh(origfn, ui, repo, *pats, **opts): |
|
75 | def qrefresh(origfn, ui, repo, *pats, **opts): | |
79 | if not opts['interactive']: |
|
76 | if not opts['interactive']: | |
80 | return origfn(ui, repo, *pats, **opts) |
|
77 | return origfn(ui, repo, *pats, **opts) | |
81 |
|
78 | |||
82 | mq = extensions.find('mq') |
|
79 | mq = extensions.find('mq') | |
83 |
|
80 | |||
84 | def committomq(ui, repo, *pats, **opts): |
|
81 | def committomq(ui, repo, *pats, **opts): | |
85 | # At this point the working copy contains only changes that |
|
82 | # At this point the working copy contains only changes that | |
86 | # were accepted. All other changes were reverted. |
|
83 | # were accepted. All other changes were reverted. | |
87 | # We can't pass *pats here since qrefresh will undo all other |
|
84 | # We can't pass *pats here since qrefresh will undo all other | |
88 | # changed files in the patch that aren't in pats. |
|
85 | # changed files in the patch that aren't in pats. | |
89 | mq.refresh(ui, repo, **opts) |
|
86 | mq.refresh(ui, repo, **opts) | |
90 |
|
87 | |||
91 | # backup all changed files |
|
88 | # backup all changed files | |
92 | cmdutil.dorecord(ui, repo, committomq, None, True, |
|
89 | cmdutil.dorecord(ui, repo, committomq, None, True, | |
93 | cmdutil.recordfilter, *pats, **opts) |
|
90 | cmdutil.recordfilter, *pats, **opts) | |
94 |
|
91 | |||
95 | # This command registration is replaced during uisetup(). |
|
92 | # This command registration is replaced during uisetup(). | |
96 | @command('qrecord', |
|
93 | @command('qrecord', | |
97 | [], |
|
94 | [], | |
98 | _('hg qrecord [OPTION]... PATCH [FILE]...'), |
|
95 | _('hg qrecord [OPTION]... PATCH [FILE]...'), | |
99 | inferrepo=True) |
|
96 | inferrepo=True) | |
100 | def qrecord(ui, repo, patch, *pats, **opts): |
|
97 | def qrecord(ui, repo, patch, *pats, **opts): | |
101 | '''interactively record a new patch |
|
98 | '''interactively record a new patch | |
102 |
|
99 | |||
103 | See :hg:`help qnew` & :hg:`help record` for more information and |
|
100 | See :hg:`help qnew` & :hg:`help record` for more information and | |
104 | usage. |
|
101 | usage. | |
105 | ''' |
|
102 | ''' | |
106 | return _qrecord('qnew', ui, repo, patch, *pats, **opts) |
|
103 | return _qrecord('qnew', ui, repo, patch, *pats, **opts) | |
107 |
|
104 | |||
108 | def _qrecord(cmdsuggest, ui, repo, patch, *pats, **opts): |
|
105 | def _qrecord(cmdsuggest, ui, repo, patch, *pats, **opts): | |
109 | try: |
|
106 | try: | |
110 | mq = extensions.find('mq') |
|
107 | mq = extensions.find('mq') | |
111 | except KeyError: |
|
108 | except KeyError: | |
112 | raise error.Abort(_("'mq' extension not loaded")) |
|
109 | raise error.Abort(_("'mq' extension not loaded")) | |
113 |
|
110 | |||
114 | repo.mq.checkpatchname(patch) |
|
111 | repo.mq.checkpatchname(patch) | |
115 |
|
112 | |||
116 | def committomq(ui, repo, *pats, **opts): |
|
113 | def committomq(ui, repo, *pats, **opts): | |
117 | opts['checkname'] = False |
|
114 | opts['checkname'] = False | |
118 | mq.new(ui, repo, patch, *pats, **opts) |
|
115 | mq.new(ui, repo, patch, *pats, **opts) | |
119 |
|
116 | |||
120 |
|
|
117 | overrides = {('experimental', 'crecord'): False} | |
121 | try: |
|
118 | with ui.configoverride(overrides, 'record'): | |
122 | ui.setconfig('experimental', 'crecord', False, 'record') |
|
|||
123 | cmdutil.dorecord(ui, repo, committomq, cmdsuggest, False, |
|
119 | cmdutil.dorecord(ui, repo, committomq, cmdsuggest, False, | |
124 | cmdutil.recordfilter, *pats, **opts) |
|
120 | cmdutil.recordfilter, *pats, **opts) | |
125 | finally: |
|
|||
126 | ui.restoreconfig(backup) |
|
|||
127 |
|
121 | |||
128 | def qnew(origfn, ui, repo, patch, *args, **opts): |
|
122 | def qnew(origfn, ui, repo, patch, *args, **opts): | |
129 | if opts['interactive']: |
|
123 | if opts['interactive']: | |
130 | return _qrecord(None, ui, repo, patch, *args, **opts) |
|
124 | return _qrecord(None, ui, repo, patch, *args, **opts) | |
131 | return origfn(ui, repo, patch, *args, **opts) |
|
125 | return origfn(ui, repo, patch, *args, **opts) | |
132 |
|
126 | |||
133 |
|
127 | |||
134 | def uisetup(ui): |
|
128 | def uisetup(ui): | |
135 | try: |
|
129 | try: | |
136 | mq = extensions.find('mq') |
|
130 | mq = extensions.find('mq') | |
137 | except KeyError: |
|
131 | except KeyError: | |
138 | return |
|
132 | return | |
139 |
|
133 | |||
140 | cmdtable["qrecord"] = \ |
|
134 | cmdtable["qrecord"] = \ | |
141 | (qrecord, |
|
135 | (qrecord, | |
142 | # same options as qnew, but copy them so we don't get |
|
136 | # same options as qnew, but copy them so we don't get | |
143 | # -i/--interactive for qrecord and add white space diff options |
|
137 | # -i/--interactive for qrecord and add white space diff options | |
144 | mq.cmdtable['^qnew'][1][:] + commands.diffwsopts, |
|
138 | mq.cmdtable['^qnew'][1][:] + commands.diffwsopts, | |
145 | _('hg qrecord [OPTION]... PATCH [FILE]...')) |
|
139 | _('hg qrecord [OPTION]... PATCH [FILE]...')) | |
146 |
|
140 | |||
147 | _wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch")) |
|
141 | _wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch")) | |
148 | _wrapcmd('qrefresh', mq.cmdtable, qrefresh, |
|
142 | _wrapcmd('qrefresh', mq.cmdtable, qrefresh, | |
149 | _("interactively select changes to refresh")) |
|
143 | _("interactively select changes to refresh")) | |
150 |
|
144 | |||
151 | def _wrapcmd(cmd, table, wrapfn, msg): |
|
145 | def _wrapcmd(cmd, table, wrapfn, msg): | |
152 | entry = extensions.wrapcommand(table, cmd, wrapfn) |
|
146 | entry = extensions.wrapcommand(table, cmd, wrapfn) | |
153 | entry[1].append(('i', 'interactive', None, msg)) |
|
147 | entry[1].append(('i', 'interactive', None, msg)) |
General Comments 0
You need to be logged in to leave comments.
Login now