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