##// END OF EJS Templates
filelog: custom filelog to be used with narrow repos...
filelog: custom filelog to be used with narrow repos Narrow repos may have file revisions whose copy/rename metadata references files not in the store. This can pose problems when consumers attempt to access a missing referenced file revision. The narrow extension hacks around this problem by implementing a derived filelog type that provides custom implementations of renamed(), size(), and cmp() which handle renames against files not in the narrow spec by silently removing the rename metadata. While silently dropping metadata isn't the most robust solution, it is the easiest to implement. This commit ports the custom narrow filelog class to core. When a narrow repo is constructed, its ifilestorage creation function will automatically use the new filelog type. This means the extra logic is 0 cost for non-narrow repos and shouldn't interfere with their operation. Differential Revision: https://phab.mercurial-scm.org/D4643

File last commit:

r36490:d0d5eef5 default
r39801:3e801ffd default
Show More
narrowpatch.py
41 lines | 1.5 KiB | text/x-python | PythonLexer
# narrowpatch.py - extensions to mercurial patch module to support narrow clones
#
# Copyright 2017 Google, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from mercurial import (
extensions,
patch,
)
def setup(repo):
def _filepairs(orig, *args):
"""Only includes files within the narrow spec in the diff."""
narrowmatch = repo.narrowmatch()
if not narrowmatch.always():
for x in orig(*args):
f1, f2, copyop = x
if ((not f1 or narrowmatch(f1)) and
(not f2 or narrowmatch(f2))):
yield x
else:
for x in orig(*args):
yield x
def trydiff(orig, repo, revs, ctx1, ctx2, modified, added, removed,
copy, getfilectx, *args, **kwargs):
narrowmatch = repo.narrowmatch()
if not narrowmatch.always():
modified = [f for f in modified if narrowmatch(f)]
added = [f for f in added if narrowmatch(f)]
removed = [f for f in removed if narrowmatch(f)]
copy = {k: v for k, v in copy.iteritems() if narrowmatch(k)}
return orig(repo, revs, ctx1, ctx2, modified, added, removed, copy,
getfilectx, *args, **kwargs)
extensions.wrapfunction(patch, '_filepairs', _filepairs)
extensions.wrapfunction(patch, 'trydiff', trydiff)