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