[PATCH] rebase: dry-run implemenation

Augie Fackler raf at durin42.com
Tue Jan 12 15:18:35 UTC 2016


On Tue, Dec 22, 2015 at 12:18:47PM -0600, timeless at mozdev.org wrote:
> # HG changeset patch
> # User timeless at mozdev.org
> # Date 1444168027 14400
> #      Tue Oct 06 17:47:07 2015 -0400
> # Node ID 7701bc1363ab8e8fbed258c847073fd8e655228d
> # Parent  3dea4eae4eebac11741f0c1dc5dcd9c88d8f4554
> rebase: dry-run implemenation

I like the idea of a dry-run here, but I'm unconvinced by the
output. I'm just not sure how to read what it's telling me in terms of
what that means for the shape of my history when the rebase is done.

>
> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -100,6 +100,7 @@
>      ('t', 'tool', '', _('specify merge tool')),
>      ('c', 'continue', False, _('continue an interrupted rebase')),
>      ('a', 'abort', False, _('abort an interrupted rebase'))] +
> +     commands.dryrunopts +
>       templateopts,
>      _('[-s REV | -b REV] [-d REV] [OPTION]'))
>  def rebase(ui, repo, **opts):
> @@ -210,6 +211,7 @@
>          # keepopen is not meant for use on the command line, but by
>          # other extensions
>          keepopen = opts.get('keepopen', False)
> +        dryrun = opts.get('dry_run')
>
>          if opts.get('interactive'):
>              try:
> @@ -243,7 +245,8 @@
>                   keepbranchesf, external, activebookmark) = restorestatus(repo)
>              except error.RepoLookupError:
>                  if abortf:
> -                    clearstatus(repo)
> +                    if not dryrun:
> +                        clearstatus(repo)
>                      repo.ui.warn(_('rebase aborted (no revision is removed,'
>                                     ' only broken state is cleared)\n'))
>                      return 0
> @@ -408,10 +411,14 @@
>                              _('changesets'), total)
>                  p1, p2, base = defineparents(repo, rev, target, state,
>                                               targetancestors)
> -                storestatus(repo, originalwd, target, state, collapsef, keepf,
> -                            keepbranchesf, external, activebookmark)
> +                if not dryrun:
> +                    storestatus(repo, originalwd, target, state, collapsef,
> +                            keepf, keepbranchesf, external, activebookmark)
>                  if len(repo[None].parents()) == 2:
>                      repo.ui.debug('resuming interrupted rebase\n')
> +                elif dryrun:
> +                    if p1 >= 0:
> +                        repo.ui.status(" update to %d:%s\n" % (p1, repo[p1]))
>                  else:
>                      try:
>                          ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
> @@ -424,7 +431,9 @@
>                                    'resolve, then hg rebase --continue)'))
>                      finally:
>                          ui.setconfig('ui', 'forcemerge', '', 'rebase')
> -                if not collapsef:
> +                if dryrun:
> +                    pass
> +                elif not collapsef:
>                      merging = p2 != nullrev
>                      editform = cmdutil.mergeeditform(merging, 'rebase')
>                      editor = cmdutil.getcommiteditor(editform=editform, **opts)
> @@ -439,7 +448,9 @@
>                      repo.dirstate.endparentchange()
>                      newnode = None
>                  # Update the state
> -                if newnode is not None:
> +                if dryrun:
> +                    ui.debug('dryrun cannot predict if there will be changes')
> +                elif newnode is not None:
>                      state[rev] = repo[newnode].rev()
>                      ui.debug('rebased as %s\n' % short(newnode))
>                  else:
> @@ -469,6 +480,10 @@
>          ui.progress(_('rebasing'), None)
>          ui.note(_('rebase merging completed\n'))
>
> +        if dryrun:
> +            ui.note(_("rebase completed\n"))
> +            return
> +
>          if collapsef and not keepopen:
>              p1, p2, _base = defineparents(repo, min(state), target,
>                                            state, targetancestors)
> diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
> --- a/tests/test-rebase-scenario-global.t
> +++ b/tests/test-rebase-scenario-global.t
> @@ -50,6 +50,9 @@
>
>    $ hg status --rev "3^1" --rev 3
>    A D
> +  $ HGEDITOR=cat hg rebase --dry-run -s 3 -d 7 --edit
> +  rebasing 3:32af7686d403 "D"
> +   update to 7:02de42196ebe
>    $ HGEDITOR=cat hg rebase -s 3 -d 7 --edit
>    rebasing 3:32af7686d403 "D"
>    D
> @@ -89,6 +92,9 @@
>    $ hg clone -q -u . a a2
>    $ cd a2
>
> +  $ HGEDITOR=cat hg rebase --dry-run -s 3 -d 5
> +  rebasing 3:32af7686d403 "D"
> +   update to 5:24b6387c8c8c
>    $ HGEDITOR=cat hg rebase -s 3 -d 5
>    rebasing 3:32af7686d403 "D"
>    saved backup bundle to $TESTTMP/a2/.hg/strip-backup/32af7686d403-6f7dface-backup.hg (glob)
> @@ -118,6 +124,10 @@
>    $ hg clone -q -u . a a3
>    $ cd a3
>
> +  $ hg rebase --dry-run -s 4 -d 7
> +  rebasing 4:9520eea781bc "E"
> +   update to 7:02de42196ebe
> +  rebasing 6:eea13746799a "G"
>    $ hg rebase -s 4 -d 7
>    rebasing 4:9520eea781bc "E"
>    rebasing 6:eea13746799a "G"
> @@ -147,6 +157,11 @@
>    $ hg clone -q -u . a a4
>    $ cd a4
>
> +  $ hg rebase --dry-run -s 5 -d 4
> +  rebasing 5:24b6387c8c8c "F"
> +   update to 4:9520eea781bc
> +  rebasing 6:eea13746799a "G"
> +  rebasing 7:02de42196ebe "H" (tip)
>    $ hg rebase -s 5 -d 4
>    rebasing 5:24b6387c8c8c "F"
>    rebasing 6:eea13746799a "G"
> @@ -177,6 +192,9 @@
>    $ hg clone -q -u . a a5
>    $ cd a5
>
> +  $ hg rebase --dry-run -s 6 -d 7
> +  rebasing 6:eea13746799a "G"
> +   update to 7:02de42196ebe
>    $ hg rebase -s 6 -d 7
>    rebasing 6:eea13746799a "G"
>    saved backup bundle to $TESTTMP/a5/.hg/strip-backup/eea13746799a-883828ed-backup.hg (glob)
> @@ -206,6 +224,11 @@
>    $ hg clone -q -u . a a6
>    $ cd a6
>
> +  $ hg rebase --dry-run -s 5 -d 1
> +  rebasing 5:24b6387c8c8c "F"
> +   update to 1:42ccdea3bb16
> +  rebasing 6:eea13746799a "G"
> +  rebasing 7:02de42196ebe "H" (tip)
>    $ hg rebase -s 5 -d 1
>    rebasing 5:24b6387c8c8c "F"
>    rebasing 6:eea13746799a "G"
> @@ -239,18 +262,28 @@
>    $ hg clone -q -u . a a7
>    $ cd a7
>
> +  $ hg rebase --dry-run -s 6 -d 5
> +  nothing to rebase
> +  [1]
>    $ hg rebase -s 6 -d 5
>    nothing to rebase
>    [1]
>
>  F onto G - rebase onto a descendant:
>
> +  $ hg rebase --dry-run -s 5 -d 6
> +  abort: source is ancestor of destination
> +  [255]
>    $ hg rebase -s 5 -d 6
>    abort: source is ancestor of destination
>    [255]
>
>  G onto B - merge revision with both parents not in ancestors of target:
>
> +  $ hg rebase --dry-run -s 6 -d 1
> +  rebasing 6:eea13746799a "G"
> +  abort: cannot use revision 6 as base, result would have 3 parents
> +  [255]
>    $ hg rebase -s 6 -d 1
>    rebasing 6:eea13746799a "G"
>    abort: cannot use revision 6 as base, result would have 3 parents
> @@ -261,24 +294,37 @@
>
>  G onto G - rebase onto same changeset:
>
> +  $ hg rebase --dry-run -b 6 -d 6
> +  nothing to rebase - eea13746799a is both "base" and destination
> +  [1]
>    $ hg rebase -b 6 -d 6
>    nothing to rebase - eea13746799a is both "base" and destination
>    [1]
>
>  G onto F - rebase onto an ancestor:
>
> +  $ hg rebase --dry-run -b 6 -d 5
> +  nothing to rebase
> +  [1]
>    $ hg rebase -b 6 -d 5
>    nothing to rebase
>    [1]
>
>  F onto G - rebase onto a descendant:
>
> +  $ hg rebase --dry-run -b 5 -d 6
> +  nothing to rebase - "base" 24b6387c8c8c is already an ancestor of destination eea13746799a
> +  [1]
>    $ hg rebase -b 5 -d 6
>    nothing to rebase - "base" 24b6387c8c8c is already an ancestor of destination eea13746799a
>    [1]
>
>  C onto A - rebase onto an ancestor:
>
> +  $ hg rebase --dry-run -d 0 -s 2
> +  rebasing 2:5fddd98957c8 "C"
> +   update to 0:cd010b8cd998
> +  rebasing 3:32af7686d403 "D"
>    $ hg rebase -d 0 -s 2
>    rebasing 2:5fddd98957c8 "C"
>    rebasing 3:32af7686d403 "D"
> @@ -304,14 +350,25 @@
>  Check rebasing public changeset
>
>    $ hg pull --config phases.publish=True -q -r 6 . # update phase of 6
> +  $ hg rebase --dry-run -d 0 -b 6
> +  nothing to rebase
> +  [1]
>    $ hg rebase -d 0 -b 6
>    nothing to rebase
>    [1]
> +  $ hg rebase --dry-run -d 5 -b 6
> +  abort: can't rebase public changeset e1c4361dd923
> +  (see "hg help phases" for details)
> +  [255]
>    $ hg rebase -d 5 -b 6
>    abort: can't rebase public changeset e1c4361dd923
>    (see "hg help phases" for details)
>    [255]
>
> +  $ hg rebase --dry-run -d 5 -b 6 --keep
> +  rebasing 6:e1c4361dd923 "C"
> +   update to 5:02de42196ebe
> +  rebasing 7:c9659aac0000 "D" (tip)
>    $ hg rebase -d 5 -b 6 --keep
>    rebasing 6:e1c4361dd923 "C"
>    rebasing 7:c9659aac0000 "D" (tip)
> @@ -320,6 +377,9 @@
>  Source phase greater or equal to destination phase: new changeset get the phase of source:
>    $ hg id -n
>    5
> +  $ hg rebase --dry-run -s9 -d0
> +  rebasing 9:2b23e52411f4 "D" (tip)
> +   update to 0:cd010b8cd998
>    $ hg rebase -s9 -d0
>    rebasing 9:2b23e52411f4 "D" (tip)
>    saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2b23e52411f4-f942decf-backup.hg (glob)
> @@ -327,23 +387,35 @@
>    5
>    $ hg log --template "{phase}\n" -r 9
>    draft
> +  $ hg rebase --dry-run -s9 -d1
> +  rebasing 9:2cb10d0cfc6c "D" (tip)
> +   update to 1:42ccdea3bb16
>    $ hg rebase -s9 -d1
>    rebasing 9:2cb10d0cfc6c "D" (tip)
>    saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2cb10d0cfc6c-ddb0f256-backup.hg (glob)
>    $ hg log --template "{phase}\n" -r 9
>    draft
>    $ hg phase --force --secret 9
> +  $ hg rebase --dry-run -s9 -d0
> +  rebasing 9:c5b12b67163a "D" (tip)
> +   update to 0:cd010b8cd998
>    $ hg rebase -s9 -d0
>    rebasing 9:c5b12b67163a "D" (tip)
>    saved backup bundle to $TESTTMP/a7/.hg/strip-backup/c5b12b67163a-4e372053-backup.hg (glob)
>    $ hg log --template "{phase}\n" -r 9
>    secret
> +  $ hg rebase --dry-run -s9 -d1
> +  rebasing 9:2a0524f868ac "D" (tip)
> +   update to 1:42ccdea3bb16
>    $ hg rebase -s9 -d1
>    rebasing 9:2a0524f868ac "D" (tip)
>    saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2a0524f868ac-cefd8574-backup.hg (glob)
>    $ hg log --template "{phase}\n" -r 9
>    secret
>  Source phase lower than destination phase: new changeset get the phase of destination:
> +  $ hg rebase --dry-run -s8 -d9
> +  rebasing 8:6d4f22462821 "C"
> +   update to 9:5ac831c74b56
>    $ hg rebase -s8 -d9
>    rebasing 8:6d4f22462821 "C"
>    saved backup bundle to $TESTTMP/a7/.hg/strip-backup/6d4f22462821-3441f70b-backup.hg (glob)
> @@ -393,10 +465,21 @@
>
>    $ hg clone -q -u . ah ah1
>    $ cd ah1
> +  $ hg rebase --dry-run -r '2::8' -d 1
> +  abort: can't remove original changesets with unrebased descendants
> +  (use --keep to keep original changesets)
> +  [255]
>    $ hg rebase -r '2::8' -d 1
>    abort: can't remove original changesets with unrebased descendants
>    (use --keep to keep original changesets)
>    [255]
> +  $ hg rebase --dry-run -r '2::8' -d 1 -k
> +  rebasing 2:c9e50f6cdc55 "C"
> +   update to 1:8fd0f7e49f53
> +  rebasing 3:ffd453c31098 "D"
> +  rebasing 6:3d8a618087a7 "G"
> +  rebasing 7:72434a4e60b0 "H"
> +  rebasing 8:479ddb54a924 "I" (tip)
>    $ hg rebase -r '2::8' -d 1 -k
>    rebasing 2:c9e50f6cdc55 "C"
>    rebasing 3:ffd453c31098 "D"
> @@ -439,10 +522,20 @@
>
>    $ hg clone -q -u . ah ah2
>    $ cd ah2
> +  $ hg rebase --dry-run -r '3::8' -d 1
> +  abort: can't remove original changesets with unrebased descendants
> +  (use --keep to keep original changesets)
> +  [255]
>    $ hg rebase -r '3::8' -d 1
>    abort: can't remove original changesets with unrebased descendants
>    (use --keep to keep original changesets)
>    [255]
> +  $ hg rebase --dry-run -r '3::8' -d 1 --keep
> +  rebasing 3:ffd453c31098 "D"
> +   update to 1:8fd0f7e49f53
> +  rebasing 6:3d8a618087a7 "G"
> +  rebasing 7:72434a4e60b0 "H"
> +  rebasing 8:479ddb54a924 "I" (tip)
>    $ hg rebase -r '3::8' -d 1 --keep
>    rebasing 3:ffd453c31098 "D"
>    rebasing 6:3d8a618087a7 "G"
> @@ -482,10 +575,19 @@
>
>    $ hg clone -q -u . ah ah3
>    $ cd ah3
> +  $ hg rebase --dry-run -r '3::7' -d 1
> +  abort: can't remove original changesets with unrebased descendants
> +  (use --keep to keep original changesets)
> +  [255]
>    $ hg rebase -r '3::7' -d 1
>    abort: can't remove original changesets with unrebased descendants
>    (use --keep to keep original changesets)
>    [255]
> +  $ hg rebase --dry-run -r '3::7' -d 1 --keep
> +  rebasing 3:ffd453c31098 "D"
> +   update to 1:8fd0f7e49f53
> +  rebasing 6:3d8a618087a7 "G"
> +  rebasing 7:72434a4e60b0 "H"
>    $ hg rebase -r '3::7' -d 1 --keep
>    rebasing 3:ffd453c31098 "D"
>    rebasing 6:3d8a618087a7 "G"
> @@ -522,10 +624,21 @@
>
>    $ hg clone -q -u . ah ah4
>    $ cd ah4
> +  $ hg rebase --dry-run -r '3::(7+5)' -d 1
> +  abort: can't remove original changesets with unrebased descendants
> +  (use --keep to keep original changesets)
> +  [255]
>    $ hg rebase -r '3::(7+5)' -d 1
>    abort: can't remove original changesets with unrebased descendants
>    (use --keep to keep original changesets)
>    [255]
> +  $ hg rebase --dry-run -r '3::(7+5)' -d 1 --keep
> +  rebasing 3:ffd453c31098 "D"
> +   update to 1:8fd0f7e49f53
> +  rebasing 4:c01897464e7f "E"
> +  rebasing 5:41bfcc75ed73 "F"
> +  rebasing 6:3d8a618087a7 "G"
> +  rebasing 7:72434a4e60b0 "H"
>    $ hg rebase -r '3::(7+5)' -d 1 --keep
>    rebasing 3:ffd453c31098 "D"
>    rebasing 4:c01897464e7f "E"
> @@ -570,6 +683,11 @@
>
>    $ hg clone -q -u . ah ah5
>    $ cd ah5
> +  $ hg rebase --dry-run -r '6::' -d 2
> +  rebasing 6:3d8a618087a7 "G"
> +   update to 2:c9e50f6cdc55
> +  rebasing 7:72434a4e60b0 "H"
> +  rebasing 8:479ddb54a924 "I" (tip)
>    $ hg rebase -r '6::' -d 2
>    rebasing 6:3d8a618087a7 "G"
>    rebasing 7:72434a4e60b0 "H"
> @@ -603,6 +721,14 @@
>
>    $ hg clone -q -u . ah ah6
>    $ cd ah6
> +  $ hg rebase --dry-run -r '(4+6)::' -d 1
> +  rebasing 4:c01897464e7f "E"
> +   update to 1:8fd0f7e49f53
> +  rebasing 5:41bfcc75ed73 "F"
> +  rebasing 6:3d8a618087a7 "G"
> +   update to 1:8fd0f7e49f53
> +  rebasing 7:72434a4e60b0 "H"
> +  rebasing 8:479ddb54a924 "I" (tip)
>    $ hg rebase -r '(4+6)::' -d 1
>    rebasing 4:c01897464e7f "E"
>    rebasing 5:41bfcc75ed73 "F"
> @@ -675,6 +801,11 @@
>
>  (actual test)
>
> +  $ hg rebase --dry-run --dest 'desc(G)' --rev 'desc(K) + desc(I)'
> +  rebasing 8:e7ec4e813ba6 "I"
> +   update to 6:eea13746799a
> +  rebasing 10:23a4ace37988 "K" (tip)
> +   update to 6:eea13746799a
>    $ hg rebase --dest 'desc(G)' --rev 'desc(K) + desc(I)'
>    rebasing 8:e7ec4e813ba6 "I"
>    rebasing 10:23a4ace37988 "K" (tip)
> @@ -739,6 +870,10 @@
>    $ touch subfile
>    $ hg add subfile
>    $ hg commit -m 'second source with subdir'
> +  $ hg rebase --dry-run -b . -d 1 --traceback
> +  rebasing 2:779a07b1b7a0 "first source commit"
> +   update to 1:58d79cc1cf43
> +  rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
>    $ hg rebase -b . -d 1 --traceback
>    rebasing 2:779a07b1b7a0 "first source commit"
>    rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list