Mercurial > hg-stable
annotate hgext/largefiles/reposetup.py @ 15617:74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
author | Na'Tosha Bard <natosha@unity3d.com> |
---|---|
date | Wed, 07 Dec 2011 12:56:44 +0100 |
parents | 4439ec496378 |
children | 931dc4af0d95 |
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: | |
91 try: | |
92 return super(lfiles_repo, self).status(node1, node2, match, | |
93 listignored, listclean, listunknown, listsubrepos) | |
94 except TypeError: | |
95 return super(lfiles_repo, self).status(node1, node2, match, | |
96 listignored, listclean, listunknown) | |
97 else: | |
98 # some calls in this function rely on the old version of status | |
99 self.lfstatus = False | |
100 if isinstance(node1, context.changectx): | |
101 ctx1 = node1 | |
102 else: | |
103 ctx1 = repo[node1] | |
104 if isinstance(node2, context.changectx): | |
105 ctx2 = node2 | |
106 else: | |
107 ctx2 = repo[node2] | |
108 working = ctx2.rev() is None | |
109 parentworking = working and ctx1 == self['.'] | |
110 | |
111 def inctx(file, ctx): | |
112 try: | |
113 if ctx.rev() is None: | |
114 return file in ctx.manifest() | |
115 ctx[file] | |
116 return True | |
15171
547da6115d1d
largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents:
15170
diff
changeset
|
117 except KeyError: |
15168 | 118 return False |
119 | |
120 if match is None: | |
121 match = match_.always(self.root, self.getcwd()) | |
122 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
123 # 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
|
124 # of largefiles. |
15168 | 125 def tostandin(file): |
126 if inctx(lfutil.standin(file), ctx2): | |
127 return lfutil.standin(file) | |
128 return file | |
129 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
130 # 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
|
131 # 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
|
132 # 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
|
133 # 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
|
134 # 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
|
135 def _ignoreoverride(self): |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
136 return False |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
137 |
15168 | 138 m = copy.copy(match) |
139 m._files = [tostandin(f) for f in m._files] | |
140 | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
141 # 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
|
142 # must use the result here for filtering later |
15168 | 143 try: |
144 result = super(lfiles_repo, self).status(node1, node2, m, | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
145 True, clean, unknown, listsubrepos) |
15168 | 146 except TypeError: |
147 result = super(lfiles_repo, self).status(node1, node2, m, | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
148 True, clean, unknown) |
15168 | 149 if working: |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
150 # hold the wlock while we read largefiles and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
151 # update the lfdirstate |
15168 | 152 wlock = repo.wlock() |
153 try: | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
154 # Any non-largefiles that were explicitly listed must be |
15168 | 155 # taken out or lfdirstate.status will report an error. |
156 # The status of these files was already computed using | |
157 # super's status. | |
158 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
|
159 # 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
|
160 # anything |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
161 orig_ignore = lfdirstate._ignore |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
162 lfdirstate._ignore = _ignoreoverride |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
163 |
15168 | 164 match._files = [f for f in match._files if f in |
165 lfdirstate] | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
166 # 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
|
167 # 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
|
168 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
|
169 listclean, False) |
15168 | 170 (unsure, modified, added, removed, missing, unknown, |
171 ignored, clean) = s | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
172 # 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
|
173 # 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
|
174 # largefiles |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
175 lfiles = set(lfdirstate._map) |
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
176 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
|
177 unknown = set(result[4]).difference(lfiles) |
15168 | 178 if parentworking: |
179 for lfile in unsure: | |
180 if ctx1[lfutil.standin(lfile)].data().strip() \ | |
181 != lfutil.hashfile(self.wjoin(lfile)): | |
182 modified.append(lfile) | |
183 else: | |
184 clean.append(lfile) | |
185 lfdirstate.normal(lfile) | |
186 lfdirstate.write() | |
187 else: | |
188 tocheck = unsure + modified + added + clean | |
189 modified, added, clean = [], [], [] | |
190 | |
191 for lfile in tocheck: | |
192 standin = lfutil.standin(lfile) | |
193 if inctx(standin, ctx1): | |
194 if ctx1[standin].data().strip() != \ | |
195 lfutil.hashfile(self.wjoin(lfile)): | |
196 modified.append(lfile) | |
197 else: | |
198 clean.append(lfile) | |
199 else: | |
200 added.append(lfile) | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
201 # 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
|
202 lfdirstate._ignore = orig_ignore |
15168 | 203 finally: |
204 wlock.release() | |
205 | |
206 for standin in ctx1.manifest(): | |
207 if not lfutil.isstandin(standin): | |
208 continue | |
209 lfile = lfutil.splitstandin(standin) | |
210 if not match(lfile): | |
211 continue | |
212 if lfile not in lfdirstate: | |
213 removed.append(lfile) | |
214 # Handle unknown and ignored differently | |
215 lfiles = (modified, added, removed, missing, [], [], clean) | |
216 result = list(result) | |
217 # Unknown files | |
15617
74e691b141c4
largefiles: optimize performance of status on largefiles repos (issue3136)
Na'Tosha Bard <natosha@unity3d.com>
parents:
15385
diff
changeset
|
218 unknown = set(unknown).difference(ignored) |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
219 result[4] = [f for f in unknown |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
220 if (repo.dirstate[f] == '?' and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
221 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
|
222 # 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
|
223 # 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
|
224 result[5] = ignored |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
225 # combine normal files and largefiles |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
226 normals = [[fn for fn in filelist |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
227 if not lfutil.isstandin(fn)] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
228 for filelist in result] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
229 result = [sorted(list1 + list2) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
230 for (list1, list2) in zip(normals, lfiles)] |
15168 | 231 else: |
232 def toname(f): | |
233 if lfutil.isstandin(f): | |
234 return lfutil.splitstandin(f) | |
235 return f | |
236 result = [[toname(f) for f in items] for items in result] | |
237 | |
238 if not listunknown: | |
239 result[4] = [] | |
240 if not listignored: | |
241 result[5] = [] | |
242 if not listclean: | |
243 result[6] = [] | |
244 self.lfstatus = True | |
245 return result | |
246 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
247 # 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
|
248 # cache. |
15168 | 249 def commitctx(self, *args, **kwargs): |
250 node = super(lfiles_repo, self).commitctx(*args, **kwargs) | |
251 ctx = self[node] | |
252 for filename in ctx.files(): | |
253 if lfutil.isstandin(filename) and filename in ctx.manifest(): | |
254 realfile = lfutil.splitstandin(filename) | |
15316
c65f5b6e26d4
largefiles: rename functions and methods to match desired behavior
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15312
diff
changeset
|
255 lfutil.copytostore(self, ctx.node(), realfile) |
15168 | 256 |
257 return node | |
258 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
259 # 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
|
260 # 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
|
261 # Do that here. |
15168 | 262 def commit(self, text="", user=None, date=None, match=None, |
263 force=False, editor=False, extra={}): | |
264 orig = super(lfiles_repo, self).commit | |
265 | |
266 wlock = repo.wlock() | |
267 try: | |
268 if getattr(repo, "_isrebasing", False): | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
269 # 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
|
270 # largefiles now. Otherwise if we are rebasing, |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
271 # any largefiles that were modified in the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
272 # destination changesets get overwritten, either |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
273 # 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
|
274 # rebase. |
15168 | 275 lfcommands.updatelfiles(repo.ui, repo) |
276 # 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
|
277 # 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
|
278 # are "dirty". |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
279 if ((match is None) or |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
280 (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
|
281 # 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
|
282 # 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
|
283 # 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
|
284 # 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
|
285 # large. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 modifiedfiles = [] |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
290 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
|
291 modifiedfiles.extend(i) |
15168 | 292 lfiles = lfutil.listlfiles(self) |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
293 # this only loops through largefiles that exist (not |
15168 | 294 # removed/renamed) |
295 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
|
296 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
|
297 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
|
298 # 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
|
299 # 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
|
300 # yet. |
f172292cd416
largefiles: speed up commit by only rewriting standins for modified largefiles
Na'Tosha Bard <natosha@unity3d.com>
parents:
15224
diff
changeset
|
301 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
|
302 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
|
303 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
|
304 lfdirstate.normal(lfile) |
15168 | 305 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
|
306 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
|
307 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
|
308 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
|
309 lfdirstate.drop(lfile) |
15168 | 310 lfdirstate.write() |
311 | |
312 return orig(text=text, user=user, date=date, match=match, | |
313 force=force, editor=editor, extra=extra) | |
314 | |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
315 for f in match.files(): |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
316 if lfutil.isstandin(f): |
15168 | 317 raise util.Abort( |
15253
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
318 _('file "%s" is a largefile standin') % f, |
67d010779907
largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
319 hint=('commit the largefile itself instead')) |
15168 | 320 |
321 # Case 2: user calls commit with specified patterns: refresh | |
322 # any matching big files. | |
323 smatcher = lfutil.composestandinmatcher(self, match) | |
324 standins = lfutil.dirstate_walk(self.dirstate, smatcher) | |
325 | |
326 # No matching big files: get out of the way and pass control to | |
327 # the usual commit() method. | |
328 if not standins: | |
329 return orig(text=text, user=user, date=date, match=match, | |
330 force=force, editor=editor, extra=extra) | |
331 | |
332 # Refresh all matching big files. It's possible that the | |
333 # commit will end up failing, in which case the big files will | |
334 # stay refreshed. No harm done: the user modified them and | |
335 # asked to commit them, so sooner or later we're going to | |
336 # refresh the standins. Might as well leave them refreshed. | |
337 lfdirstate = lfutil.openlfdirstate(ui, self) | |
338 for standin in standins: | |
339 lfile = lfutil.splitstandin(standin) | |
340 if lfdirstate[lfile] <> 'r': | |
341 lfutil.updatestandin(self, standin) | |
342 lfdirstate.normal(lfile) | |
343 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
|
344 lfdirstate.drop(lfile) |
15168 | 345 lfdirstate.write() |
346 | |
347 # Cook up a new matcher that only matches regular files or | |
348 # standins corresponding to the big files requested by the | |
349 # user. Have to modify _files to prevent commit() from | |
350 # complaining "not tracked" for big files. | |
351 lfiles = lfutil.listlfiles(repo) | |
352 match = copy.copy(match) | |
353 orig_matchfn = match.matchfn | |
354 | |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15253
diff
changeset
|
355 # 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
|
356 # 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
|
357 # won't be in the list of largefiles at this point |
15168 | 358 match._files += sorted(standins) |
359 | |
360 actualfiles = [] | |
361 for f in match._files: | |
362 fstandin = lfutil.standin(f) | |
363 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
364 # ignore known largefiles and standins |
15168 | 365 if f in lfiles or fstandin in standins: |
366 continue | |
367 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
368 # append directory separator to avoid collisions |
15168 | 369 if not fstandin.endswith(os.sep): |
370 fstandin += os.sep | |
371 | |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15250
diff
changeset
|
372 # prevalidate matching standin directories |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
373 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
|
374 if st.startswith(fstandin)): |
15168 | 375 continue |
376 actualfiles.append(f) | |
377 match._files = actualfiles | |
378 | |
379 def matchfn(f): | |
380 if orig_matchfn(f): | |
381 return f not in lfiles | |
382 else: | |
383 return f in standins | |
384 | |
385 match.matchfn = matchfn | |
386 return orig(text=text, user=user, date=date, match=match, | |
387 force=force, editor=editor, extra=extra) | |
388 finally: | |
389 wlock.release() | |
390 | |
391 def push(self, remote, force=False, revs=None, newbranch=False): | |
392 o = lfutil.findoutgoing(repo, remote, force) | |
393 if o: | |
394 toupload = set() | |
395 o = repo.changelog.nodesbetween(o, revs)[0] | |
396 for n in o: | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
397 parents = [p for p in repo.changelog.parents(n) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
398 if p != node.nullid] |
15168 | 399 ctx = repo[n] |
400 files = set(ctx.files()) | |
401 if len(parents) == 2: | |
402 mc = ctx.manifest() | |
403 mp1 = ctx.parents()[0].manifest() | |
404 mp2 = ctx.parents()[1].manifest() | |
405 for f in mp1: | |
406 if f not in mc: | |
407 files.add(f) | |
408 for f in mp2: | |
409 if f not in mc: | |
410 files.add(f) | |
411 for f in mc: | |
412 if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, | |
413 None): | |
414 files.add(f) | |
415 | |
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
416 toupload = toupload.union( |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
417 set([ctx[f].data().strip() |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
418 for f in files |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
419 if lfutil.isstandin(f) and f in ctx])) |
15168 | 420 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
|
421 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
|
422 newbranch) |
15168 | 423 |
424 repo.__class__ = lfiles_repo | |
425 | |
426 def checkrequireslfiles(ui, repo, **kwargs): | |
15319
9da7e96cd5c2
largefiles: remove redundant any_ function
Benjamin Pollack <benjamin@bitquabit.com>
parents:
15316
diff
changeset
|
427 if 'largefiles' not in repo.requirements and util.any( |
15168 | 428 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
|
429 repo.requirements.add('largefiles') |
15168 | 430 repo._writerequirements() |
431 | |
432 ui.setconfig('hooks', 'changegroup.lfiles', checkrequireslfiles) | |
433 ui.setconfig('hooks', 'commit.lfiles', checkrequireslfiles) |