Mercurial > hg
diff hgext/lfs/__init__.py @ 35504:6bb940de4c4c
lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
A hook like this is how largefiles manages to do the same. Largefiles uses a
changegroup hook, but this uses pretxnchangegroup because that actually causes
the transaction to rollback in the unlikely event that writing the requirements
out fails. Sadly, the requires file itself isn't rolled back if a subsequent
hook fails, but that seems trivial.
Now that commit, changegroup and convert are covered, I don't think there's any
way to get an lfs repo without the requirement.
The grep exit code is blotted out of some test-lfs-serve.t tests now showing the
requirement, because run-tests.py doesn't support conditionalizing the exit
code.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 23 Dec 2017 23:51:40 -0500 |
parents | 488634db5928 |
children | fa865878a849 |
line wrap: on
line diff
--- a/hgext/lfs/__init__.py Sat Dec 23 15:07:24 2017 -0500 +++ b/hgext/lfs/__init__.py Sat Dec 23 23:51:40 2017 -0500 @@ -43,6 +43,7 @@ filelog, hg, localrepo, + node, registrar, revlog, scmutil, @@ -122,13 +123,21 @@ if 'lfs' not in repo.requirements: def checkrequireslfs(ui, repo, **kwargs): if 'lfs' not in repo.requirements: - ctx = repo[kwargs['node']] + last = kwargs.get('node_last') + _bin = node.bin + if last: + s = repo.set('%n:%n', _bin(kwargs['node']), _bin(last)) + else: + s = repo.set('%n', _bin(kwargs['node'])) + for ctx in s: # TODO: is there a way to just walk the files in the commit? if any(ctx[f].islfs() for f in ctx.files() if f in ctx): repo.requirements.add('lfs') repo._writerequirements() + break ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs') + ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs') def wrapfilelog(filelog): wrapfunction = extensions.wrapfunction