Patchwork [5,of,6] tags: support setting hgtags fnodes cache entries

login
register
mail settings
Submitter Gregory Szorc
Date June 1, 2015, 12:28 a.m.
Message ID <8f34e8f9636d47c50948.1433118510@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/9414/
State Accepted
Headers show

Comments

Gregory Szorc - June 1, 2015, 12:28 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1432597735 25200
#      Mon May 25 16:48:55 2015 -0700
# Node ID 8f34e8f9636d47c5094844c4e8bbf7353b95d75a
# Parent  a95c5fe846acd1336c11f591273bc82db5b31ddc
tags: support setting hgtags fnodes cache entries

An upcoming patch will teach bundle2 to transfer .hgtags fnodes
values. To support this, we need to support inserting values into
the cache.

Add functionality to do that.
Pierre-Yves David - June 1, 2015, 6:44 a.m.
On 05/31/2015 05:28 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1432597735 25200
> #      Mon May 25 16:48:55 2015 -0700
> # Node ID 8f34e8f9636d47c5094844c4e8bbf7353b95d75a
> # Parent  a95c5fe846acd1336c11f591273bc82db5b31ddc
> tags: support setting hgtags fnodes cache entries

Patch 4 and 5 make sense on their own and have been pushed to the 
clowncopter.

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -483,16 +483,29 @@  class hgtagsfnodescache(object):
         except error.LookupError:
             # No .hgtags file on this revision.
             fnode = nullid
 
+        self._writeentry(offset, properprefix, fnode)
+        return fnode
+
+    def setfnode(self, node, fnode):
+        """Set the .hgtags filenode for a given changeset."""
+        assert len(fnode) == 20
+        ctx = self._repo[node]
+
+        # Do a lookup first to avoid writing if nothing has changed.
+        if self.getfnode(ctx.node(), computemissing=False) == fnode:
+            return
+
+        self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode)
+
+    def _writeentry(self, offset, prefix, fnode):
         # Slices on array instances only accept other array.
-        entry = array('c', properprefix + fnode)
+        entry = array('c', prefix + fnode)
         self._raw[offset:offset + _fnodesrecsize] = entry
         # self._dirtyoffset could be None.
         self._dirtyoffset = min(self._dirtyoffset, offset) or 0
 
-        return fnode
-
     def write(self):
         """Perform all necessary writes to cache file.
 
         This may no-op if no writes are needed or if a write lock could