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