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

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 8, 2015, 9:42 p.m.
Message ID <18cba2544597d954fde9.1444340536@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10894/
State Superseded
Commit ae5f7be2b4ab35b844b792b5fc48f164a3656718
Headers show

Comments

Pierre-Yves David - Oct. 8, 2015, 9:42 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 18cba2544597d954fde95ee36f6450faab57fcbc
# Parent  6253db3dac7a5614020be223d0debdff9c2feefd
destupdate: include the 'check' logic

After moving logic from 'merge.update' into 'scmutil.destupdate', we are now
moving logic from 'command.update' in 'scmutil.destupdate'. This will make the
function actually useful in predicting (and altering) the update behavior.
Augie Fackler - Oct. 9, 2015, 3:06 p.m.
On Thu, Oct 08, 2015 at 02:42:16PM -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 18cba2544597d954fde95ee36f6450faab57fcbc
> # Parent  6253db3dac7a5614020be223d0debdff9c2feefd
> destupdate: include the 'check' logic
>
> After moving logic from 'merge.update' into 'scmutil.destupdate', we are now

shouldn't this be destutil now?

> moving logic from 'command.update' in 'scmutil.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
> @@ -6570,14 +6570,12 @@ def update(ui, repo, node=None, rev=None
>          if check and clean:
>              raise util.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
> @@ -10,11 +10,11 @@ from . import (
>      error,
>      util,
>      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
> @@ -70,11 +70,11 @@ def destupdate(repo, clean=False):
>                  if dirty:
>                      msg = _("uncommitted changes")
>                      hint = _("commit and merge, or update --clean to"
>                               " discard changes")
>                      raise util.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 util.Abort(msg, hint=hint)
>
>      return rev
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Oct. 9, 2015, 7:44 p.m.
On 10/09/2015 08:06 AM, Augie Fackler wrote:
> On Thu, Oct 08, 2015 at 02:42:16PM -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 18cba2544597d954fde95ee36f6450faab57fcbc
>> # Parent  6253db3dac7a5614020be223d0debdff9c2feefd
>> destupdate: include the 'check' logic
>>
>> After moving logic from 'merge.update' into 'scmutil.destupdate', we are now
>
> shouldn't this be destutil now?

Of course it should. :-/

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6570,14 +6570,12 @@  def update(ui, repo, node=None, rev=None
         if check and clean:
             raise util.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
@@ -10,11 +10,11 @@  from . import (
     error,
     util,
     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
@@ -70,11 +70,11 @@  def destupdate(repo, clean=False):
                 if dirty:
                     msg = _("uncommitted changes")
                     hint = _("commit and merge, or update --clean to"
                              " discard changes")
                     raise util.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 util.Abort(msg, hint=hint)
 
     return rev