# HG changeset patch # User Denis Laxalde # Date 1554370518 -7200 # Node ID db72f9f6580e01560f2b717e211c2cfa9c50adc1 # Parent 675775c33ab66cd157b9929bb0371bf05cbceee6 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 ? [Ynesfdaq?]". The reason for this is that, if 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. diff -r 675775c33ab6 -r db72f9f6580e mercurial/cmdutil.py --- a/mercurial/cmdutil.py Thu Apr 04 17:34:43 2019 -0700 +++ b/mercurial/cmdutil.py Thu Apr 04 11:35:18 2019 +0200 @@ -201,7 +201,8 @@ setattr(ui, 'write', wrap) return oldwrite -def filterchunks(ui, originalhunks, usecurses, testfile, operation=None): +def filterchunks(ui, originalhunks, usecurses, testfile, match, + operation=None): try: if usecurses: if testfile: @@ -216,9 +217,9 @@ ui.warn('%s\n' % e.message) ui.warn(_('falling back to text mode\n')) - return patch.filterpatch(ui, originalhunks, operation) - -def recordfilter(ui, originalhunks, operation=None): + return patch.filterpatch(ui, originalhunks, match, operation) + +def recordfilter(ui, originalhunks, match, operation=None): """ Prompts the user to filter the originalhunks and return a list of selected hunks. *operation* is used for to build ui messages to indicate the user what @@ -230,7 +231,7 @@ oldwrite = setupwrapcolorwrite(ui) try: newchunks, newopts = filterchunks(ui, originalhunks, usecurses, - testfile, operation) + testfile, match, operation) finally: ui.write = oldwrite return newchunks, newopts @@ -312,10 +313,11 @@ diffopts.showfunc = True originaldiff = patch.diff(repo, changes=status, opts=diffopts) originalchunks = patch.parsepatch(originaldiff) + match = scmutil.match(repo[None], pats) # 1. filter patch, since we are intending to apply subset of it try: - chunks, newopts = filterfn(ui, originalchunks) + chunks, newopts = filterfn(ui, originalchunks, match) except error.PatchError as err: raise error.Abort(_('error parsing patch: %s') % err) opts.update(newopts) @@ -3081,8 +3083,9 @@ prefetch(repo, [ctx.rev()], matchfiles(repo, [f for sublist in oplist for f in sublist])) + match = scmutil.match(repo[None], pats) _performrevert(repo, parents, ctx, names, uipathfn, actions, - interactive, tobackup) + match, interactive, tobackup) if targetsubs: # Revert the subrepos on the revert list @@ -3095,7 +3098,7 @@ % (sub, short(ctx.node()))) def _performrevert(repo, parents, ctx, names, uipathfn, actions, - interactive=False, tobackup=None): + match, interactive=False, tobackup=None): """function that actually perform all the actions computed for revert This is an independent function to let extension to plug in and react to @@ -3191,7 +3194,7 @@ try: - chunks, opts = recordfilter(repo.ui, originalchunks, + chunks, opts = recordfilter(repo.ui, originalchunks, match, operation=operation) if operation == 'discard': chunks = patch.reversehunks(chunks) diff -r 675775c33ab6 -r db72f9f6580e mercurial/patch.py --- a/mercurial/patch.py Thu Apr 04 17:34:43 2019 -0700 +++ b/mercurial/patch.py Thu Apr 04 11:35:18 2019 +0200 @@ -1065,7 +1065,7 @@ } } -def filterpatch(ui, headers, operation=None): +def filterpatch(ui, headers, match, operation=None): """Interactively filter patch chunks into applied-only chunks""" messages = getmessages() @@ -1182,9 +1182,13 @@ seen.add(hdr) if skipall is None: h.pretty(ui) + files = h.files() msg = (_('examine changes to %s?') % - _(' and ').join("'%s'" % f for f in h.files())) - r, skipfile, skipall, np = prompt(skipfile, skipall, msg, None) + _(' and ').join("'%s'" % f for f in files)) + if all(match.exact(f) for f in files): + r, skipall, np = True, None, None + else: + r, skipfile, skipall, np = prompt(skipfile, skipall, msg, None) if not r: continue applied[h.filename()] = [h] diff -r 675775c33ab6 -r db72f9f6580e tests/test-commit-interactive.t --- a/tests/test-commit-interactive.t Thu Apr 04 17:34:43 2019 -0700 +++ b/tests/test-commit-interactive.t Thu Apr 04 11:35:18 2019 +0200 @@ -26,10 +26,8 @@ > EOF diff --git a/empty-rw b/empty-rw new file mode 100644 - examine changes to 'empty-rw'? [Ynesfdaq?] n - - no changes to record - [1] + abort: empty commit message + [255] $ hg tip -p changeset: -1:000000000000 @@ -47,8 +45,6 @@ > EOF diff --git a/empty-rw b/empty-rw new file mode 100644 - examine changes to 'empty-rw'? [Ynesfdaq?] y - abort: empty commit message [255] @@ -72,12 +68,9 @@ $ hg commit -i -d '0 0' -m empty empty-rw< y - > y > EOF diff --git a/empty-rw b/empty-rw new file mode 100644 - examine changes to 'empty-rw'? [Ynesfdaq?] y - $ hg tip -p changeset: 0:c0708cf4e46e @@ -249,8 +242,6 @@ > EOF diff --git a/plain b/plain new file mode 100644 - examine changes to 'plain'? [Ynesfdaq?] y - @@ -0,0 +1,10 @@ +1 +2 @@ -306,8 +297,6 @@ > EOF diff --git a/plain b/plain 1 hunks, 1 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -8,3 +8,4 @@ 7 8 9 @@ -325,8 +314,6 @@ > EOF diff --git a/plain b/plain 1 hunks, 1 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -9,3 +9,4 @@ 8 9 10 @@ -467,8 +454,6 @@ > EOF diff --git a/plain b/plain 1 hunks, 1 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -9,4 +9,4 @@ 8 9 10 @@ -480,8 +465,6 @@ diff --git a/plain2 b/plain2 new file mode 100644 - examine changes to 'plain2'? [Ynesfdaq?] y - @@ -0,0 +1,1 @@ +1 record change 2/2 to 'plain2'? [Ynesfdaq?] y @@ -504,8 +487,6 @@ > EOF diff --git a/plain b/plain 2 hunks, 3 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -1,4 +1,4 @@ -1 +2 @@ -524,8 +505,6 @@ diff --git a/plain2 b/plain2 1 hunks, 1 lines changed - examine changes to 'plain2'? [Ynesfdaq?] y - @@ -1,1 +1,2 @@ 1 +2 @@ -572,14 +551,11 @@ Record end $ hg commit -i -d '11 0' -m end-only plain < y > n > y > EOF diff --git a/plain b/plain 2 hunks, 4 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -1,9 +1,6 @@ -2 -2 @@ -630,8 +606,6 @@ > EOF diff --git a/plain b/plain 1 hunks, 3 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -1,6 +1,3 @@ -2 -2 @@ -671,14 +645,11 @@ Record end $ hg commit -i --traceback -d '13 0' -m end-again plain< y > n > y > EOF diff --git a/plain b/plain 2 hunks, 4 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -1,6 +1,9 @@ +1 +2 @@ -714,13 +685,10 @@ $ hg commit -i --config diff.noprefix=True -d '14 0' -m middle-only plain < y > y - > y > n > EOF diff --git a/plain b/plain 3 hunks, 7 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -1,2 +1,5 @@ +1 +2 @@ -781,8 +749,6 @@ > EOF diff --git a/plain b/plain 1 hunks, 2 lines changed - examine changes to 'plain'? [Ynesfdaq?] y - @@ -9,3 +9,5 @@ 6 7 8 @@ -823,8 +789,6 @@ > EOF diff --git a/subdir/a b/subdir/a 1 hunks, 1 lines changed - examine changes to 'subdir/a'? [Ynesfdaq?] y - @@ -1,1 +1,2 @@ a +a @@ -879,6 +843,35 @@ abort: user quit [255] +Patterns + + $ hg commit -i 'glob:f*' << EOF + > y + > n + > y + > n + > EOF + diff --git a/subdir/f1 b/subdir/f1 + 1 hunks, 1 lines changed + examine changes to 'subdir/f1'? [Ynesfdaq?] y + + @@ -1,1 +1,2 @@ + a + +a + record change 1/2 to 'subdir/f1'? [Ynesfdaq?] n + + diff --git a/subdir/f2 b/subdir/f2 + 1 hunks, 1 lines changed + examine changes to 'subdir/f2'? [Ynesfdaq?] y + + @@ -1,1 +1,2 @@ + b + +b + record change 2/2 to 'subdir/f2'? [Ynesfdaq?] n + + no changes to record + [1] + #if gettext Test translated help message diff -r 675775c33ab6 -r db72f9f6580e tests/test-diff-color.t --- a/tests/test-diff-color.t Thu Apr 04 17:34:43 2019 -0700 +++ b/tests/test-diff-color.t Thu Apr 04 11:35:18 2019 +0200 @@ -157,14 +157,11 @@ $ chmod +x a $ hg record -m moda a < y - > y > EOF \x1b[0;1mdiff --git a/a b/a\x1b[0m (esc) \x1b[0;36;1mold mode 100644\x1b[0m (esc) \x1b[0;36;1mnew mode 100755\x1b[0m (esc) 1 hunks, 1 lines changed - \x1b[0;33mexamine changes to 'a'? [Ynesfdaq?]\x1b[0m y (esc) - \x1b[0;35m@@ -2,7 +2,7 @@ c\x1b[0m (esc) c a diff -r 675775c33ab6 -r db72f9f6580e tests/test-keyword.t --- a/tests/test-keyword.t Thu Apr 04 17:34:43 2019 -0700 +++ b/tests/test-keyword.t Thu Apr 04 11:35:18 2019 +0200 @@ -383,13 +383,10 @@ >>> open('a', 'wb').writelines(lines) $ hg record -d '10 1' -m rectest a< y - > y > n > EOF diff --git a/a b/a 2 hunks, 2 lines changed - examine changes to 'a'? [Ynesfdaq?] y - @@ -1,3 +1,4 @@ expand $Id$ +foo @@ -448,8 +445,6 @@ > EOF diff --git a/a b/a 2 hunks, 2 lines changed - examine changes to 'a'? [Ynesfdaq?] y - @@ -1,3 +1,4 @@ expand $Id$ +foo @@ -519,8 +514,6 @@ > EOF diff --git a/r b/r new file mode 100644 - examine changes to 'r'? [Ynesfdaq?] y - @@ -0,0 +1,1 @@ +$Id$ record this change to 'r'? [Ynesfdaq?] y diff -r 675775c33ab6 -r db72f9f6580e tests/test-record.t --- a/tests/test-record.t Thu Apr 04 17:34:43 2019 -0700 +++ b/tests/test-record.t Thu Apr 04 11:35:18 2019 +0200 @@ -76,10 +76,8 @@ > EOF diff --git a/empty-rw b/empty-rw new file mode 100644 - examine changes to 'empty-rw'? [Ynesfdaq?] n - - no changes to record - [1] + abort: empty commit message + [255] $ hg tip -p changeset: -1:000000000000 diff -r 675775c33ab6 -r db72f9f6580e tests/test-revert-interactive.t --- a/tests/test-revert-interactive.t Thu Apr 04 17:34:43 2019 -0700 +++ b/tests/test-revert-interactive.t Thu Apr 04 11:35:18 2019 +0200 @@ -149,11 +149,9 @@ g Test that a noop revert doesn't do an unnecessary backup - $ (echo y; echo n) | hg revert -i -r 2 folder1/g + $ (echo n) | hg revert -i -r 2 folder1/g diff --git a/folder1/g b/folder1/g 1 hunks, 1 lines changed - examine changes to 'folder1/g'? [Ynesfdaq?] y - @@ -3,4 +3,3 @@ 3 4 @@ -165,11 +163,9 @@ g Test --no-backup - $ (echo y; echo y) | hg revert -i -C -r 2 folder1/g + $ (echo y) | hg revert -i -C -r 2 folder1/g diff --git a/folder1/g b/folder1/g 1 hunks, 1 lines changed - examine changes to 'folder1/g'? [Ynesfdaq?] y - @@ -3,4 +3,3 @@ 3 4 @@ -270,7 +266,6 @@ M f M folder1/g $ hg revert --interactive f << EOF - > y > ? > y > n @@ -278,8 +273,6 @@ > EOF diff --git a/f b/f 2 hunks, 2 lines changed - examine changes to 'f'? [Ynesfdaq?] y - @@ -1,6 +1,5 @@ -a 1 @@ -327,6 +320,25 @@ 4 5 $ rm f.orig + +Patterns + + $ hg revert -i 'glob:f*' << EOF + > y + > n + > EOF + diff --git a/f b/f + 1 hunks, 1 lines changed + examine changes to 'f'? [Ynesfdaq?] y + + @@ -4,4 +4,3 @@ + 3 + 4 + 5 + -b + discard this change to 'f'? [Ynesfdaq?] n + + $ hg update -C . 2 files updated, 0 files merged, 0 files removed, 0 files unresolved