Patchwork D10016: tags: return tag cache source from _readtagcache()

login
register
mail settings
Submitter phabricator
Date Feb. 17, 2021, 7:44 p.m.
Message ID <differential-rev-PHID-DREV-mkvydjgm5dwtke5y7cpc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48329/
State New
Headers show

Comments

phabricator - Feb. 17, 2021, 7:44 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the cache is invalid, _readtagcache() can return data which has a wrong
  filenode. We want to fix the cache in such cases by replacing the wrong filenode
  with a correct one. To do so, first the callers need to be aware from
  which cache values returned by this function are read.
  
  This patch adds a new return value which depicts the source of data return from
  `_readtagcache()`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10016

AFFECTED FILES
  mercurial/tags.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -183,7 +183,9 @@ 
 
     The tags cache is read and updated as a side-effect of calling.
     """
-    (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo)
+    (heads, tagfnode, valid, cachetags, shouldwrite, source) = _readtagcache(
+        ui, repo
+    )
     if cachetags is not None:
         assert not shouldwrite
         # XXX is this really 100% correct?  are there oddball special
@@ -392,7 +394,7 @@ 
 def _readtagcache(ui, repo):
     """Read the tag cache.
 
-    Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite).
+    Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite, source).
 
     If the cache is completely up-to-date, "cachetags" is a dict of the
     form returned by _readtags() and "heads", "fnodes", and "validinfo" are
@@ -404,6 +406,12 @@ 
     when writing the tags cache. "fnodes" is a mapping from head to .hgtags
     filenode. "shouldwrite" is True.
 
+    "source" is from which cache the data is read. Possible values are:
+        tags2: when data is read from `tags2-<filtername>` cache
+        hgtagsfnodes: data is read from hgtagsfnodes cache
+        other: when data is read from source other than tags2 and
+               hgtagsfnodes cache
+
     If the cache is not up to date, the caller is responsible for reading tag
     info from each returned head. (See findglobaltags().)
     """
@@ -443,7 +451,7 @@ 
     ):
         tags = _readtags(ui, repo, cachelines, cachefile.name)
         cachefile.close()
-        return (None, None, None, tags, False)
+        return (None, None, None, tags, False, 'tags2')
     if cachefile:
         cachefile.close()  # ignore rest of file
 
@@ -453,7 +461,7 @@ 
     # Case 2 (uncommon): empty repo; get out quickly and don't bother
     # writing an empty cache.
     if repoheads == [nullid]:
-        return ([], {}, valid, {}, False)
+        return ([], {}, valid, {}, False, 'other')
 
     # Case 3 (uncommon): cache file missing or empty.
 
@@ -471,7 +479,7 @@ 
     if not len(repo.file(b'.hgtags')):
         # No tags have ever been committed, so we can avoid a
         # potentially expensive search.
-        return ([], {}, valid, None, True)
+        return ([], {}, valid, None, True, 'other')
 
     # Now we have to lookup the .hgtags filenode for every new head.
     # This is the most expensive part of finding tags, so performance
@@ -482,7 +490,7 @@ 
 
     # Caller has to iterate over all heads, but can use the filenodes in
     # cachefnode to get to each .hgtags revision quickly.
-    return (repoheads, cachefnode, valid, None, True)
+    return (repoheads, cachefnode, valid, None, True, 'hgtagsfnodes')
 
 
 def _getfnodes(ui, repo, nodes):