Patchwork [4,of,6] tags: support reading tags cache without populating

login
register
mail settings
Submitter Gregory Szorc
Date June 1, 2015, 12:28 a.m.
Message ID <a95c5fe846acd1336c11.1433118509@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/9413/
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 1432596263 25200
#      Mon May 25 16:24:23 2015 -0700
# Node ID a95c5fe846acd1336c11f591273bc82db5b31ddc
# Parent  a9a943bfb732069110dd2d211f842bad22547535
tags: support reading tags cache without populating

An upcoming patch will teach the bundle2 protocol to transfer .hgtags
fnodes to the client. We don't want this to incur any extra work
at serve time. Create an optional cache query mode that doesn't
populate the cache as a side-effect.

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -441,13 +441,15 @@  class hgtagsfnodescache(object):
             for i in range(rawlen - wantedlen):
                 self._raw.pop()
             self._dirtyoffset = len(self._raw)
 
-    def getfnode(self, node):
+    def getfnode(self, node, computemissing=True):
         """Obtain the filenode of the .hgtags file at a specified revision.
 
         If the value is in the cache, the entry will be validated and returned.
-        Otherwise, the filenode will be computed and returned.
+        Otherwise, the filenode will be computed and returned unless
+        "computemissing" is False, in which case None will be returned without
+        any potentially expensive computation being performed.
 
         If an .hgtags does not exist at the specified revision, nullid is
         returned.
         """
@@ -469,9 +471,14 @@  class hgtagsfnodescache(object):
                 return record[4:]
 
             # Fall through.
 
-        # If we get here, the entry is either missing or invalid. Populate it.
+        # If we get here, the entry is either missing or invalid.
+
+        if not computemissing:
+            return None
+
+        # Populate missing entry.
         try:
             fnode = ctx.filenode('.hgtags')
         except error.LookupError:
             # No .hgtags file on this revision.