This is an archive of the discontinued Mercurial Phabricator instance.

branchcache: move loading of branch names and nodes into it's own function
ClosedPublic

Authored by pulkit on Feb 25 2019, 10:07 AM.

Details

Summary

This will help me in implementing lazy loading of the branchcache in upcoming
patches.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

pulkit created this revision.Feb 25 2019, 10:07 AM

I am trying to make branchcache make lazy load and only validate nodes if required. This will speed up operations and loading of branchcache. Right now loading of branchcache validates all the nodes which is not required until the branch which has that node is accessed. I believe doing this will speed up things. However the current dict interface of branchcache object is making this hard, hence I have sent only this patch for now.

lothiraldan accepted this revision.Feb 25 2019, 1:20 PM
lothiraldan added a subscriber: lothiraldan.

LGTM, queued thanks

This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Feb 25 2019, 5:58 PM
if not bcache.validfor(repo):
    # invalidate the cache
    raise ValueError(r'tip differs')
  • cl = repo.changelog
  • for line in lineiter:
  • line = line.rstrip('\n')
  • if not line:
  • continue
  • node, state, label = line.split(" ", 2)
  • if state not in 'oc':
  • raise ValueError(r'invalid branch state')
  • label = encoding.tolocal(label.strip())
  • node = bin(node)
  • if not cl.hasnode(node):
  • raise ValueError(
  • r'node %s does not exist' % pycompat.sysstr(hex(node)))
  • bcache.setdefault(label, []).append(node)
  • if state == 'c':
  • bcache._closednodes.add(node) -

+ bcache.load(repo, f)

except (IOError, OSError):
    return None

@@ -214,6 +198,26 @@

return bcache

+ def load(self, repo, f):
+ """ fully loads the branchcache by reading from the file f """
+ cl = repo.changelog
+ lineiter = iter(f)

Breaks test-static-http.t probably because f is read twice through
different iterators.