Debian Codegraph @

hgext/record.py

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