Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 42071:db72f9f6580e
interactive: do not prompt about files given in command line
For commit and revert commands with --interactive and explicit files
given in the command line, we now skip the invite to "examine changes to
<file> ? [Ynesfdaq?]". The reason for this is that, if <file> is
specified by the user, asking for confirmation is redundant.
In patch.filterpatch(), we now use an optional "match" argument to
conditionally call the prompt() function when entering a new "header"
item. We use .exact() method to compare with files from the "header" in
order to only consider (rel)path patterns.
Add tests with glob patterns for commit and revert, to make sure we
still ask to examine files in these cases.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Thu, 04 Apr 2019 11:35:18 +0200 |
parents | 566daffc607d |
children | e45c6b153e51 |
comparison
equal
deleted
inserted
replaced
42070:675775c33ab6 | 42071:db72f9f6580e |
---|---|
199 def wrap(*args, **kwargs): | 199 def wrap(*args, **kwargs): |
200 return wrapwrite(oldwrite, *args, **kwargs) | 200 return wrapwrite(oldwrite, *args, **kwargs) |
201 setattr(ui, 'write', wrap) | 201 setattr(ui, 'write', wrap) |
202 return oldwrite | 202 return oldwrite |
203 | 203 |
204 def filterchunks(ui, originalhunks, usecurses, testfile, operation=None): | 204 def filterchunks(ui, originalhunks, usecurses, testfile, match, |
205 operation=None): | |
205 try: | 206 try: |
206 if usecurses: | 207 if usecurses: |
207 if testfile: | 208 if testfile: |
208 recordfn = crecordmod.testdecorator( | 209 recordfn = crecordmod.testdecorator( |
209 testfile, crecordmod.testchunkselector) | 210 testfile, crecordmod.testchunkselector) |
214 operation) | 215 operation) |
215 except crecordmod.fallbackerror as e: | 216 except crecordmod.fallbackerror as e: |
216 ui.warn('%s\n' % e.message) | 217 ui.warn('%s\n' % e.message) |
217 ui.warn(_('falling back to text mode\n')) | 218 ui.warn(_('falling back to text mode\n')) |
218 | 219 |
219 return patch.filterpatch(ui, originalhunks, operation) | 220 return patch.filterpatch(ui, originalhunks, match, operation) |
220 | 221 |
221 def recordfilter(ui, originalhunks, operation=None): | 222 def recordfilter(ui, originalhunks, match, operation=None): |
222 """ Prompts the user to filter the originalhunks and return a list of | 223 """ Prompts the user to filter the originalhunks and return a list of |
223 selected hunks. | 224 selected hunks. |
224 *operation* is used for to build ui messages to indicate the user what | 225 *operation* is used for to build ui messages to indicate the user what |
225 kind of filtering they are doing: reverting, committing, shelving, etc. | 226 kind of filtering they are doing: reverting, committing, shelving, etc. |
226 (see patch.filterpatch). | 227 (see patch.filterpatch). |
228 usecurses = crecordmod.checkcurses(ui) | 229 usecurses = crecordmod.checkcurses(ui) |
229 testfile = ui.config('experimental', 'crecordtest') | 230 testfile = ui.config('experimental', 'crecordtest') |
230 oldwrite = setupwrapcolorwrite(ui) | 231 oldwrite = setupwrapcolorwrite(ui) |
231 try: | 232 try: |
232 newchunks, newopts = filterchunks(ui, originalhunks, usecurses, | 233 newchunks, newopts = filterchunks(ui, originalhunks, usecurses, |
233 testfile, operation) | 234 testfile, match, operation) |
234 finally: | 235 finally: |
235 ui.write = oldwrite | 236 ui.write = oldwrite |
236 return newchunks, newopts | 237 return newchunks, newopts |
237 | 238 |
238 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, | 239 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, |
310 diffopts.nodates = True | 311 diffopts.nodates = True |
311 diffopts.git = True | 312 diffopts.git = True |
312 diffopts.showfunc = True | 313 diffopts.showfunc = True |
313 originaldiff = patch.diff(repo, changes=status, opts=diffopts) | 314 originaldiff = patch.diff(repo, changes=status, opts=diffopts) |
314 originalchunks = patch.parsepatch(originaldiff) | 315 originalchunks = patch.parsepatch(originaldiff) |
316 match = scmutil.match(repo[None], pats) | |
315 | 317 |
316 # 1. filter patch, since we are intending to apply subset of it | 318 # 1. filter patch, since we are intending to apply subset of it |
317 try: | 319 try: |
318 chunks, newopts = filterfn(ui, originalchunks) | 320 chunks, newopts = filterfn(ui, originalchunks, match) |
319 except error.PatchError as err: | 321 except error.PatchError as err: |
320 raise error.Abort(_('error parsing patch: %s') % err) | 322 raise error.Abort(_('error parsing patch: %s') % err) |
321 opts.update(newopts) | 323 opts.update(newopts) |
322 | 324 |
323 # We need to keep a backup of files that have been newly added and | 325 # We need to keep a backup of files that have been newly added and |
3079 prefetch = scmutil.prefetchfiles | 3081 prefetch = scmutil.prefetchfiles |
3080 matchfiles = scmutil.matchfiles | 3082 matchfiles = scmutil.matchfiles |
3081 prefetch(repo, [ctx.rev()], | 3083 prefetch(repo, [ctx.rev()], |
3082 matchfiles(repo, | 3084 matchfiles(repo, |
3083 [f for sublist in oplist for f in sublist])) | 3085 [f for sublist in oplist for f in sublist])) |
3086 match = scmutil.match(repo[None], pats) | |
3084 _performrevert(repo, parents, ctx, names, uipathfn, actions, | 3087 _performrevert(repo, parents, ctx, names, uipathfn, actions, |
3085 interactive, tobackup) | 3088 match, interactive, tobackup) |
3086 | 3089 |
3087 if targetsubs: | 3090 if targetsubs: |
3088 # Revert the subrepos on the revert list | 3091 # Revert the subrepos on the revert list |
3089 for sub in targetsubs: | 3092 for sub in targetsubs: |
3090 try: | 3093 try: |
3093 except KeyError: | 3096 except KeyError: |
3094 raise error.Abort("subrepository '%s' does not exist in %s!" | 3097 raise error.Abort("subrepository '%s' does not exist in %s!" |
3095 % (sub, short(ctx.node()))) | 3098 % (sub, short(ctx.node()))) |
3096 | 3099 |
3097 def _performrevert(repo, parents, ctx, names, uipathfn, actions, | 3100 def _performrevert(repo, parents, ctx, names, uipathfn, actions, |
3098 interactive=False, tobackup=None): | 3101 match, interactive=False, tobackup=None): |
3099 """function that actually perform all the actions computed for revert | 3102 """function that actually perform all the actions computed for revert |
3100 | 3103 |
3101 This is an independent function to let extension to plug in and react to | 3104 This is an independent function to let extension to plug in and react to |
3102 the imminent revert. | 3105 the imminent revert. |
3103 | 3106 |
3189 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) | 3192 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) |
3190 originalchunks = patch.parsepatch(diff) | 3193 originalchunks = patch.parsepatch(diff) |
3191 | 3194 |
3192 try: | 3195 try: |
3193 | 3196 |
3194 chunks, opts = recordfilter(repo.ui, originalchunks, | 3197 chunks, opts = recordfilter(repo.ui, originalchunks, match, |
3195 operation=operation) | 3198 operation=operation) |
3196 if operation == 'discard': | 3199 if operation == 'discard': |
3197 chunks = patch.reversehunks(chunks) | 3200 chunks = patch.reversehunks(chunks) |
3198 | 3201 |
3199 except error.PatchError as err: | 3202 except error.PatchError as err: |