From 27925e5fef0212399cc676ee5a7789e02d488eb4 Mon Sep 17 00:00:00 2001 From: Durham Goode Date: Thu, 13 Oct 2016 09:47:40 -0700 Subject: [PATCH] Fix incremental updating of heads and bookmarks Summary: We had tried to be smart about incrementally updating only the heads and bookmarks that actually changed, but the old logic was broken. It compared binary and hex nodes against each other, and therefore didn't actually do anything incrementally. This patch makes us convert the Mercurial data to hex at the very beginning, so the incremental check uses hex as well. Test Plan: Inserted print statements around the insert/delets and verified they changed before and after Reviewers: #mercurial Differential Revision: https://phabricator.intern.facebook.com/D4012317 --- hgsql.py | 9 +++++---- tests/test-sync.t | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hgsql.py b/hgsql.py index 67b8281ea1..52d24868a5 100644 --- a/hgsql.py +++ b/hgsql.py @@ -823,7 +823,7 @@ def wraprepo(repo): self.sqlconn.commit() # Compute new heads, and delete old heads - newheads = set(self.heads()) + newheads = set(hex(n) for n in self.heads()) oldheads = [] cursor.execute( "SELECT value FROM revision_references " @@ -848,7 +848,8 @@ def wraprepo(repo): ) # Compute new bookmarks, and delete old bookmarks - newbookmarks = self._bookmarks.copy() + newbookmarks = dict((k, hex(v)) for k, v in + self._bookmarks.iteritems()) oldbookmarks = [] cursor.execute( "SELECT name, value FROM revision_references " @@ -876,13 +877,13 @@ def wraprepo(repo): for head in newheads: tmpl.append("(%s, 'heads', NULL, %s)") values.append(reponame) - values.append(hex(head)) + values.append(head) for k, v in newbookmarks.iteritems(): tmpl.append("(%s, 'bookmarks', %s, %s)") values.append(repo.sqlreponame) values.append(k) - values.append(hex(v)) + values.append(v) if tmpl: cursor.execute("INSERT INTO revision_references(repo, namespace, name, value) " + diff --git a/tests/test-sync.t b/tests/test-sync.t index 4d941b6cfa..3995146488 100644 --- a/tests/test-sync.t +++ b/tests/test-sync.t @@ -75,7 +75,9 @@ # Verify that --forcesync works - $ cd ../master + $ cd ../ + $ cp $HGRCPATH backup.hgrc + $ cd master $ echo '[hooks]' >> $HGRCPATH $ echo 'presyncdb=$TESTTMP/hook.sh' >> $HGRCPATH $ echo 'sleep 2' > $TESTTMP/hook.sh @@ -92,3 +94,32 @@ 3 a got lock after ? seconds (glob) 3 a + $ cd .. + $ cp backup.hgrc $HGRCPATH + +# Update one bookmark but not the other + $ cat >> $TESTTMP/inspectsql.py < import os, sys + > from mercurial import demandimport, extensions + > with demandimport.deactivated(): + > import mysql.connector + > watchstrings = os.environ.get("INSPECTSQL") + > if watchstrings: + > watchstrings = watchstrings.split(',') + > def printsql(orig, *args, **kwargs): + > if not watchstrings or any(s for s in watchstrings if s in args[1]): + > print >> sys.stderr, args[1] % args[2] + > return orig(*args, **kwargs) + > extensions.wrapfunction(mysql.connector.cursor.MySQLCursor, "execute", printsql) + > EOF + $ cat >> $HGRCPATH < [extensions] + > inspectsql=$TESTTMP/inspectsql.py + > EOF + $ cd master + $ INSPECTSQL=DELETE,INSERT hg book mybook2 + INSERT INTO revision_references(repo, namespace, name, value) VALUES (masterrepo, 'bookmarks', mybook2, 0000000000000000000000000000000000000000) + INSERT INTO revision_references(repo, namespace, name, value) + VALUES(masterrepo, 'tip', 'tip', 3) ON DUPLICATE KEY UPDATE value=3 + $ cd .. + $ cp backup.hgrc $HGRCPATH