Mercurial > public > mercurial-scm > hg
annotate hgext/largefiles/reposetup.py @ 15626:931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Mercurial 1.7 added the --subrepos flag to status and archive and the
largefiles code was still compatible with the old method signatures.
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Wed, 07 Dec 2011 16:25:51 +0100 |
parents | 74e691b141c4 |
children | 2b40513384ca |
rev | line source |
---|---|
15168 | 1 # Copyright 2009-2010 Gregory P. Ward |
2 # Copyright 2009-2010 Intelerad Medical Systems Incorporated | |
3 # Copyright 2010-2011 Fog Creek Software | |
4 # Copyright 2010-2011 Unity Technologies | |
5 # | |
6 # This software may be used and distributed according to the terms of the | |
7 # GNU General Public License version 2 or any later version. | |
8 | |
9 '''setup for largefiles repositories: reposetup''' | |
10 import copy | |
11 import types | |
12 import os | |
13 import re | |
14 | |
15305 | 15 from mercurial import context, error, manifest, match as match_, node, util |
15168 | 16 from mercurial.i18n import _ |
17 | |
18 import lfcommands | |
19 import proto | |
20 import lfutil | |
21 | |
22 def reposetup(ui, repo): | |
23 # wire repositories should be given new wireproto functions but not the | |
24 # other largefiles modifications | |
25 if not repo.local(): | |
26 return proto.wirereposetup(ui, repo) | |
27 | |
28 for name in ('status', 'commitctx', 'commit', 'push'): | |
29 method = getattr(repo, name) | |
30 #if not (isinstance(method, types.MethodType) and | |
31 # method.im_func is repo.__class__.commitctx.im_func): | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
32 if (isinstance(method, types.FunctionType) and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
33 method.func_name == 'wrap'): |
15168 | 34 ui.warn(_('largefiles: repo method %r appears to have already been' |
35 ' wrapped by another extension: ' | |
36 'largefiles may behave incorrectly\n') | |
37 % name) | |
38 | |
39 class lfiles_repo(repo.__class__): | |
40 lfstatus = False | |
41 def status_nolfiles(self, *args, **kwargs): | |
42 return super(lfiles_repo, self).status(*args, **kwargs) | |
43 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
44 # When lfstatus is set, return a context that gives the names |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
45 # of largefiles instead of their corresponding standins and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
46 # identifies the largefiles as always binary, regardless of |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
47 # their actual contents. |
15168 | 48 def __getitem__(self, changeid): |
49 ctx = super(lfiles_repo, self).__getitem__(changeid) | |
50 if self.lfstatus: | |
51 class lfiles_manifestdict(manifest.manifestdict): | |
52 def __contains__(self, filename): | |
53 if super(lfiles_manifestdict, | |
54 self).__contains__(filename): | |
55 return True | |
56 return super(lfiles_manifestdict, | |
57 self).__contains__(lfutil.shortname+'/' + filename) | |
58 class lfiles_ctx(ctx.__class__): | |
59 def files(self): | |
60 filenames = super(lfiles_ctx, self).files() | |
15170
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
61 return [re.sub('^\\'+lfutil.shortname+'/', '', |
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
62 filename) for filename in filenames] |
15168 | 63 def manifest(self): |
64 man1 = super(lfiles_ctx, self).manifest() | |
65 man1.__class__ = lfiles_manifestdict | |
66 return man1 | |
67 def filectx(self, path, fileid=None, filelog=None): | |
68 try: | |
69 result = super(lfiles_ctx, self).filectx(path, | |
70 fileid, filelog) | |
71 except error.LookupError: | |
72 # Adding a null character will cause Mercurial to | |
73 # identify this as a binary file. | |
74 result = super(lfiles_ctx, self).filectx( | |
75 lfutil.shortname + '/' + path, fileid, | |
76 filelog) | |
77 olddata = result.data | |
78 result.data = lambda: olddata() + '\0' | |
79 return result | |
80 ctx.__class__ = lfiles_ctx | |
81 return ctx | |
82 | |
83 # Figure out the status of big files and insert them into the | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
84 # appropriate list in the result. Also removes standin files |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
85 # from the listing. Revert to the original status if |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
86 # self.lfstatus is False. |
15168 | 87 def status(self, node1='.', node2=None, match=None, ignored=False, |
88 clean=False, unknown=False, listsubrepos=False): | |
89 listignored, listclean, listunknown = ignored, clean, unknown | |
90 if not self.lfstatus: | |
15626
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
91 return super(lfiles_repo, self).status(node1, node2, match, |
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
92 listignored, listclean, listunknown, listsubrepos) |
15168 | 93 else: |
94 # some calls in this function rely on the old version of status | |
95 self.lfstatus = False | |
96 if isinstance(node1, context.changectx): | |
97 ctx1 = node1 | |
98 else: | |
99 ctx1 = repo[node1] | |
100 if isinstance(node2, context.changectx): | |
101 ctx2 = node2 | |
102 else: | |
103 ctx2 = repo[node2] | |
104 working = ctx2.rev() is None | |
105 parentworking = working and ctx1 == self['.'] | |
106 | |
107 def inctx(file, ctx): | |
108 try: | |
109 if ctx.rev() is None: | |
110 return file in ctx.manifest() | |
111 ctx[file] | |
112 return True | |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
113 except KeyError: |
15168 | 114 return False |
115 | |
116 if match is None: | |
117 match = match_.always(self.root, self.getcwd()) | |
118 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
119 # Create a copy of match that matches standins instead |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
120 # of largefiles. |
15168 | 121 def tostandin(file): |
122 if inctx(lfutil.standin(file), ctx2): | |
123 return lfutil.standin(file) | |
124 return file | |
125 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
126 # Create a function that we can use to override what is |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
127 # normally the ignore matcher. We've already checked |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
128 # for ignored files on the first dirstate walk, and |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
129 # unecessarily re-checking here causes a huge performance |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
130 # hit because lfdirstate only knows about largefiles |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
131 def _ignoreoverride(self): |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
132 return False |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
133 |
15168 | 134 m = copy.copy(match) |
135 m._files = [tostandin(f) for f in m._files] | |
136 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
137 # Get ignored files here even if we weren't asked for them; we |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
138 # must use the result here for filtering later |
15626
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
139 result = super(lfiles_repo, self).status(node1, node2, m, |
931dc4af0d95
largefiles: remove pre-1.7 compatibility code
Martin Geisler <mg@aragost.com>
parents:
15617
diff
changeset
|
140 True, clean, unknown, listsubrepos) |
15168 | 141 if working: |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
142 # hold the wlock while we read largefiles and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
143 # update the lfdirstate |
15168 | 144 wlock = repo.wlock() |
145 try: | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
146 # Any non-largefiles that were explicitly listed must be |
15168 | 147 # taken out or lfdirstate.status will report an error. |
148 # The status of these files was already computed using | |
149 # super's status. | |
150 lfdirstate = lfutil.openlfdirstate(ui, self) | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
151 # Override lfdirstate's ignore matcher to not do |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
152 # anything |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
153 orig_ignore = lfdirstate._ignore |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
154 lfdirstate._ignore = _ignoreoverride |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
155 |
15168 | 156 match._files = [f for f in match._files if f in |
157 lfdirstate] | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
158 # Don't waste time getting the ignored and unknown |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
159 # files again; we already have them |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
160 s = lfdirstate.status(match, [], False, |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
161 listclean, False) |
15168 | 162 (unsure, modified, added, removed, missing, unknown, |
163 ignored, clean) = s | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
164 # Replace the list of ignored and unknown files with |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
165 # the previously caclulated lists, and strip out the |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
166 # largefiles |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
167 lfiles = set(lfdirstate._map) |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
168 ignored = set(result[5]).difference(lfiles) |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
169 unknown = set(result[4]).difference(lfiles) |
15168 | 170 if parentworking: |
171 for lfile in unsure: | |
172 if ctx1[lfutil.standin(lfile)].data().strip() \ | |
173 != lfutil.hashfile(self.wjoin(lfile)): | |
174 modified.append(lfile) | |
175 else: | |
176 clean.append(lfile) | |
177 lfdirstate.normal(lfile) | |
178 lfdirstate.write() | |
179 else: | |
180 tocheck = unsure + modified + added + clean | |
181 modified, added, clean = [], [], [] | |
182 | |
183 for lfile in tocheck: | |
184 standin = lfutil.standin(lfile) | |
185 if inctx(standin, ctx1): | |
186 if ctx1[standin].data().strip() != \ | |
187 lfutil.hashfile(self.wjoin(lfile)): | |
188 modified.append(lfile) | |
189 else: | |
190 clean.append(lfile) | |
191 else: | |
192 added.append(lfile) | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
193 # Replace the original ignore function |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
194 lfdirstate._ignore = orig_ignore |
15168 | 195 finally: |
196 wlock.release() | |
197 | |
198 for standin in ctx1.manifest(): | |
199 if not lfutil.isstandin(standin): | |
200 continue | |
201 lfile = lfutil.splitstandin(standin) | |
202 if not match(lfile): | |
203 continue | |
204 if lfile not in lfdirstate: | |
205 removed.append(lfile) | |
206 # Handle unknown and ignored differently | |
207 lfiles = (modified, added, removed, missing, [], [], clean) | |
208 result = list(result) | |
209 # Unknown files | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
210 unknown = set(unknown).difference(ignored) |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
211 result[4] = [f for f in unknown |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
212 if (repo.dirstate[f] == '?' and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
213 not lfutil.isstandin(f))] |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
214 # Ignored files were calculated earlier by the dirstate, |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
215 # and we already stripped out the largefiles from the list |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
216 result[5] = ignored |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
217 # combine normal files and largefiles |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
218 normals = [[fn for fn in filelist |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
219 if not lfutil.isstandin(fn)] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
220 for filelist in result] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
221 result = [sorted(list1 + list2) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
222 for (list1, list2) in zip(normals, lfiles)] |
15168 | 223 else: |
224 def toname(f): | |
225 if lfutil.isstandin(f): | |
226 return lfutil.splitstandin(f) | |
227 return f | |
228 result = [[toname(f) for f in items] for items in result] | |
229 | |
230 if not listunknown: | |
231 result[4] = [] | |
232 if not listignored: | |
233 result[5] = [] | |
234 if not listclean: | |
235 result[6] = [] | |
236 self.lfstatus = True | |
237 return result | |
238 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
239 # As part of committing, copy all of the largefiles into the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
240 # cache. |
15168 | 241 def commitctx(self, *args, **kwargs): |
242 node = super(lfiles_repo, self).commitctx(*args, **kwargs) | |
243 ctx = self[node] | |
244 for filename in ctx.files(): | |
245 if lfutil.isstandin(filename) and filename in ctx.manifest(): | |
246 realfile = lfutil.splitstandin(filename) | |
15316
c65f5b6e26d4
largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15312
diff
changeset
|
247 lfutil.copytostore(self, ctx.node(), realfile) |
15168 | 248 |
249 return node | |
250 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
251 # Before commit, largefile standins have not had their |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
252 # contents updated to reflect the hash of their largefile. |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
253 # Do that here. |
15168 | 254 def commit(self, text="", user=None, date=None, match=None, |
255 force=False, editor=False, extra={}): | |
256 orig = super(lfiles_repo, self).commit | |
257 | |
258 wlock = repo.wlock() | |
259 try: | |
260 if getattr(repo, "_isrebasing", False): | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
261 # We have to take the time to pull down the new |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
262 # largefiles now. Otherwise if we are rebasing, |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
263 # any largefiles that were modified in the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
264 # destination changesets get overwritten, either |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
265 # by the rebase or in the first commit after the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
266 # rebase. |
15168 | 267 lfcommands.updatelfiles(repo.ui, repo) |
268 # Case 1: user calls commit with no specific files or | |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
269 # include/exclude patterns: refresh and commit all files that |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
270 # are "dirty". |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
271 if ((match is None) or |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
272 (not match.anypats() and not match.files())): |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
273 # Spend a bit of time here to get a list of files we know |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
274 # are modified so we can compare only against those. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
275 # It can cost a lot of time (several seconds) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
276 # otherwise to update all standins if the largefiles are |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
277 # large. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
278 lfdirstate = lfutil.openlfdirstate(ui, self) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
279 dirtymatch = match_.always(repo.root, repo.getcwd()) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
280 s = lfdirstate.status(dirtymatch, [], False, False, False) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
281 modifiedfiles = [] |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
282 for i in s: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
283 modifiedfiles.extend(i) |
15168 | 284 lfiles = lfutil.listlfiles(self) |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
285 # this only loops through largefiles that exist (not |
15168 | 286 # removed/renamed) |
287 for lfile in lfiles: | |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
288 if lfile in modifiedfiles: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
289 if os.path.exists(self.wjoin(lfutil.standin(lfile))): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
290 # this handles the case where a rebase is being |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
291 # performed and the working copy is not updated |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
292 # yet. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
293 if os.path.exists(self.wjoin(lfile)): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
294 lfutil.updatestandin(self, |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
295 lfutil.standin(lfile)) |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
296 lfdirstate.normal(lfile) |
15168 | 297 for lfile in lfdirstate: |
15250
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
298 if lfile in modifiedfiles: |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
299 if not os.path.exists( |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
300 repo.wjoin(lfutil.standin(lfile))): |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
301 lfdirstate.drop(lfile) |
15168 | 302 lfdirstate.write() |
303 | |
304 return orig(text=text, user=user, date=date, match=match, | |
305 force=force, editor=editor, extra=extra) | |
306 | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
307 for f in match.files(): |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
308 if lfutil.isstandin(f): |
15168 | 309 raise util.Abort( |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
310 _('file "%s" is a largefile standin') % f, |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
311 hint=('commit the largefile itself instead')) |
15168 | 312 |
313 # Case 2: user calls commit with specified patterns: refresh | |
314 # any matching big files. | |
315 smatcher = lfutil.composestandinmatcher(self, match) | |
316 standins = lfutil.dirstate_walk(self.dirstate, smatcher) | |
317 | |
318 # No matching big files: get out of the way and pass control to | |
319 # the usual commit() method. | |
320 if not standins: | |
321 return orig(text=text, user=user, date=date, match=match, | |
322 force=force, editor=editor, extra=extra) | |
323 | |
324 # Refresh all matching big files. It's possible that the | |
325 # commit will end up failing, in which case the big files will | |
326 # stay refreshed. No harm done: the user modified them and | |
327 # asked to commit them, so sooner or later we're going to | |
328 # refresh the standins. Might as well leave them refreshed. | |
329 lfdirstate = lfutil.openlfdirstate(ui, self) | |
330 for standin in standins: | |
331 lfile = lfutil.splitstandin(standin) | |
332 if lfdirstate[lfile] <> 'r': | |
333 lfutil.updatestandin(self, standin) | |
334 lfdirstate.normal(lfile) | |
335 else: | |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
336 lfdirstate.drop(lfile) |
15168 | 337 lfdirstate.write() |
338 | |
339 # Cook up a new matcher that only matches regular files or | |
340 # standins corresponding to the big files requested by the | |
341 # user. Have to modify _files to prevent commit() from | |
342 # complaining "not tracked" for big files. | |
343 lfiles = lfutil.listlfiles(repo) | |
344 match = copy.copy(match) | |
345 orig_matchfn = match.matchfn | |
346 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
347 # Check both the list of largefiles and the list of |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
348 # standins because if a largefile was removed, it |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
349 # won't be in the list of largefiles at this point |
15168 | 350 match._files += sorted(standins) |
351 | |
352 actualfiles = [] | |
353 for f in match._files: | |
354 fstandin = lfutil.standin(f) | |
355 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
356 # ignore known largefiles and standins |
15168 | 357 if f in lfiles or fstandin in standins: |
358 continue | |
359 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
360 # append directory separator to avoid collisions |
15168 | 361 if not fstandin.endswith(os.sep): |
362 fstandin += os.sep | |
363 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
364 # prevalidate matching standin directories |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
365 if util.any(st for st in match._files |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
366 if st.startswith(fstandin)): |
15168 | 367 continue |
368 actualfiles.append(f) | |
369 match._files = actualfiles | |
370 | |
371 def matchfn(f): | |
372 if orig_matchfn(f): | |
373 return f not in lfiles | |
374 else: | |
375 return f in standins | |
376 | |
377 match.matchfn = matchfn | |
378 return orig(text=text, user=user, date=date, match=match, | |
379 force=force, editor=editor, extra=extra) | |
380 finally: | |
381 wlock.release() | |
382 | |
383 def push(self, remote, force=False, revs=None, newbranch=False): | |
384 o = lfutil.findoutgoing(repo, remote, force) | |
385 if o: | |
386 toupload = set() | |
387 o = repo.changelog.nodesbetween(o, revs)[0] | |
388 for n in o: | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
389 parents = [p for p in repo.changelog.parents(n) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
390 if p != node.nullid] |
15168 | 391 ctx = repo[n] |
392 files = set(ctx.files()) | |
393 if len(parents) == 2: | |
394 mc = ctx.manifest() | |
395 mp1 = ctx.parents()[0].manifest() | |
396 mp2 = ctx.parents()[1].manifest() | |
397 for f in mp1: | |
398 if f not in mc: | |
399 files.add(f) | |
400 for f in mp2: | |
401 if f not in mc: | |
402 files.add(f) | |
403 for f in mc: | |
404 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, | |
405 None): | |
406 files.add(f) | |
407 | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
408 toupload = toupload.union( |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
409 set([ctx[f].data().strip() |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
410 for f in files |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
411 if lfutil.isstandin(f) and f in ctx])) |
15168 | 412 lfcommands.uploadlfiles(ui, self, remote, toupload) |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
413 return super(lfiles_repo, self).push(remote, force, revs, |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15171
diff
changeset
|
414 newbranch) |
15168 | 415 |
416 repo.__class__ = lfiles_repo | |
417 | |
418 def checkrequireslfiles(ui, repo, **kwargs): | |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
419 if 'largefiles' not in repo.requirements and util.any( |
15168 | 420 lfutil.shortname+'/' in f[0] for f in repo.store.datafiles()): |
15312
8d862e7b96d4
largefiles: remove 1.9 compat code
Eli Carter <eli.carter@tektronix.com>
parents:
15305
diff
changeset
|
421 repo.requirements.add('largefiles') |
15168 | 422 repo._writerequirements() |
423 | |
424 ui.setconfig('hooks', 'changegroup.lfiles', checkrequireslfiles) | |
425 ui.setconfig('hooks', 'commit.lfiles', checkrequireslfiles) |