Patchwork [1,of,4] rebase: move destination computation in a revset

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 21, 2015, 10:16 p.m.
Message ID <4a5d8f70d71f914b85b4.1442873795@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10557/
State Superseded
Headers show

Comments

Pierre-Yves David - Sept. 21, 2015, 10:16 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1442512792 25200
#      Thu Sep 17 10:59:52 2015 -0700
# Node ID 4a5d8f70d71f914b85b415b2dfb7a7448e9137e5
# Parent  4b685712fa454919c121d8d1c967da35b0522dd5
rebase: move destination computation in a revset

This is the first step toward making the "default destination" logic more clear
and unified. revset is private because I'm happy to delay the bikeshedding until
after the clean up happened.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -14,11 +14,11 @@  For more information:
 http://mercurial.selenic.com/wiki/RebaseExtension
 '''
 
 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
 from mercurial import extensions, patch, scmutil, phases, obsolete, error
-from mercurial import copies, repoview
+from mercurial import copies, repoview, revset
 from mercurial.commands import templateopts
 from mercurial.node import nullrev, nullid, hex, short
 from mercurial.lock import release
 from mercurial.i18n import _
 import os, errno
@@ -52,10 +52,26 @@  def _makeextrafn(copiers):
     def extrafn(ctx, extra):
         for c in copiers:
             c(ctx, extra)
     return extrafn
 
+def _rebasedefaultdest(repo, subset, x):
+    """``_rebasedefaultdest()``
+
+    default destination for rebase.
+    # XXX: Currently private because I expect the signature to change.
+    # XXX: - taking rev as arguments,
+    # XXX: - bailing out in case of ambiguity vs returning all data.
+    # XXX: - probably merging with the merge destination.
+    """
+    # i18n: "_rebasedefaultdest" is a keyword
+    # Destination defaults to the latest revision in the
+    # current branch
+    revset.getargs(x, 0, 0, _("_rebasedefaultdest takes no arguments"))
+    branch = repo[None].branch()
+    return subset & revset.baseset([repo[branch].rev()])
+
 @command('rebase',
     [('s', 'source', '',
      _('rebase the specified changeset and descendants'), _('REV')),
     ('b', 'base', '',
      _('rebase everything from branching point of specified changeset'),
@@ -250,16 +266,12 @@  def rebase(ui, repo, **opts):
 
             cmdutil.checkunfinished(repo)
             cmdutil.bailifchanged(repo)
 
             if not destf:
-                # Destination defaults to the latest revision in the
-                # current branch
-                branch = repo[None].branch()
-                dest = repo[branch]
-            else:
-                dest = scmutil.revsingle(repo, destf)
+                destf = '_rebasedefaultdest()'
+            dest = scmutil.revsingle(repo, destf)
 
             if revf:
                 rebaseset = scmutil.revrange(repo, revf)
                 if not rebaseset:
                     ui.status(_('empty "rev" revision set - '
@@ -1124,5 +1136,6 @@  def uisetup(ui):
     cmdutil.unfinishedstates.append(
         ['rebasestate', False, False, _('rebase in progress'),
          _("use 'hg rebase --continue' or 'hg rebase --abort'")])
     # ensure rebased rev are not hidden
     extensions.wrapfunction(repoview, '_getdynamicblockers', _rebasedvisible)
+    revset.symbols['_rebasedefaultdest'] = _rebasedefaultdest