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