annotate hgext/lfs/__init__.py @ 35618:c780e0649e41

lfs: migrate most file filtering from threshold to custom filter Migrate `lfs.threshold` to more powerful `lfs.filter` added by D4990618 so people can specify what files to be stored in LFS with more flexibility. This patch was authored by Jun Wu for the fb-experimental repo, to avoid using matcher for efficiency[1]. All I've changed here is to register the new 'lfs.track' default so that the tests run cleanly, and adapt the subsequent language changes. Migrating the remaining uses of 'lfs.threshold' can be done separately since there's a fallback in place. [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109388.html
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 31 Dec 2017 02:54:49 -0500
parents 6d6d20658cce
children 8580e5898cb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
1 # lfs - hash-preserving large file support using Git-LFS protocol
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
2 #
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
3 # Copyright 2017 Facebook, Inc.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
4 #
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
7
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
8 """lfs - large file support (EXPERIMENTAL)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
9
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
10 Configs::
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
11
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
12 [lfs]
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
13 # Remote endpoint. Multiple protocols are supported:
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
14 # - http(s)://user:pass@example.com/path
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
15 # git-lfs endpoint
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
16 # - file:///tmp/path
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
17 # local filesystem, usually for testing
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
18 # if unset, lfs will prompt setting this when it must use this value.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
19 # (default: unset)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
20 url = https://example.com/lfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
21
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
22 # Which files to track in LFS. Path tests are "**.extname" for file
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
23 # extensions, and "path:under/some/directory" for path prefix. Both
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
24 # are relative to the repository root, and the latter must be quoted.
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
25 # File size can be tested with the "size()" fileset, and tests can be
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
26 # joined with fileset operators. (See "hg help filesets.operators".)
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
27 #
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
28 # Some examples:
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
29 # - all() # everything
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
30 # - none() # nothing
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
31 # - size(">20MB") # larger than 20MB
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
32 # - !**.txt # anything not a *.txt file
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
33 # - **.zip | **.tar.gz | **.7z # some types of compressed files
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
34 # - "path:bin" # files under "bin" in the project root
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
35 # - (**.php & size(">2MB")) | (**.js & size(">5MB")) | **.tar.gz
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
36 # | ("path:bin" & !"path:/bin/README") | size(">1GB")
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
37 # (default: none())
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
38 track = size(">10M")
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
39
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
40 # how many times to retry before giving up on transferring an object
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
41 retry = 5
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
42
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
43 # the local directory to store lfs files for sharing across local clones.
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
44 # If not set, the cache is located in an OS specific cache location.
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
45 usercache = /path/to/global/cache
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
46 """
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
47
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
48 from __future__ import absolute_import
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
49
35099
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
50 from mercurial.i18n import _
b8e5fb8d2389 lfs: quiesce check-module-import warnings
Matt Harbison <matt_harbison@yahoo.com>
parents: 35098
diff changeset
51
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
52 from mercurial import (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
53 bundle2,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
54 changegroup,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
55 context,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
56 exchange,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
57 extensions,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
58 filelog,
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
59 fileset,
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
60 hg,
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
61 localrepo,
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
62 minifileset,
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
63 node,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
64 registrar,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
65 revlog,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
66 scmutil,
35346
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
67 upgrade,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
68 vfs as vfsmod,
35506
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
69 wireproto,
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
70 )
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
71
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
72 from . import (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
73 blobstore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
74 wrapper,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
75 )
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
76
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
77 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
78 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
79 # be specifying the version(s) of Mercurial they are tested with, or
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
80 # leave the attribute unspecified.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
81 testedwith = 'ships-with-hg-core'
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
82
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
83 configtable = {}
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
84 configitem = registrar.configitem(configtable)
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
85
35440
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
86 configitem('experimental', 'lfs.user-agent',
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
87 default=None,
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
88 )
e333d27514b0 lfs: add an experimental config to override User-Agent for the blob transfer
Matt Harbison <matt_harbison@yahoo.com>
parents: 35363
diff changeset
89
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
90 configitem('lfs', 'url',
35614
6d6d20658cce lfs: drop deprecated remote store config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35506
diff changeset
91 default=None,
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
92 )
35280
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
93 configitem('lfs', 'usercache',
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
94 default=None,
8e72f9152c4d lfs: introduce a user level cache for lfs files
Matt Harbison <matt_harbison@yahoo.com>
parents: 35214
diff changeset
95 )
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
96 # Deprecated
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
97 configitem('lfs', 'threshold',
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
98 default=None,
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
99 )
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
100 configitem('lfs', 'track',
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
101 default='none()',
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
102 )
35100
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
103 configitem('lfs', 'retry',
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
104 default=5,
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
105 )
07e97998d385 lfs: register config options
Matt Harbison <matt_harbison@yahoo.com>
parents: 35099
diff changeset
106
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
107 cmdtable = {}
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
108 command = registrar.command(cmdtable)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
109
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
110 templatekeyword = registrar.templatekeyword()
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
111
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
112 def featuresetup(ui, supported):
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
113 # don't die on seeing a repo with the lfs requirement
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
114 supported |= {'lfs'}
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
115
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
116 def uisetup(ui):
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
117 localrepo.localrepository.featuresetupfuncs.add(featuresetup)
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
118
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
119 def reposetup(ui, repo):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
120 # Nothing to do with a remote repo
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
121 if not repo.local():
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
122 return
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
123
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
124 trackspec = repo.ui.config('lfs', 'track')
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
125
35618
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
126 # deprecated config: lfs.threshold
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
127 threshold = repo.ui.configbytes('lfs', 'threshold')
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
128 if threshold:
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
129 fileset.parse(trackspec) # make sure syntax errors are confined
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
130 trackspec = "(%s) | size('>%d')" % (trackspec, threshold)
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
131
c780e0649e41 lfs: migrate most file filtering from threshold to custom filter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35614
diff changeset
132 repo.svfs.options['lfstrack'] = minifileset.compile(trackspec)
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
133 repo.svfs.lfslocalblobstore = blobstore.local(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
134 repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
135
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
136 # Push hook
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
137 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
138
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
139 if 'lfs' not in repo.requirements:
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
140 def checkrequireslfs(ui, repo, **kwargs):
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
141 if 'lfs' not in repo.requirements:
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
142 last = kwargs.get('node_last')
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
143 _bin = node.bin
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
144 if last:
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
145 s = repo.set('%n:%n', _bin(kwargs['node']), _bin(last))
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
146 else:
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
147 s = repo.set('%n', _bin(kwargs['node']))
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
148 for ctx in s:
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
149 # TODO: is there a way to just walk the files in the commit?
35452
488634db5928 lfs: fix committing deleted files caused by e0a1b9ee93cd
Jun Wu <quark@fb.com>
parents: 35440
diff changeset
150 if any(ctx[f].islfs() for f in ctx.files() if f in ctx):
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
151 repo.requirements.add('lfs')
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
152 repo._writerequirements()
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
153 break
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
154
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
155 ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs')
35504
6bb940de4c4c lfs: add the 'lfs' requirement in the changegroup transaction introducing lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35452
diff changeset
156 ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs')
35175
e0a1b9ee93cd lfs: add a repo requirement for this extension once an lfs file is committed
Matt Harbison <matt_harbison@yahoo.com>
parents: 35100
diff changeset
157
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
158 def wrapfilelog(filelog):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
159 wrapfunction = extensions.wrapfunction
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
160
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
161 wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
162 wrapfunction(filelog, 'renamed', wrapper.filelogrenamed)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
163 wrapfunction(filelog, 'size', wrapper.filelogsize)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
164
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
165 def extsetup(ui):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
166 wrapfilelog(filelog.filelog)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
167
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
168 wrapfunction = extensions.wrapfunction
35178
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
169
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
170 wrapfunction(scmutil, 'wrapconvertsink', wrapper.convertsink)
f8f939a2926c lfs: add a repo requirement for this extension when converting to lfs
Matt Harbison <matt_harbison@yahoo.com>
parents: 35175
diff changeset
171
35363
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
172 wrapfunction(upgrade, '_finishdatamigration',
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
173 wrapper.upgradefinishdatamigration)
b0ba1539af01 lfs: restore the local blob store after a repo upgrade
Matt Harbison <matt_harbison@yahoo.com>
parents: 35346
diff changeset
174
35346
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
175 wrapfunction(upgrade, 'preservedrequirements',
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
176 wrapper.upgraderequirements)
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
177
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
178 wrapfunction(upgrade, 'supporteddestrequirements',
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
179 wrapper.upgraderequirements)
9eb19b13e92a lfs: allow to run 'debugupgraderepo' on repo with largefiles
Boris Feld <boris.feld@octobus.net>
parents: 35280
diff changeset
180
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
181 wrapfunction(changegroup,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
182 'supportedoutgoingversions',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
183 wrapper.supportedoutgoingversions)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
184 wrapfunction(changegroup,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
185 'allsupportedversions',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
186 wrapper.allsupportedversions)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
187
35506
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
188 wrapfunction(exchange, 'push', wrapper.push)
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
189 wrapfunction(wireproto, '_capabilities', wrapper._capabilities)
fa865878a849 lfs: show a friendly message when pushing lfs to a server without lfs enabled
Matt Harbison <matt_harbison@yahoo.com>
parents: 35504
diff changeset
190
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
191 wrapfunction(context.basefilectx, 'cmp', wrapper.filectxcmp)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
192 wrapfunction(context.basefilectx, 'isbinary', wrapper.filectxisbinary)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
193 context.basefilectx.islfs = wrapper.filectxislfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
194
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
195 revlog.addflagprocessor(
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
196 revlog.REVIDX_EXTSTORED,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
197 (
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
198 wrapper.readfromstore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
199 wrapper.writetostore,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
200 wrapper.bypasscheckhash,
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
201 ),
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
202 )
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
203
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
204 wrapfunction(hg, 'clone', wrapper.hgclone)
35214
a8c778b2a689 lfs: enable the extension locally after sharing a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35213
diff changeset
205 wrapfunction(hg, 'postshare', wrapper.hgpostshare)
35213
24aa4853c031 lfs: enable the extension locally after cloning a repo with 'lfs' requirement
Matt Harbison <matt_harbison@yahoo.com>
parents: 35178
diff changeset
206
35098
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
207 # Make bundle choose changegroup3 instead of changegroup2. This affects
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
208 # "hg bundle" command. Note: it does not cover all bundle formats like
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
209 # "packed1". Using "packed1" with lfs will likely cause trouble.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
210 names = [k for k, v in exchange._bundlespeccgversions.items() if v == '02']
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
211 for k in names:
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
212 exchange._bundlespeccgversions[k] = '03'
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
213
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
214 # bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
215 # options and blob stores are passed from othervfs to the new readonlyvfs.
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
216 wrapfunction(vfsmod.readonlyvfs, '__init__', wrapper.vfsinit)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
217
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
218 # when writing a bundle via "hg bundle" command, upload related LFS blobs
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
219 wrapfunction(bundle2, 'writenewbundle', wrapper.writenewbundle)
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
220
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
221 @templatekeyword('lfs_files')
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
222 def lfsfiles(repo, ctx, **args):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
223 """List of strings. LFS files added or modified by the changeset."""
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
224 pointers = wrapper.pointersfromctx(ctx) # {path: pointer}
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
225 return sorted(pointers.keys())
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
226
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
227 @command('debuglfsupload',
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
228 [('r', 'rev', [], _('upload large files introduced by REV'))])
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
229 def debuglfsupload(ui, repo, **opts):
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
230 """upload lfs blobs added by the working copy parent or given revisions"""
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
231 revs = opts.get('rev', [])
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
232 pointers = wrapper.extractpointers(repo, scmutil.revrange(repo, revs))
66c5a8cf2868 lfs: import the Facebook git-lfs client extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
233 wrapper.uploadblobs(repo, pointers)