Patchwork [cleanup] discovery: put trivial branch first

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 12, 2015, 4:10 p.m.
Message ID <306bf601d8cfd056a26e.1444666225@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10961/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 12, 2015, 4:10 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1444635924 25200
#      Mon Oct 12 00:45:24 2015 -0700
# Node ID 306bf601d8cfd056a26ec15c423606ece40b6793
# Parent  9ca13d10881d7044b79d903ad64653f6541591f1
# EXP-Topic disc.cleanup
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 306bf601d8cf
discovery: put trivial branch first

Having the simple and tiny branch of the conditional first help readability. The
"else" that appears after a screen of code is harder to relate to a conditional.
Augie Fackler - Oct. 12, 2015, 5:11 p.m.
On Mon, Oct 12, 2015 at 09:10:25AM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1444635924 25200
> #      Mon Oct 12 00:45:24 2015 -0700
> # Node ID 306bf601d8cfd056a26ec15c423606ece40b6793
> # Parent  9ca13d10881d7044b79d903ad64653f6541591f1
> # EXP-Topic disc.cleanup
> # Available At http://hg.netv6.net/marmoute-wip/mercurial/
> #              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 306bf601d8cf
> discovery: put trivial branch first

queued, thanks

>
> Having the simple and tiny branch of the conditional first help readability. The
> "else" that appears after a screen of code is harder to relate to a conditional.
>
> diff --git a/mercurial/discovery.py b/mercurial/discovery.py
> --- a/mercurial/discovery.py
> +++ b/mercurial/discovery.py
> @@ -303,11 +303,13 @@ def checkheads(repo, remote, outgoing, r
>              oldhs = set(remoteheads)
>          oldhs.update(unsyncedheads)
>          candidate_newhs.update(unsyncedheads)
>          dhs = None # delta heads, the new heads on branch
>          discardedheads = set()
> -        if repo.obsstore:
> +        if not repo.obsstore:
> +            newhs = candidate_newhs
> +        else:
>              # remove future heads which are actually obsoleted by another
>              # pushed element:
>              #
>              # XXX as above, There are several cases this code does not handle
>              # XXX properly
> @@ -332,12 +334,10 @@ def checkheads(repo, remote, outgoing, r
>                          if suc != nh and suc in allfuturecommon:
>                              discardedheads.add(nh)
>                              break
>                      else:
>                          newhs.add(nh)
> -        else:
> -            newhs = candidate_newhs
>          unsynced = sorted(h for h in unsyncedheads if h not in discardedheads)
>          if unsynced:
>              if None in unsynced:
>                  # old remote, no heads data
>                  heads = None
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -303,11 +303,13 @@  def checkheads(repo, remote, outgoing, r
             oldhs = set(remoteheads)
         oldhs.update(unsyncedheads)
         candidate_newhs.update(unsyncedheads)
         dhs = None # delta heads, the new heads on branch
         discardedheads = set()
-        if repo.obsstore:
+        if not repo.obsstore:
+            newhs = candidate_newhs
+        else:
             # remove future heads which are actually obsoleted by another
             # pushed element:
             #
             # XXX as above, There are several cases this code does not handle
             # XXX properly
@@ -332,12 +334,10 @@  def checkheads(repo, remote, outgoing, r
                         if suc != nh and suc in allfuturecommon:
                             discardedheads.add(nh)
                             break
                     else:
                         newhs.add(nh)
-        else:
-            newhs = candidate_newhs
         unsynced = sorted(h for h in unsyncedheads if h not in discardedheads)
         if unsynced:
             if None in unsynced:
                 # old remote, no heads data
                 heads = None