Mercurial > hg
comparison hgext/lfs/__init__.py @ 35175:e0a1b9ee93cd
lfs: add a repo requirement for this extension once an lfs file is committed
Largefiles does the same thing (also delayed until the first largefile commit),
to prevent access to the repo without the extension. In the case of this
extension, not having the extension loaded while accessing an lfs file results
in cryptic errors about "missing processor for flag '0x2000'". If enabled
locally but not remotely, the cryptic error message is about no common
changegroup version. (It wants '03', which is currently experimental.)
The largefiles extension looks for any tracked file that starts with '.hglf/'.
Unfortunately, that doesn't work here. I didn't see any way to get the files
that were just committed, without doing a full status. But since there's no
secondary check on adding an lfs file once the extension is loaded and a
threshold set, the best practice is to only enable this locally on a repo that
needs it. That should minimize the unnecessary overhead for repos without an
lfs file.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 15 Nov 2017 23:43:15 -0500 |
parents | 07e97998d385 |
children | f8f939a2926c |
comparison
equal
deleted
inserted
replaced
35164:6864c405f023 | 35175:e0a1b9ee93cd |
---|---|
35 changegroup, | 35 changegroup, |
36 context, | 36 context, |
37 exchange, | 37 exchange, |
38 extensions, | 38 extensions, |
39 filelog, | 39 filelog, |
40 localrepo, | |
40 registrar, | 41 registrar, |
41 revlog, | 42 revlog, |
42 scmutil, | 43 scmutil, |
43 vfs as vfsmod, | 44 vfs as vfsmod, |
44 ) | 45 ) |
82 cmdtable = {} | 83 cmdtable = {} |
83 command = registrar.command(cmdtable) | 84 command = registrar.command(cmdtable) |
84 | 85 |
85 templatekeyword = registrar.templatekeyword() | 86 templatekeyword = registrar.templatekeyword() |
86 | 87 |
88 def featuresetup(ui, supported): | |
89 # don't die on seeing a repo with the lfs requirement | |
90 supported |= {'lfs'} | |
91 | |
92 def uisetup(ui): | |
93 localrepo.localrepository.featuresetupfuncs.add(featuresetup) | |
94 | |
87 def reposetup(ui, repo): | 95 def reposetup(ui, repo): |
88 # Nothing to do with a remote repo | 96 # Nothing to do with a remote repo |
89 if not repo.local(): | 97 if not repo.local(): |
90 return | 98 return |
91 | 99 |
95 repo.svfs.lfslocalblobstore = blobstore.local(repo) | 103 repo.svfs.lfslocalblobstore = blobstore.local(repo) |
96 repo.svfs.lfsremoteblobstore = blobstore.remote(repo) | 104 repo.svfs.lfsremoteblobstore = blobstore.remote(repo) |
97 | 105 |
98 # Push hook | 106 # Push hook |
99 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) | 107 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) |
108 | |
109 if 'lfs' not in repo.requirements: | |
110 def checkrequireslfs(ui, repo, **kwargs): | |
111 if 'lfs' not in repo.requirements: | |
112 ctx = repo[kwargs['node']] | |
113 # TODO: is there a way to just walk the files in the commit? | |
114 if any(ctx[f].islfs() for f in ctx.files()): | |
115 repo.requirements.add('lfs') | |
116 repo._writerequirements() | |
117 | |
118 ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs') | |
100 | 119 |
101 def wrapfilelog(filelog): | 120 def wrapfilelog(filelog): |
102 wrapfunction = extensions.wrapfunction | 121 wrapfunction = extensions.wrapfunction |
103 | 122 |
104 wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision) | 123 wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision) |