Patchwork [2,of,4,defaultdest,V2] destupdate: include the 'check' logic

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 12, 2015, 5:22 p.m.
Message ID <976e836aa9fcc99d05a4.1444670574@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10963/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 12, 2015, 5:22 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1443511129 25200
#      Tue Sep 29 00:18:49 2015 -0700
# Node ID 976e836aa9fcc99d05a462afef5007351e5226a1
# Parent  b11a6b6eb40b453a53a01da69f876a4ab78de402
# EXP-Topic defaultdest
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 976e836aa9fc
destupdate: include the 'check' logic

After moving logic from 'merge.update' into 'destutil.destupdate', we are now
moving logic from 'command.update' in 'destutil.destupdate'. This will make the
function actually useful in predicting (and altering) the update behavior.
Augie Fackler - Oct. 13, 2015, 3:28 p.m.
On Mon, Oct 12, 2015 at 10:22:54AM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1443511129 25200
> #      Tue Sep 29 00:18:49 2015 -0700
> # Node ID 976e836aa9fcc99d05a462afef5007351e5226a1
> # Parent  b11a6b6eb40b453a53a01da69f876a4ab78de402
> # EXP-Topic defaultdest
> # Available At http://hg.netv6.net/marmoute-wip/mercurial/
> #              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 976e836aa9fc
> destupdate: include the 'check' logic

Queued these two, but patch 3 still needs some TLC.

>
> After moving logic from 'merge.update' into 'destutil.destupdate', we are now
> moving logic from 'command.update' in 'destutil.destupdate'. This will make the
> function actually useful in predicting (and altering) the update behavior.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -6575,14 +6575,12 @@ def update(ui, repo, node=None, rev=None
>              raise error.Abort(_("cannot specify both -c/--check and -C/--clean")
>                               )
>
>          if check:
>              cmdutil.bailifchanged(repo, merge=False)
> -            if rev is None:
> -                rev = repo[repo[None].branch()].rev()
> -        elif rev is None:
> -            rev = destutil.destupdate(repo, clean=clean)
> +        if rev is None:
> +            rev = destutil.destupdate(repo, clean=clean, check=check)
>
>          repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
>
>          if clean:
>              ret = hg.clean(repo, rev)
> diff --git a/mercurial/destutil.py b/mercurial/destutil.py
> --- a/mercurial/destutil.py
> +++ b/mercurial/destutil.py
> @@ -9,11 +9,11 @@ from .i18n import _
>  from . import (
>      error,
>      obsolete,
>  )
>
> -def destupdate(repo, clean=False):
> +def destupdate(repo, clean=False, check=False):
>      """destination for bare update operation
>      """
>      # Here is where we should consider bookmarks, divergent bookmarks, and tip
>      # of current branch; but currently we are only checking the branch tips.
>      node = None
> @@ -69,11 +69,11 @@ def destupdate(repo, clean=False):
>                  if dirty:
>                      msg = _("uncommitted changes")
>                      hint = _("commit and merge, or update --clean to"
>                               " discard changes")
>                      raise error.Abort(msg, hint=hint)
> -                else:  # destination is not a descendant.
> +                elif not check:  # destination is not a descendant.
>                      msg = _("not a linear update")
>                      hint = _("merge or update --check to force update")
>                      raise error.Abort(msg, hint=hint)
>
>      return rev
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6575,14 +6575,12 @@  def update(ui, repo, node=None, rev=None
             raise error.Abort(_("cannot specify both -c/--check and -C/--clean")
                              )
 
         if check:
             cmdutil.bailifchanged(repo, merge=False)
-            if rev is None:
-                rev = repo[repo[None].branch()].rev()
-        elif rev is None:
-            rev = destutil.destupdate(repo, clean=clean)
+        if rev is None:
+            rev = destutil.destupdate(repo, clean=clean, check=check)
 
         repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
 
         if clean:
             ret = hg.clean(repo, rev)
diff --git a/mercurial/destutil.py b/mercurial/destutil.py
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -9,11 +9,11 @@  from .i18n import _
 from . import (
     error,
     obsolete,
 )
 
-def destupdate(repo, clean=False):
+def destupdate(repo, clean=False, check=False):
     """destination for bare update operation
     """
     # Here is where we should consider bookmarks, divergent bookmarks, and tip
     # of current branch; but currently we are only checking the branch tips.
     node = None
@@ -69,11 +69,11 @@  def destupdate(repo, clean=False):
                 if dirty:
                     msg = _("uncommitted changes")
                     hint = _("commit and merge, or update --clean to"
                              " discard changes")
                     raise error.Abort(msg, hint=hint)
-                else:  # destination is not a descendant.
+                elif not check:  # destination is not a descendant.
                     msg = _("not a linear update")
                     hint = _("merge or update --check to force update")
                     raise error.Abort(msg, hint=hint)
 
     return rev