[PATCH 1 of 2] push-discovery: don't turn use generator when comparing bookmarks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1 of 2] push-discovery: don't turn use generator when comparing bookmarks

Boris Feld
# HG changeset patch
# User Boris Feld <[hidden email]>
# Date 1520609495 -3600
#      Fri Mar 09 16:31:35 2018 +0100
# Node ID 9ecb102cd955e075a6a637f1b8d4f5c8e3015751
# Parent  2cdf47e14c30dbdc2ebc0fd498fc0b85205ce2b3
# EXP-Topic push-book-handling
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9ecb102cd955
push-discovery: don't turn use generator when comparing bookmarks

We want extensions to be able to implement their own logic. Generators can be
consume only once, impractical for this purpose.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -620,8 +620,8 @@ def _pushdiscoverybookmarks(pushop):
         return hex(x)
 
     def hexifycompbookmarks(bookmarks):
-        for b, scid, dcid in bookmarks:
-            yield b, safehex(scid), safehex(dcid)
+        return [(b, safehex(scid), safehex(dcid))
+                for (b, scid, dcid) in bookmarks]
 
     comp = [hexifycompbookmarks(marks) for marks in comp]
     addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2 of 2] push-discovery: extract the bookmark comparison logic in its own function

Boris Feld
# HG changeset patch
# User Boris Feld <[hidden email]>
# Date 1520607221 -3600
#      Fri Mar 09 15:53:41 2018 +0100
# Node ID 5b15c9c72bc88931d5a5dc9bfec0935098c04402
# Parent  9ecb102cd955e075a6a637f1b8d4f5c8e3015751
# EXP-Topic push-book-handling
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5b15c9c72bc8
push-discovery: extract the bookmark comparison logic in its own function

This will help extensions to alter the behavior as they see fit.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -624,12 +624,20 @@ def _pushdiscoverybookmarks(pushop):
                 for (b, scid, dcid) in bookmarks]
 
     comp = [hexifycompbookmarks(marks) for marks in comp]
+    return _processcompared(pushop, ancestors, explicit, remotebookmark, comp)
+
+def _processcompared(pushop, pushed, explicit, remotebms, comp):
+    """take decision on bookmark to pull from the remote bookmark
+
+    Exist to help extension who want to alter this behavior."""
     addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
 
+    repo = pushop.repo
+
     for b, scid, dcid in advsrc:
         if b in explicit:
             explicit.remove(b)
-        if not ancestors or repo[scid].rev() in ancestors:
+        if not pushed or repo[scid].rev() in pushed:
             pushop.outbookmarks.append((b, dcid, scid))
     # search added bookmark
     for b, scid, dcid in addsrc:
@@ -655,8 +663,8 @@ def _pushdiscoverybookmarks(pushop):
     if explicit:
         explicit = sorted(explicit)
         # we should probably list all of them
-        ui.warn(_('bookmark %s does not exist on the local '
-                  'or remote repository!\n') % explicit[0])
+        pushop.ui.warn(_('bookmark %s does not exist on the local '
+                         'or remote repository!\n') % explicit[0])
         pushop.bkresult = 2
 
     pushop.outbookmarks.sort()
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1 of 2] push-discovery: don't turn use generator when comparing bookmarks

Yuya Nishihara
In reply to this post by Boris Feld
On Tue, 13 Mar 2018 17:49:17 +0100, Boris Feld wrote:

> # HG changeset patch
> # User Boris Feld <[hidden email]>
> # Date 1520609495 -3600
> #      Fri Mar 09 16:31:35 2018 +0100
> # Node ID 9ecb102cd955e075a6a637f1b8d4f5c8e3015751
> # Parent  2cdf47e14c30dbdc2ebc0fd498fc0b85205ce2b3
> # EXP-Topic push-book-handling
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9ecb102cd955
> push-discovery: don't turn use generator when comparing bookmarks

Seems fine. Queued, thanks.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel