diff --git a/remotefilelog/__init__.py b/remotefilelog/__init__.py --- a/remotefilelog/__init__.py +++ b/remotefilelog/__init__.py @@ -68,6 +68,8 @@ import time import traceback +from functools import partial + # ensures debug commands are registered hgdebugcommands.command @@ -130,6 +132,21 @@ # debugdata needs remotefilelog.len to work extensions.wrapcommand(commands.table, 'debugdata', debugdatashallow) +def extsetup(ui): + def _runcommandwrapper(orig, lui, repo, cmd, *args, **kwargs): + + if util.safehasattr(repo, 'fileservice') and cmd == 'commit': + # Currently prefetches happen even during commit, and that means + # that sometimes it's impossible to commit offline. This is a very + # bad user experience, but we don't know when and why it happens. + # This logger should help us with that. + logger = partial(lui.log, 'remotefilelogcommitprefetch', + user=shallowutil.getusername(repo.ui)) + repo.fileservice.logger = logger + return orig(lui, repo, cmd, *args) + + extensions.wrapfunction(dispatch, 'runcommand', _runcommandwrapper) + def cloneshallow(orig, ui, repo, *args, **opts): if opts.get('shallow'): repos = [] diff --git a/remotefilelog/fileserverclient.py b/remotefilelog/fileserverclient.py --- a/remotefilelog/fileserverclient.py +++ b/remotefilelog/fileserverclient.py @@ -557,6 +557,15 @@ if fetchhistory: missingids.update(historystore.getmissing(idstocheck)) + if util.safehasattr(self, 'logger') and missingids: + # logger is set if we want to log all prefetches (for example, + # prefetches that happen during command that shouldn't require + # network connection like hg commit). + # Since there can be a lot of missing ids, let's log just first 5 + # of them + files = ['(%s %s)' % (f[0], hex(f[1])) + for f in sorted(list(missingids))[:5]] + self.logger(files=', '.join(files), total=len(missingids)) # partition missing nodes into nullid and not-nullid so we can # warn about this filtering potentially shadowing bugs. nullids = len([None for unused, id in missingids if id == nullid]) diff --git a/tests/test-remotefilelog-commit-logging.t b/tests/test-remotefilelog-commit-logging.t new file mode 100644 --- /dev/null +++ b/tests/test-remotefilelog-commit-logging.t @@ -0,0 +1,66 @@ +Currently 'hg commit' sometimes requires network connection, and that means +that people can't commit offline. Let's log these issues to understand why and +how often it happens. + + $ PYTHONPATH=$TESTDIR/..:$PYTHONPATH + $ export PYTHONPATH + + $ . "$TESTDIR/library.sh" + + $ hginit master + $ cd master + $ cat >> .hg/hgrc < [remotefilelog] + > server=True + > EOF + $ echo x > x + $ hg commit -qAm x + $ mkdir dir + $ echo y > dir/y + $ hg commit -qAm y + + $ cd .. + +Shallow clone from full + + $ hgcloneshallow ssh://user@dummy/master shallow --noupdate + streaming all changes + 2 files to transfer, 473 bytes of data + transferred 473 bytes in * seconds (*/sec) (glob) + searching for changes + no changes found + + $ cd shallow + +Setup extension that logs ui.log linkrevfixup output on the stderr + $ cat >> $TESTTMP/uilog.py < from mercurial import extensions + > from mercurial import ui as uimod + > def uisetup(ui): + > extensions.wrapfunction(uimod.ui, 'log', mylog) + > def mylog(orig, self, service, *msg, **opts): + > if service in ['remotefilelogcommitprefetch']: + > kwstr = ", ".join("%s=%s" % (k, v) for k, v in + > sorted(opts.iteritems())) + > self.warn('%s: %s\n' % (service, kwstr)) + > return orig(self, service, *msg, **opts) + > EOF + $ cat >> $HGRCPATH < [extensions] + > uilog=$TESTTMP/uilog.py + > EOF + + $ hg update + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + 2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) + +Delete the cache - it should trigger prefetch + $ rm -r $TESTTMP/hgcache + $ echo y > x + $ hg ci -m test + remotefilelogcommitprefetch: files=(dir/y 076f5e2225b3ff0400b98c92aa6cdf403ee24cca), (x 1406e74118627694268417491f018a4a883152f0), total=2, user=test + 2 files fetched over 1 fetches - (2 misses, 0.00% hit ratio) over *s (glob) + +Make sure that next commit doesn't trigger prefetch + $ echo z > x + $ hg ci -m test2