Patchwork [2,of,3,STABLE,v2] bookmarks: explicitly track identical bookmarks

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 24, 2014, 6:07 p.m.
Message ID <7773b325a83a08183435.1414174079@3.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/6462/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 24, 2014, 6:07 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1414172437 25200
#      Fri Oct 24 10:40:37 2014 -0700
# Branch stable
# Node ID 7773b325a83a08183435da11113a9b63838eae58
# Parent  8344ea64087d5eaab42709aaab6daa38dbde3db8
bookmarks: explicitly track identical bookmarks

bookmarks.compare() previously lumped identical bookmarks in the
"invalid" bucket. This patch adds a "same" bucket.

An 8-tuple for holding this state is pretty gnarly. The return value
should probably be converted into a class to increase readability. But
that is beyond the scope of a patch intended to be a late arrival to
stable.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -270,8 +270,9 @@  def compare(repo, srcmarks, dstmarks,
     :advdst:  advanced on dst side
     :diverge: diverge
     :differ:  changed, but changeset referred on src is unknown on dst
     :invalid: unknown on both side
+    :same:    same on both side
 
     Each elements of lists in result tuple is tuple "(bookmark name,
     changeset ID on source side, changeset ID on destination
     side)". Each changeset IDs are 40 hexadecimal digit string or
@@ -298,21 +299,19 @@  def compare(repo, srcmarks, dstmarks,
         bset = set(targets)
     else:
         srcmarkset = set(srcmarks)
         dstmarkset = set(dstmarks)
-        bset = srcmarkset ^ dstmarkset
-        for b in srcmarkset & dstmarkset:
-            if srchex(srcmarks[b]) != dsthex(dstmarks[b]):
-                bset.add(b)
+        bset = srcmarkset | dstmarkset
 
-    results = ([], [], [], [], [], [], [])
+    results = ([], [], [], [], [], [], [], [])
     addsrc = results[0].append
     adddst = results[1].append
     advsrc = results[2].append
     advdst = results[3].append
     diverge = results[4].append
     differ = results[5].append
     invalid = results[6].append
+    same = results[7].append
 
     for b in sorted(bset):
         if b not in srcmarks:
             if b in dstmarks:
@@ -323,9 +322,11 @@  def compare(repo, srcmarks, dstmarks,
             addsrc((b, srchex(srcmarks[b]), None))
         else:
             scid = srchex(srcmarks[b])
             dcid = dsthex(dstmarks[b])
-            if scid in repo and dcid in repo:
+            if scid == dcid:
+                same((b, scid, dcid))
+            elif scid in repo and dcid in repo:
                 sctx = repo[scid]
                 dctx = repo[dcid]
                 if sctx.rev() < dctx.rev():
                     if validdest(repo, sctx, dctx):
@@ -364,9 +365,9 @@  def _diverge(ui, b, path, localmarks):
 
 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
     ui.debug("checking for updated bookmarks\n")
     localmarks = repo._bookmarks
-    (addsrc, adddst, advsrc, advdst, diverge, differ, invalid
+    (addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same
      ) = compare(repo, remotemarks, localmarks, dsthex=hex)
 
     status = ui.status
     warn = ui.warn
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -332,9 +332,9 @@  def _pushdiscoverybookmarks(pushop):
 
     explicit = set(pushop.bookmarks)
 
     comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
-    addsrc, adddst, advsrc, advdst, diverge, differ, invalid = comp
+    addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
     for b, scid, dcid in advsrc:
         if b in explicit:
             explicit.remove(b)
         if not ancestors or repo[scid].rev() in ancestors: