Patchwork [02,of,12,V2] bookmarks: rewrite "updatefromremote()" by "compare()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 22, 2013, 2:05 p.m.
Message ID <6f60d541bdf5bd90778c.1379858728@feefifofum>
Download mbox | patch
Permalink /patch/2600/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Sept. 22, 2013, 2:05 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1379858556 -32400
#      Sun Sep 22 23:02:36 2013 +0900
# Node ID 6f60d541bdf5bd90778c0e8395b3504d09d985d6
# Parent  2bb09ac15facc79ae3e926317d250d4f2bf50bfc
bookmarks: rewrite "updatefromremote()" by "compare()"

To update entries in bmstore "localmarks", this patch uses
"bin(changesetid)" instead of "repo[changesetid].node()" used in
original "updatefromremote()" implementation, because the former is
cheaper than the latter.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -6,7 +6,7 @@ 
 # GNU General Public License version 2 or any later version.
 
 from mercurial.i18n import _
-from mercurial.node import hex
+from mercurial.node import hex, bin
 from mercurial import encoding, error, util, obsolete
 import errno, os
 
@@ -317,47 +317,48 @@ 
             count += 1
     return count
 
+def _diverge(ui, b, path, localmarks):
+    if b == '@':
+        b = ''
+    # find a unique @ suffix
+    for x in range(1, 100):
+        n = '%s@%d' % (b, x)
+        if n not in localmarks:
+            break
+    # try to use an @pathalias suffix
+    # if an @pathalias already exists, we overwrite (update) it
+    for p, u in ui.configitems("paths"):
+        if path == u:
+            n = '%s@%s' % (b, p)
+    return n
+
 def updatefromremote(ui, repo, remotemarks, path):
     ui.debug("checking for updated bookmarks\n")
-    changed = False
     localmarks = repo._bookmarks
-    for k in sorted(remotemarks):
-        if k in localmarks:
-            nr, nl = remotemarks[k], localmarks[k]
-            if nr in repo:
-                cr = repo[nr]
-                cl = repo[nl]
-                if cl.rev() >= cr.rev():
-                    continue
-                if validdest(repo, cl, cr):
-                    localmarks[k] = cr.node()
-                    changed = True
-                    ui.status(_("updating bookmark %s\n") % k)
-                else:
-                    if k == '@':
-                        kd = ''
-                    else:
-                        kd = k
-                    # find a unique @ suffix
-                    for x in range(1, 100):
-                        n = '%s@%d' % (kd, x)
-                        if n not in localmarks:
-                            break
-                    # try to use an @pathalias suffix
-                    # if an @pathalias already exists, we overwrite (update) it
-                    for p, u in ui.configitems("paths"):
-                        if path == u:
-                            n = '%s@%s' % (kd, p)
 
-                    localmarks[n] = cr.node()
-                    changed = True
-                    ui.warn(_("divergent bookmark %s stored as %s\n") % (k, n))
-        elif remotemarks[k] in repo:
-            # add remote bookmarks for changes we already have
-            localmarks[k] = repo[remotemarks[k]].node()
-            changed = True
-            ui.status(_("adding remote bookmark %s\n") % k)
+    def addsrc(b, scid, dcid):
+        if scid in repo: # add remote bookmarks for changes we already have
+            localmarks[b] = bin(scid)
+            ui.status(_("adding remote bookmark %s\n") % b)
+            return True
+    def advsrc(b, scid, dcid):
+        localmarks[b] = bin(scid)
+        ui.status(_("updating bookmark %s\n") % b)
+        return True
+    def diverge(b, scid, dcid):
+        db = _diverge(ui, b, path, localmarks)
+        localmarks[db] = bin(scid)
+        ui.warn(_("divergent bookmark %s stored as %s\n") % (b, db))
+        return True
 
+    changed = _execactions(compare(repo, remotemarks, localmarks,
+                                   dsthex=hex),
+                           {'addsrc': addsrc,
+                            'advsrc': advsrc,
+                            'diverge': diverge,
+                            },
+                            ignore=set(['adddst', 'advdst', 'differ'])
+                            )
     if changed:
         localmarks.write()