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