fastannotate: deal with non-writable fastannotate directory

Summary:
Previously, fastannotate requires `.hg/fastannotate` to be writable. However,
this cannot be guaranteed in cases like running hg in other's repo.

This patch adds some exception handling to make fastannotate running in "fctx"
mode just work even if `.hg/fastannotate` is not writable.

Note: the `fastannotate` command ("fastannotate" mode) is not changed as if
that command is triggered explicitly, the user should be aware of it works
differently from the vanilla annotate command.

Test Plan: Added a test

Reviewers: #sourcecontrol, durham

Reviewed By: durham

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4481427

Tasks: 15489272

Signature: t1:4481427:1485775004:ccc0b99b38146034c5b235445d762e55dbb78dbe
This commit is contained in:
Jun Wu 2017-01-30 11:56:38 +00:00
parent 9d76f8392d
commit d38f639086
2 changed files with 26 additions and 7 deletions

View File

@ -233,13 +233,17 @@ def localreposetup(ui, repo):
master = _getmaster(self.ui)
needupdatepaths = []
lastnodemap = {}
for path in _filterfetchpaths(self, paths):
with context.annotatecontext(self, path) as actx:
if not actx.isuptodate(master, strict=False):
needupdatepaths.append(path)
lastnodemap[path] = actx.lastnode
if needupdatepaths:
clientfetch(self, needupdatepaths, lastnodemap, peer)
try:
for path in _filterfetchpaths(self, paths):
with context.annotatecontext(self, path) as actx:
if not actx.isuptodate(master, strict=False):
needupdatepaths.append(path)
lastnodemap[path] = actx.lastnode
if needupdatepaths:
clientfetch(self, needupdatepaths, lastnodemap, peer)
except Exception as ex:
# could be directory not writable or so, not fatal
self.ui.debug('fastannotate: prefetch failed: %r\n' % ex)
repo.__class__ = fastannotaterepo
def clientreposetup(ui, repo):

View File

@ -190,6 +190,21 @@ without downloading from the server
3: 4
4: 5
if the fastannotate directory is not writable, the fctx mode still works
$ rm -rf $p1
$ touch $p1
$ hg annotate a --debug --traceback --config fastannotate.modes=fctx
fastannotate: a: cache broken and deleted
fastannotate: prefetch failed: * (glob)
fastannotate: a: cache broken and deleted
fastannotate: falling back to the vanilla annotate: * (glob)
0: 1
1: 2
2: 3
3: 4
4: 5
with serverbuildondemand=False, the server will not build anything
$ cat >> ../repo-server/.hg/hgrc <<EOF