Patchwork [V2] discovery: factor out calculation of heads to not warn about

login
register
mail settings
Submitter Ryan McElroy
Date Nov. 6, 2015, 5:55 p.m.
Message ID <78998efe2eb11258ea7c.1446832507@devbig314.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11304/
State Accepted
Headers show

Comments

Ryan McElroy - Nov. 6, 2015, 5:55 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1446832104 28800
#      Fri Nov 06 09:48:24 2015 -0800
# Node ID 78998efe2eb11258ea7c5d78bb560d410ad2754b
# Parent  f9984f76fd90e439221425d751e29bae17bec995
discovery: factor out calculation of heads to not warn about

In addition to taking a step towards getting an unreasonably large function
factored into smaller, more manageable functions, this will allow extensions
such as remotenames have more control over what pushes are allowed or not.
Augie Fackler - Nov. 6, 2015, 8:35 p.m.
queued this, thanks

> On Nov 6, 2015, at 12:55 PM, Ryan McElroy <rm@fb.com> wrote:
> 
> # HG changeset patch
> # User Ryan McElroy <rmcelroy@fb.com>
> # Date 1446832104 28800
> #      Fri Nov 06 09:48:24 2015 -0800
> # Node ID 78998efe2eb11258ea7c5d78bb560d410ad2754b
> # Parent  f9984f76fd90e439221425d751e29bae17bec995
> discovery: factor out calculation of heads to not warn about
> 
> In addition to taking a step towards getting an unreasonably large function
> factored into smaller, more manageable functions, this will allow extensions
> such as remotenames have more control over what pushes are allowed or not.
> 
> diff --git a/mercurial/discovery.py b/mercurial/discovery.py
> --- a/mercurial/discovery.py
> +++ b/mercurial/discovery.py
> @@ -238,6 +238,23 @@ def _oldheadssummary(repo, remoteheads,
>         unsynced = set()
>     return {None: (oldheads, newheads, unsynced)}
> 
> +def _nowarnheads(repo, remote, newbookmarks):
> +    # Compute newly pushed bookmarks. We don't warn about bookmarked heads.
> +    localbookmarks = repo._bookmarks
> +    remotebookmarks = remote.listkeys('bookmarks')
> +    bookmarkedheads = set()
> +    for bm in localbookmarks:
> +        rnode = remotebookmarks.get(bm)
> +        if rnode and rnode in repo:
> +            lctx, rctx = repo[bm], repo[rnode]
> +            if bookmarks.validdest(repo, rctx, lctx):
> +                bookmarkedheads.add(lctx.node())
> +        else:
> +            if bm in newbookmarks and bm not in remotebookmarks:
> +                bookmarkedheads.add(repo[bm].node())
> +
> +    return bookmarkedheads
> +
> def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False,
>                newbookmarks=[]):
>     """Check that a push won't add any outgoing head
> @@ -268,19 +285,8 @@ def checkheads(repo, remote, outgoing, r
>                          hint=_("use 'hg push --new-branch' to create"
>                                 " new remote branches"))
> 
> -    # 2. Compute newly pushed bookmarks. We don't warn about bookmarked heads.
> -    localbookmarks = repo._bookmarks
> -    remotebookmarks = remote.listkeys('bookmarks')
> -    bookmarkedheads = set()
> -    for bm in localbookmarks:
> -        rnode = remotebookmarks.get(bm)
> -        if rnode and rnode in repo:
> -            lctx, rctx = repo[bm], repo[rnode]
> -            if bookmarks.validdest(repo, rctx, lctx):
> -                bookmarkedheads.add(lctx.node())
> -        else:
> -            if bm in newbookmarks and bm not in remotebookmarks:
> -                bookmarkedheads.add(repo[bm].node())
> +    # 2. Find heads that we need not warn about
> +    nowarnheads = _nowarnheads(repo, remote, newbookmarks)
> 
>     # 3. Check for new heads.
>     # If there are more heads after the push than before, a suitable
> @@ -366,7 +372,7 @@ def checkheads(repo, remote, outgoing, r
>                              " pushing new heads")
>         elif len(newhs) > len(oldhs):
>             # remove bookmarked or existing remote heads from the new heads list
> -            dhs = sorted(newhs - bookmarkedheads - oldhs)
> +            dhs = sorted(newhs - nowarnheads - oldhs)
>         if dhs:
>             if errormsg is None:
>                 if branch not in ('default', 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
@@ -238,6 +238,23 @@  def _oldheadssummary(repo, remoteheads, 
         unsynced = set()
     return {None: (oldheads, newheads, unsynced)}
 
+def _nowarnheads(repo, remote, newbookmarks):
+    # Compute newly pushed bookmarks. We don't warn about bookmarked heads.
+    localbookmarks = repo._bookmarks
+    remotebookmarks = remote.listkeys('bookmarks')
+    bookmarkedheads = set()
+    for bm in localbookmarks:
+        rnode = remotebookmarks.get(bm)
+        if rnode and rnode in repo:
+            lctx, rctx = repo[bm], repo[rnode]
+            if bookmarks.validdest(repo, rctx, lctx):
+                bookmarkedheads.add(lctx.node())
+        else:
+            if bm in newbookmarks and bm not in remotebookmarks:
+                bookmarkedheads.add(repo[bm].node())
+
+    return bookmarkedheads
+
 def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False,
                newbookmarks=[]):
     """Check that a push won't add any outgoing head
@@ -268,19 +285,8 @@  def checkheads(repo, remote, outgoing, r
                          hint=_("use 'hg push --new-branch' to create"
                                 " new remote branches"))
 
-    # 2. Compute newly pushed bookmarks. We don't warn about bookmarked heads.
-    localbookmarks = repo._bookmarks
-    remotebookmarks = remote.listkeys('bookmarks')
-    bookmarkedheads = set()
-    for bm in localbookmarks:
-        rnode = remotebookmarks.get(bm)
-        if rnode and rnode in repo:
-            lctx, rctx = repo[bm], repo[rnode]
-            if bookmarks.validdest(repo, rctx, lctx):
-                bookmarkedheads.add(lctx.node())
-        else:
-            if bm in newbookmarks and bm not in remotebookmarks:
-                bookmarkedheads.add(repo[bm].node())
+    # 2. Find heads that we need not warn about
+    nowarnheads = _nowarnheads(repo, remote, newbookmarks)
 
     # 3. Check for new heads.
     # If there are more heads after the push than before, a suitable
@@ -366,7 +372,7 @@  def checkheads(repo, remote, outgoing, r
                              " pushing new heads")
         elif len(newhs) > len(oldhs):
             # remove bookmarked or existing remote heads from the new heads list
-            dhs = sorted(newhs - bookmarkedheads - oldhs)
+            dhs = sorted(newhs - nowarnheads - oldhs)
         if dhs:
             if errormsg is None:
                 if branch not in ('default', None):