Mercurial > public > mercurial-scm > hg-stable
diff hgext/lfs/wrapper.py @ 35189:f8f939a2926c
lfs: add a repo requirement for this extension when converting to lfs
This covers both the vanilla repo -> lfs repo and largefiles -> lfs conversions.
The largefiles extension adds the requirement directly, because it has a
dedicated command to convert. Using the convert extension is better, because it
supports more features.
I'd like ideas about how to ensure that converting away from lfs works on all
files. (See comments in test-lfs.t)
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 22 Nov 2017 22:38:50 -0500 |
parents | b8e5fb8d2389 |
children | 24aa4853c031 |
line wrap: on
line diff
--- a/hgext/lfs/wrapper.py Sun Nov 26 14:59:39 2017 -0500 +++ b/hgext/lfs/wrapper.py Wed Nov 22 22:38:50 2017 -0500 @@ -165,6 +165,31 @@ def filectxislfs(self): return _islfs(self.filelog(), self.filenode()) +def convertsink(orig, sink): + sink = orig(sink) + if sink.repotype == 'hg': + class lfssink(sink.__class__): + def putcommit(self, files, copies, parents, commit, source, revmap, + full, cleanp2): + pc = super(lfssink, self).putcommit + node = pc(files, copies, parents, commit, source, revmap, full, + cleanp2) + + if 'lfs' not in self.repo.requirements: + ctx = self.repo[node] + + # The file list may contain removed files, so check for + # membership before assuming it is in the context. + if any(f in ctx and ctx[f].islfs() for f, n in files): + self.repo.requirements.add('lfs') + self.repo._writerequirements() + + return node + + sink.__class__ = lfssink + + return sink + def vfsinit(orig, self, othervfs): orig(self, othervfs) # copy lfs related options