##// END OF EJS Templates
revert: option to choose what to keep, not what to discard...
Martin von Zweigbergk -
r42154:c1d83d91 default
parent child Browse files
Show More
@@ -3176,22 +3176,25 b' def _performrevert(repo, parents, ctx, n'
3176 configprefix='revert.interactive.')
3176 configprefix='revert.interactive.')
3177 diffopts.nodates = True
3177 diffopts.nodates = True
3178 diffopts.git = True
3178 diffopts.git = True
3179 operation = 'discard'
3179 operation = 'apply'
3180 reversehunks = True
3180 if node == parent:
3181 if node != parent:
3181 if repo.ui.configbool('experimental',
3182 operation = 'apply'
3182 'revert.interactive.select-to-keep'):
3183 reversehunks = False
3183 operation = 'keep'
3184 if reversehunks:
3184 else:
3185 operation = 'discard'
3186
3187 if operation == 'apply':
3188 diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
3189 else:
3185 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
3190 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
3186 else:
3187 diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
3188 originalchunks = patch.parsepatch(diff)
3191 originalchunks = patch.parsepatch(diff)
3189
3192
3190 try:
3193 try:
3191
3194
3192 chunks, opts = recordfilter(repo.ui, originalchunks,
3195 chunks, opts = recordfilter(repo.ui, originalchunks,
3193 operation=operation)
3196 operation=operation)
3194 if reversehunks:
3197 if operation == 'discard':
3195 chunks = patch.reversehunks(chunks)
3198 chunks = patch.reversehunks(chunks)
3196
3199
3197 except error.PatchError as err:
3200 except error.PatchError as err:
@@ -3205,6 +3208,7 b' def _performrevert(repo, parents, ctx, n'
3205 # chunks are serialized per file, but files aren't sorted
3208 # chunks are serialized per file, but files aren't sorted
3206 for f in sorted(set(c.header.filename() for c in chunks if ishunk(c))):
3209 for f in sorted(set(c.header.filename() for c in chunks if ishunk(c))):
3207 prntstatusmsg('revert', f)
3210 prntstatusmsg('revert', f)
3211 files = set()
3208 for c in chunks:
3212 for c in chunks:
3209 if ishunk(c):
3213 if ishunk(c):
3210 abs = c.header.filename()
3214 abs = c.header.filename()
@@ -3214,6 +3218,10 b' def _performrevert(repo, parents, ctx, n'
3214 bakname = scmutil.backuppath(repo.ui, repo, abs)
3218 bakname = scmutil.backuppath(repo.ui, repo, abs)
3215 util.copyfile(target, bakname)
3219 util.copyfile(target, bakname)
3216 tobackup.remove(abs)
3220 tobackup.remove(abs)
3221 if abs not in files:
3222 files.add(abs)
3223 if operation == 'keep':
3224 checkout(abs)
3217 c.write(fp)
3225 c.write(fp)
3218 dopatch = fp.tell()
3226 dopatch = fp.tell()
3219 fp.seek(0)
3227 fp.seek(0)
@@ -595,6 +595,9 b" coreconfigitem('experimental', 'remotena"
595 coreconfigitem('experimental', 'removeemptydirs',
595 coreconfigitem('experimental', 'removeemptydirs',
596 default=True,
596 default=True,
597 )
597 )
598 coreconfigitem('experimental', 'revert.interactive.select-to-keep',
599 default=False,
600 )
598 coreconfigitem('experimental', 'revisions.prefixhexnode',
601 coreconfigitem('experimental', 'revisions.prefixhexnode',
599 default=False,
602 default=False,
600 )
603 )
@@ -566,6 +566,7 b' def testchunkselector(testfn, ui, header'
566 _headermessages = { # {operation: text}
566 _headermessages = { # {operation: text}
567 'apply': _('Select hunks to apply'),
567 'apply': _('Select hunks to apply'),
568 'discard': _('Select hunks to discard'),
568 'discard': _('Select hunks to discard'),
569 'keep': _('Select hunks to keep'),
569 None: _('Select hunks to record'),
570 None: _('Select hunks to record'),
570 }
571 }
571
572
@@ -1012,11 +1012,13 b' def getmessages():'
1012 'multiple': {
1012 'multiple': {
1013 'apply': _("apply change %d/%d to '%s'?"),
1013 'apply': _("apply change %d/%d to '%s'?"),
1014 'discard': _("discard change %d/%d to '%s'?"),
1014 'discard': _("discard change %d/%d to '%s'?"),
1015 'keep': _("keep change %d/%d to '%s'?"),
1015 'record': _("record change %d/%d to '%s'?"),
1016 'record': _("record change %d/%d to '%s'?"),
1016 },
1017 },
1017 'single': {
1018 'single': {
1018 'apply': _("apply this change to '%s'?"),
1019 'apply': _("apply this change to '%s'?"),
1019 'discard': _("discard this change to '%s'?"),
1020 'discard': _("discard this change to '%s'?"),
1021 'keep': _("keep this change to '%s'?"),
1020 'record': _("record this change to '%s'?"),
1022 'record': _("record this change to '%s'?"),
1021 },
1023 },
1022 'help': {
1024 'help': {
@@ -1040,6 +1042,16 b' def getmessages():'
1040 '$$ Discard &all changes to all remaining files'
1042 '$$ Discard &all changes to all remaining files'
1041 '$$ &Quit, discarding no changes'
1043 '$$ &Quit, discarding no changes'
1042 '$$ &? (display help)'),
1044 '$$ &? (display help)'),
1045 'keep': _('[Ynesfdaq?]'
1046 '$$ &Yes, keep this change'
1047 '$$ &No, skip this change'
1048 '$$ &Edit this change manually'
1049 '$$ &Skip remaining changes to this file'
1050 '$$ Keep remaining changes to this &file'
1051 '$$ &Done, skip remaining changes and files'
1052 '$$ Keep &all changes to all remaining files'
1053 '$$ &Quit, keeping all changes'
1054 '$$ &? (display help)'),
1043 'record': _('[Ynesfdaq?]'
1055 'record': _('[Ynesfdaq?]'
1044 '$$ &Yes, record this change'
1056 '$$ &Yes, record this change'
1045 '$$ &No, skip this change'
1057 '$$ &No, skip this change'
@@ -444,4 +444,52 b' Prompt before undeleting file(issue6008)'
444 > EOF
444 > EOF
445 add back removed file a (Yn)? n
445 add back removed file a (Yn)? n
446 $ ls
446 $ ls
447 $ hg revert -a
448 undeleting a
447 $ cd ..
449 $ cd ..
450
451 Test "keep" mode
452
453 $ cat <<EOF >> $HGRCPATH
454 > [experimental]
455 > revert.interactive.select-to-keep = true
456 > EOF
457
458 $ cd repo
459 $ printf "x\na\ny\n" > a
460 $ hg diff
461 diff -r cb9a9f314b8b a
462 --- a/a Thu Jan 01 00:00:00 1970 +0000
463 +++ b/a Thu Jan 01 00:00:00 1970 +0000
464 @@ -1,1 +1,3 @@
465 +x
466 a
467 +y
468 $ cat > $TESTTMP/editor.sh << '__EOF__'
469 > echo "+new line" >> "$1"
470 > __EOF__
471
472 $ HGEDITOR="\"sh\" \"${TESTTMP}/editor.sh\"" hg revert -i <<EOF
473 > y
474 > n
475 > e
476 > EOF
477 diff --git a/a b/a
478 2 hunks, 2 lines changed
479 examine changes to 'a'? [Ynesfdaq?] y
480
481 @@ -1,1 +1,2 @@
482 +x
483 a
484 keep change 1/2 to 'a'? [Ynesfdaq?] n
485
486 @@ -1,1 +2,2 @@
487 a
488 +y
489 keep change 2/2 to 'a'? [Ynesfdaq?] e
490
491 reverting a
492 $ cat a
493 a
494 y
495 new line
General Comments 0
You need to be logged in to leave comments. Login now