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