author | Thomas Arendsen Hein <thomas@intevation.de> |
Sun, 16 Oct 2011 11:28:03 +0200 | |
branch | stable |
changeset 15279 | 018608160299 |
parent 15255 | 7ab05d752405 |
child 15294 | db7b09e689f1 |
permissions | -rw-r--r-- |
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 |
'''Overridden Mercurial commands and functions for the largefiles extension''' |
|
10 |
||
11 |
import os |
|
12 |
import copy |
|
13 |
||
14 |
from mercurial import hg, commands, util, cmdutil, match as match_, node, \ |
|
15 |
archival, error, merge |
|
16 |
from mercurial.i18n import _ |
|
17 |
from mercurial.node import hex |
|
18 |
from hgext import rebase |
|
15227
a7686abf73a6
largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents:
15224
diff
changeset
|
19 |
import lfutil |
15168 | 20 |
|
21 |
try: |
|
22 |
from mercurial import scmutil |
|
23 |
except ImportError: |
|
24 |
pass |
|
25 |
||
26 |
import lfutil |
|
27 |
import lfcommands |
|
28 |
||
29 |
def installnormalfilesmatchfn(manifest): |
|
30 |
'''overrides scmutil.match so that the matcher it returns will ignore all |
|
31 |
largefiles''' |
|
32 |
oldmatch = None # for the closure |
|
33 |
def override_match(repo, pats=[], opts={}, globbed=False, |
|
34 |
default='relpath'): |
|
35 |
match = oldmatch(repo, pats, opts, globbed, default) |
|
36 |
m = copy.copy(match) |
|
37 |
notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in |
|
38 |
manifest) |
|
39 |
m._files = filter(notlfile, m._files) |
|
40 |
m._fmap = set(m._files) |
|
41 |
orig_matchfn = m.matchfn |
|
42 |
m.matchfn = lambda f: notlfile(f) and orig_matchfn(f) or None |
|
43 |
return m |
|
44 |
oldmatch = installmatchfn(override_match) |
|
45 |
||
46 |
def installmatchfn(f): |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
47 |
oldmatch = scmutil.match |
15168 | 48 |
setattr(f, 'oldmatch', oldmatch) |
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
49 |
scmutil.match = f |
15168 | 50 |
return oldmatch |
51 |
||
52 |
def restorematchfn(): |
|
53 |
'''restores scmutil.match to what it was before installnormalfilesmatchfn |
|
54 |
was called. no-op if scmutil.match is its original function. |
|
55 |
||
56 |
Note that n calls to installnormalfilesmatchfn will require n calls to |
|
57 |
restore matchfn to reverse''' |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
58 |
scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match) |
15168 | 59 |
|
60 |
# -- Wrappers: modify existing commands -------------------------------- |
|
61 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
62 |
# Add works by going through the files that the user wanted to add and |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
63 |
# checking if they should be added as largefiles. Then it makes a new |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
64 |
# matcher which matches only the normal files and runs the original |
15168 | 65 |
# version of add. |
66 |
def override_add(orig, ui, repo, *pats, **opts): |
|
67 |
large = opts.pop('large', None) |
|
15227
a7686abf73a6
largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents:
15224
diff
changeset
|
68 |
lfsize = lfutil.getminsize( |
a7686abf73a6
largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents:
15224
diff
changeset
|
69 |
ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None)) |
15168 | 70 |
|
71 |
lfmatcher = None |
|
72 |
if os.path.exists(repo.wjoin(lfutil.shortname)): |
|
15229
89e19ca2a90e
largefiles: use ui.configlist() to split largefiles.patterns
Greg Ward <greg@gerg.ca>
parents:
15227
diff
changeset
|
73 |
lfpats = ui.configlist(lfutil.longname, 'patterns', default=[]) |
15168 | 74 |
if lfpats: |
75 |
lfmatcher = match_.match(repo.root, '', list(lfpats)) |
|
76 |
||
77 |
lfnames = [] |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
78 |
m = scmutil.match(repo[None], pats, opts) |
15168 | 79 |
m.bad = lambda x, y: None |
80 |
wctx = repo[None] |
|
81 |
for f in repo.walk(m): |
|
82 |
exact = m.exact(f) |
|
83 |
lfile = lfutil.standin(f) in wctx |
|
84 |
nfile = f in wctx |
|
85 |
exists = lfile or nfile |
|
86 |
||
87 |
# Don't warn the user when they attempt to add a normal tracked file. |
|
88 |
# The normal add code will do that for us. |
|
89 |
if exact and exists: |
|
90 |
if lfile: |
|
91 |
ui.warn(_('%s already a largefile\n') % f) |
|
92 |
continue |
|
93 |
||
94 |
if exact or not exists: |
|
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
95 |
abovemin = (lfsize and |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
96 |
os.path.getsize(repo.wjoin(f)) >= lfsize * 1024 * 1024) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
97 |
if large or abovemin or (lfmatcher and lfmatcher(f)): |
15168 | 98 |
lfnames.append(f) |
99 |
if ui.verbose or not exact: |
|
100 |
ui.status(_('adding %s as a largefile\n') % m.rel(f)) |
|
101 |
||
102 |
bad = [] |
|
103 |
standins = [] |
|
104 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
105 |
# Need to lock, otherwise there could be a race condition between |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
106 |
# when standins are created and added to the repo. |
15168 | 107 |
wlock = repo.wlock() |
108 |
try: |
|
109 |
if not opts.get('dry_run'): |
|
110 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
111 |
for f in lfnames: |
|
112 |
standinname = lfutil.standin(f) |
|
113 |
lfutil.writestandin(repo, standinname, hash='', |
|
114 |
executable=lfutil.getexecutable(repo.wjoin(f))) |
|
115 |
standins.append(standinname) |
|
116 |
if lfdirstate[f] == 'r': |
|
117 |
lfdirstate.normallookup(f) |
|
118 |
else: |
|
119 |
lfdirstate.add(f) |
|
120 |
lfdirstate.write() |
|
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
121 |
bad += [lfutil.splitstandin(f) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
122 |
for f in lfutil.repo_add(repo, standins) |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
123 |
if f in m.files()] |
15168 | 124 |
finally: |
125 |
wlock.release() |
|
126 |
||
127 |
installnormalfilesmatchfn(repo[None].manifest()) |
|
128 |
result = orig(ui, repo, *pats, **opts) |
|
129 |
restorematchfn() |
|
130 |
||
131 |
return (result == 1 or bad) and 1 or 0 |
|
132 |
||
133 |
def override_remove(orig, ui, repo, *pats, **opts): |
|
134 |
manifest = repo[None].manifest() |
|
135 |
installnormalfilesmatchfn(manifest) |
|
136 |
orig(ui, repo, *pats, **opts) |
|
137 |
restorematchfn() |
|
138 |
||
139 |
after, force = opts.get('after'), opts.get('force') |
|
140 |
if not pats and not after: |
|
141 |
raise util.Abort(_('no files specified')) |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
142 |
m = scmutil.match(repo[None], pats, opts) |
15168 | 143 |
try: |
144 |
repo.lfstatus = True |
|
145 |
s = repo.status(match=m, clean=True) |
|
146 |
finally: |
|
147 |
repo.lfstatus = False |
|
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
148 |
modified, added, deleted, clean = [[f for f in list |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
149 |
if lfutil.standin(f) in manifest] |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
150 |
for list in [s[0], s[1], s[3], s[6]]] |
15168 | 151 |
|
152 |
def warn(files, reason): |
|
153 |
for f in files: |
|
154 |
ui.warn(_('not removing %s: file %s (use -f to force removal)\n') |
|
155 |
% (m.rel(f), reason)) |
|
156 |
||
157 |
if force: |
|
158 |
remove, forget = modified + deleted + clean, added |
|
159 |
elif after: |
|
160 |
remove, forget = deleted, [] |
|
161 |
warn(modified + added + clean, _('still exists')) |
|
162 |
else: |
|
163 |
remove, forget = deleted + clean, [] |
|
164 |
warn(modified, _('is modified')) |
|
165 |
warn(added, _('has been marked for add')) |
|
166 |
||
167 |
for f in sorted(remove + forget): |
|
168 |
if ui.verbose or not m.exact(f): |
|
169 |
ui.status(_('removing %s\n') % m.rel(f)) |
|
170 |
||
171 |
# Need to lock because standin files are deleted then removed from the |
|
172 |
# repository and we could race inbetween. |
|
173 |
wlock = repo.wlock() |
|
174 |
try: |
|
175 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
176 |
for f in remove: |
|
177 |
if not after: |
|
178 |
os.unlink(repo.wjoin(f)) |
|
179 |
currentdir = os.path.split(f)[0] |
|
180 |
while currentdir and not os.listdir(repo.wjoin(currentdir)): |
|
181 |
os.rmdir(repo.wjoin(currentdir)) |
|
182 |
currentdir = os.path.split(currentdir)[0] |
|
183 |
lfdirstate.remove(f) |
|
184 |
lfdirstate.write() |
|
185 |
||
186 |
forget = [lfutil.standin(f) for f in forget] |
|
187 |
remove = [lfutil.standin(f) for f in remove] |
|
188 |
lfutil.repo_forget(repo, forget) |
|
189 |
lfutil.repo_remove(repo, remove, unlink=True) |
|
190 |
finally: |
|
191 |
wlock.release() |
|
192 |
||
193 |
def override_status(orig, ui, repo, *pats, **opts): |
|
194 |
try: |
|
195 |
repo.lfstatus = True |
|
196 |
return orig(ui, repo, *pats, **opts) |
|
197 |
finally: |
|
198 |
repo.lfstatus = False |
|
199 |
||
200 |
def override_log(orig, ui, repo, *pats, **opts): |
|
201 |
try: |
|
202 |
repo.lfstatus = True |
|
203 |
orig(ui, repo, *pats, **opts) |
|
204 |
finally: |
|
205 |
repo.lfstatus = False |
|
206 |
||
207 |
def override_verify(orig, ui, repo, *pats, **opts): |
|
208 |
large = opts.pop('large', False) |
|
209 |
all = opts.pop('lfa', False) |
|
210 |
contents = opts.pop('lfc', False) |
|
211 |
||
212 |
result = orig(ui, repo, *pats, **opts) |
|
213 |
if large: |
|
214 |
result = result or lfcommands.verifylfiles(ui, repo, all, contents) |
|
215 |
return result |
|
216 |
||
217 |
# Override needs to refresh standins so that update's normal merge |
|
218 |
# will go through properly. Then the other update hook (overriding repo.update) |
|
219 |
# will get the new files. Filemerge is also overriden so that the merge |
|
220 |
# will merge standins correctly. |
|
221 |
def override_update(orig, ui, repo, *pats, **opts): |
|
222 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
223 |
s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, |
|
224 |
False, False) |
|
225 |
(unsure, modified, added, removed, missing, unknown, ignored, clean) = s |
|
226 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
227 |
# Need to lock between the standins getting updated and their |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
228 |
# largefiles getting updated |
15168 | 229 |
wlock = repo.wlock() |
230 |
try: |
|
231 |
if opts['check']: |
|
232 |
mod = len(modified) > 0 |
|
233 |
for lfile in unsure: |
|
234 |
standin = lfutil.standin(lfile) |
|
235 |
if repo['.'][standin].data().strip() != \ |
|
236 |
lfutil.hashfile(repo.wjoin(lfile)): |
|
237 |
mod = True |
|
238 |
else: |
|
239 |
lfdirstate.normal(lfile) |
|
240 |
lfdirstate.write() |
|
241 |
if mod: |
|
242 |
raise util.Abort(_('uncommitted local changes')) |
|
243 |
# XXX handle removed differently |
|
244 |
if not opts['clean']: |
|
245 |
for lfile in unsure + modified + added: |
|
246 |
lfutil.updatestandin(repo, lfutil.standin(lfile)) |
|
247 |
finally: |
|
248 |
wlock.release() |
|
249 |
return orig(ui, repo, *pats, **opts) |
|
250 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
251 |
# Override filemerge to prompt the user about how they wish to merge |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
252 |
# largefiles. This will handle identical edits, and copy/rename + |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
253 |
# edit without prompting the user. |
15168 | 254 |
def override_filemerge(origfn, repo, mynode, orig, fcd, fco, fca): |
255 |
# Use better variable names here. Because this is a wrapper we cannot |
|
256 |
# change the variable names in the function declaration. |
|
257 |
fcdest, fcother, fcancestor = fcd, fco, fca |
|
258 |
if not lfutil.isstandin(orig): |
|
259 |
return origfn(repo, mynode, orig, fcdest, fcother, fcancestor) |
|
260 |
else: |
|
261 |
if not fcother.cmp(fcdest): # files identical? |
|
262 |
return None |
|
263 |
||
264 |
# backwards, use working dir parent as ancestor |
|
265 |
if fcancestor == fcother: |
|
266 |
fcancestor = fcdest.parents()[0] |
|
267 |
||
268 |
if orig != fcother.path(): |
|
269 |
repo.ui.status(_('merging %s and %s to %s\n') |
|
270 |
% (lfutil.splitstandin(orig), |
|
271 |
lfutil.splitstandin(fcother.path()), |
|
272 |
lfutil.splitstandin(fcdest.path()))) |
|
273 |
else: |
|
274 |
repo.ui.status(_('merging %s\n') |
|
275 |
% lfutil.splitstandin(fcdest.path())) |
|
276 |
||
277 |
if fcancestor.path() != fcother.path() and fcother.data() == \ |
|
278 |
fcancestor.data(): |
|
279 |
return 0 |
|
280 |
if fcancestor.path() != fcdest.path() and fcdest.data() == \ |
|
281 |
fcancestor.data(): |
|
282 |
repo.wwrite(fcdest.path(), fcother.data(), fcother.flags()) |
|
283 |
return 0 |
|
284 |
||
285 |
if repo.ui.promptchoice(_('largefile %s has a merge conflict\n' |
|
286 |
'keep (l)ocal or take (o)ther?') % |
|
287 |
lfutil.splitstandin(orig), |
|
288 |
(_('&Local'), _('&Other')), 0) == 0: |
|
289 |
return 0 |
|
290 |
else: |
|
291 |
repo.wwrite(fcdest.path(), fcother.data(), fcother.flags()) |
|
292 |
return 0 |
|
293 |
||
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
294 |
# Copy first changes the matchers to match standins instead of |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
295 |
# largefiles. Then it overrides util.copyfile in that function it |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
296 |
# checks if the destination largefile already exists. It also keeps a |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
297 |
# list of copied files so that the largefiles can be copied and the |
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
298 |
# dirstate updated. |
15168 | 299 |
def override_copy(orig, ui, repo, pats, opts, rename=False): |
15252
6e809bb4f969
largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents:
15229
diff
changeset
|
300 |
# doesn't remove largefile on rename |
15168 | 301 |
if len(pats) < 2: |
302 |
# this isn't legal, let the original function deal with it |
|
303 |
return orig(ui, repo, pats, opts, rename) |
|
304 |
||
305 |
def makestandin(relpath): |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
306 |
path = scmutil.canonpath(repo.root, repo.getcwd(), relpath) |
15168 | 307 |
return os.path.join(os.path.relpath('.', repo.getcwd()), |
308 |
lfutil.standin(path)) |
|
309 |
||
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
310 |
fullpats = scmutil.expandpats(pats) |
15168 | 311 |
dest = fullpats[-1] |
312 |
||
313 |
if os.path.isdir(dest): |
|
314 |
if not os.path.isdir(makestandin(dest)): |
|
315 |
os.makedirs(makestandin(dest)) |
|
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
316 |
# This could copy both lfiles and normal files in one command, |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
317 |
# but we don't want to do that. First replace their matcher to |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
318 |
# only match normal files and run it, then replace it to just |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
319 |
# match largefiles and run it again. |
15168 | 320 |
nonormalfiles = False |
321 |
nolfiles = False |
|
322 |
try: |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
323 |
try: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
324 |
installnormalfilesmatchfn(repo[None].manifest()) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
325 |
result = orig(ui, repo, pats, opts, rename) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
326 |
except util.Abort, e: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
327 |
if str(e) != 'no files to copy': |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
328 |
raise e |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
329 |
else: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
330 |
nonormalfiles = True |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
331 |
result = 0 |
15168 | 332 |
finally: |
333 |
restorematchfn() |
|
334 |
||
335 |
# The first rename can cause our current working directory to be removed. |
|
336 |
# In that case there is nothing left to copy/rename so just quit. |
|
337 |
try: |
|
338 |
repo.getcwd() |
|
339 |
except OSError: |
|
340 |
return result |
|
341 |
||
342 |
try: |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
343 |
try: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
344 |
# When we call orig below it creates the standins but we don't add them |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
345 |
# to the dir state until later so lock during that time. |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
346 |
wlock = repo.wlock() |
15168 | 347 |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
348 |
manifest = repo[None].manifest() |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
349 |
oldmatch = None # for the closure |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
350 |
def override_match(repo, pats=[], opts={}, globbed=False, |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
351 |
default='relpath'): |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
352 |
newpats = [] |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
353 |
# The patterns were previously mangled to add the standin |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
354 |
# directory; we need to remove that now |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
355 |
for pat in pats: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
356 |
if match_.patkind(pat) is None and lfutil.shortname in pat: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
357 |
newpats.append(pat.replace(lfutil.shortname, '')) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
358 |
else: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
359 |
newpats.append(pat) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
360 |
match = oldmatch(repo, newpats, opts, globbed, default) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
361 |
m = copy.copy(match) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
362 |
lfile = lambda f: lfutil.standin(f) in manifest |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
363 |
m._files = [lfutil.standin(f) for f in m._files if lfile(f)] |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
364 |
m._fmap = set(m._files) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
365 |
orig_matchfn = m.matchfn |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
366 |
m.matchfn = lambda f: (lfutil.isstandin(f) and |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
367 |
lfile(lfutil.splitstandin(f)) and |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
368 |
orig_matchfn(lfutil.splitstandin(f)) or |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
369 |
None) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
370 |
return m |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
371 |
oldmatch = installmatchfn(override_match) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
372 |
listpats = [] |
15168 | 373 |
for pat in pats: |
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
374 |
if match_.patkind(pat) is not None: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
375 |
listpats.append(pat) |
15168 | 376 |
else: |
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
377 |
listpats.append(makestandin(pat)) |
15168 | 378 |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
379 |
try: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
380 |
origcopyfile = util.copyfile |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
381 |
copiedfiles = [] |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
382 |
def override_copyfile(src, dest): |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
383 |
if lfutil.shortname in src and lfutil.shortname in dest: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
384 |
destlfile = dest.replace(lfutil.shortname, '') |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
385 |
if not opts['force'] and os.path.exists(destlfile): |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
386 |
raise IOError('', |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
387 |
_('destination largefile already exists')) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
388 |
copiedfiles.append((src, dest)) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
389 |
origcopyfile(src, dest) |
15168 | 390 |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
391 |
util.copyfile = override_copyfile |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
392 |
result += orig(ui, repo, listpats, opts, rename) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
393 |
finally: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
394 |
util.copyfile = origcopyfile |
15168 | 395 |
|
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
396 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
397 |
for (src, dest) in copiedfiles: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
398 |
if lfutil.shortname in src and lfutil.shortname in dest: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
399 |
srclfile = src.replace(lfutil.shortname, '') |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
400 |
destlfile = dest.replace(lfutil.shortname, '') |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
401 |
destlfiledir = os.path.dirname(destlfile) or '.' |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
402 |
if not os.path.isdir(destlfiledir): |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
403 |
os.makedirs(destlfiledir) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
404 |
if rename: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
405 |
os.rename(srclfile, destlfile) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
406 |
lfdirstate.remove(os.path.relpath(srclfile, |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
407 |
repo.root)) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
408 |
else: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
409 |
util.copyfile(srclfile, destlfile) |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
410 |
lfdirstate.add(os.path.relpath(destlfile, |
15168 | 411 |
repo.root)) |
15279
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
412 |
lfdirstate.write() |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
413 |
except util.Abort, e: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
414 |
if str(e) != 'no files to copy': |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
415 |
raise e |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
416 |
else: |
018608160299
largefiles: use separate try/except and try/finally as needed for python2.4
Thomas Arendsen Hein <thomas@intevation.de>
parents:
15255
diff
changeset
|
417 |
nolfiles = True |
15168 | 418 |
finally: |
419 |
restorematchfn() |
|
420 |
wlock.release() |
|
421 |
||
422 |
if nolfiles and nonormalfiles: |
|
423 |
raise util.Abort(_('no files to copy')) |
|
424 |
||
425 |
return result |
|
426 |
||
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
427 |
# When the user calls revert, we have to be careful to not revert any |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
428 |
# changes to other largefiles accidentally. This means we have to keep |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
429 |
# track of the largefiles that are being reverted so we only pull down |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
430 |
# the necessary largefiles. |
15168 | 431 |
# |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
432 |
# Standins are only updated (to match the hash of largefiles) before |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
433 |
# commits. Update the standins then run the original revert, changing |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
434 |
# the matcher to hit standins instead of largefiles. Based on the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
435 |
# resulting standins update the largefiles. Then return the standins |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
436 |
# to their proper state |
15168 | 437 |
def override_revert(orig, ui, repo, *pats, **opts): |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
438 |
# Because we put the standins in a bad state (by updating them) |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
439 |
# and then return them to a correct state we need to lock to |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
440 |
# prevent others from changing them in their incorrect state. |
15168 | 441 |
wlock = repo.wlock() |
442 |
try: |
|
443 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
444 |
(modified, added, removed, missing, unknown, ignored, clean) = \ |
|
445 |
lfutil.lfdirstate_status(lfdirstate, repo, repo['.'].rev()) |
|
446 |
for lfile in modified: |
|
447 |
lfutil.updatestandin(repo, lfutil.standin(lfile)) |
|
448 |
||
449 |
try: |
|
450 |
ctx = repo[opts.get('rev')] |
|
451 |
oldmatch = None # for the closure |
|
452 |
def override_match(ctxorrepo, pats=[], opts={}, globbed=False, |
|
453 |
default='relpath'): |
|
15169
aa262fff87ac
largefile: fix up hasattr usage
Matt Mackall <mpm@selenic.com>
parents:
15168
diff
changeset
|
454 |
if util.safehasattr(ctxorrepo, 'match'): |
15168 | 455 |
ctx0 = ctxorrepo |
456 |
else: |
|
457 |
ctx0 = ctxorrepo[None] |
|
458 |
match = oldmatch(ctxorrepo, pats, opts, globbed, default) |
|
459 |
m = copy.copy(match) |
|
460 |
def tostandin(f): |
|
461 |
if lfutil.standin(f) in ctx0 or lfutil.standin(f) in ctx: |
|
462 |
return lfutil.standin(f) |
|
463 |
elif lfutil.standin(f) in repo[None]: |
|
464 |
return None |
|
465 |
return f |
|
466 |
m._files = [tostandin(f) for f in m._files] |
|
467 |
m._files = [f for f in m._files if f is not None] |
|
468 |
m._fmap = set(m._files) |
|
469 |
orig_matchfn = m.matchfn |
|
470 |
def matchfn(f): |
|
471 |
if lfutil.isstandin(f): |
|
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
472 |
# We need to keep track of what largefiles are being |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
473 |
# matched so we know which ones to update later -- |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
474 |
# otherwise we accidentally revert changes to other |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
475 |
# largefiles. This is repo-specific, so duckpunch the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
476 |
# repo object to keep the list of largefiles for us |
15168 | 477 |
# later. |
478 |
if orig_matchfn(lfutil.splitstandin(f)) and \ |
|
479 |
(f in repo[None] or f in ctx): |
|
480 |
lfileslist = getattr(repo, '_lfilestoupdate', []) |
|
481 |
lfileslist.append(lfutil.splitstandin(f)) |
|
482 |
repo._lfilestoupdate = lfileslist |
|
483 |
return True |
|
484 |
else: |
|
485 |
return False |
|
486 |
return orig_matchfn(f) |
|
487 |
m.matchfn = matchfn |
|
488 |
return m |
|
489 |
oldmatch = installmatchfn(override_match) |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
490 |
scmutil.match |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
491 |
matches = override_match(repo[None], pats, opts) |
15168 | 492 |
orig(ui, repo, *pats, **opts) |
493 |
finally: |
|
494 |
restorematchfn() |
|
495 |
lfileslist = getattr(repo, '_lfilestoupdate', []) |
|
15170
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15169
diff
changeset
|
496 |
lfcommands.updatelfiles(ui, repo, filelist=lfileslist, |
c1a4a3220711
largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents:
15169
diff
changeset
|
497 |
printmessage=False) |
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
498 |
|
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
499 |
# empty out the largefiles list so we start fresh next time |
15168 | 500 |
repo._lfilestoupdate = [] |
501 |
for lfile in modified: |
|
502 |
if lfile in lfileslist: |
|
503 |
if os.path.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\ |
|
504 |
in repo['.']: |
|
505 |
lfutil.writestandin(repo, lfutil.standin(lfile), |
|
506 |
repo['.'][lfile].data().strip(), |
|
507 |
'x' in repo['.'][lfile].flags()) |
|
508 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
509 |
for lfile in added: |
|
510 |
standin = lfutil.standin(lfile) |
|
511 |
if standin not in ctx and (standin in matches or opts.get('all')): |
|
512 |
if lfile in lfdirstate: |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
513 |
lfdirstate.drop(lfile) |
15168 | 514 |
util.unlinkpath(repo.wjoin(standin)) |
515 |
lfdirstate.write() |
|
516 |
finally: |
|
517 |
wlock.release() |
|
518 |
||
519 |
def hg_update(orig, repo, node): |
|
520 |
result = orig(repo, node) |
|
521 |
# XXX check if it worked first |
|
522 |
lfcommands.updatelfiles(repo.ui, repo) |
|
523 |
return result |
|
524 |
||
525 |
def hg_clean(orig, repo, node, show_stats=True): |
|
526 |
result = orig(repo, node, show_stats) |
|
527 |
lfcommands.updatelfiles(repo.ui, repo) |
|
528 |
return result |
|
529 |
||
530 |
def hg_merge(orig, repo, node, force=None, remind=True): |
|
531 |
result = orig(repo, node, force, remind) |
|
532 |
lfcommands.updatelfiles(repo.ui, repo) |
|
533 |
return result |
|
534 |
||
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
535 |
# When we rebase a repository with remotely changed largefiles, we need to |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
536 |
# take some extra care so that the largefiles are correctly updated in the |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
537 |
# working copy |
15168 | 538 |
def override_pull(orig, ui, repo, source=None, **opts): |
539 |
if opts.get('rebase', False): |
|
540 |
repo._isrebasing = True |
|
541 |
try: |
|
542 |
if opts.get('update'): |
|
543 |
del opts['update'] |
|
544 |
ui.debug('--update and --rebase are not compatible, ignoring ' |
|
545 |
'the update flag\n') |
|
546 |
del opts['rebase'] |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
547 |
cmdutil.bailifchanged(repo) |
15168 | 548 |
revsprepull = len(repo) |
549 |
origpostincoming = commands.postincoming |
|
550 |
def _dummy(*args, **kwargs): |
|
551 |
pass |
|
552 |
commands.postincoming = _dummy |
|
553 |
repo.lfpullsource = source |
|
554 |
if not source: |
|
555 |
source = 'default' |
|
556 |
try: |
|
557 |
result = commands.pull(ui, repo, source, **opts) |
|
558 |
finally: |
|
559 |
commands.postincoming = origpostincoming |
|
560 |
revspostpull = len(repo) |
|
561 |
if revspostpull > revsprepull: |
|
562 |
result = result or rebase.rebase(ui, repo) |
|
563 |
finally: |
|
564 |
repo._isrebasing = False |
|
565 |
else: |
|
566 |
repo.lfpullsource = source |
|
567 |
if not source: |
|
568 |
source = 'default' |
|
569 |
result = orig(ui, repo, source, **opts) |
|
570 |
return result |
|
571 |
||
572 |
def override_rebase(orig, ui, repo, **opts): |
|
573 |
repo._isrebasing = True |
|
574 |
try: |
|
575 |
orig(ui, repo, **opts) |
|
576 |
finally: |
|
577 |
repo._isrebasing = False |
|
578 |
||
579 |
def override_archive(orig, repo, dest, node, kind, decode=True, matchfn=None, |
|
580 |
prefix=None, mtime=None, subrepos=None): |
|
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
581 |
# No need to lock because we are only reading history and |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
582 |
# largefile caches, neither of which are modified. |
15168 | 583 |
lfcommands.cachelfiles(repo.ui, repo, node) |
584 |
||
585 |
if kind not in archival.archivers: |
|
586 |
raise util.Abort(_("unknown archive type '%s'") % kind) |
|
587 |
||
588 |
ctx = repo[node] |
|
589 |
||
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
590 |
if kind == 'files': |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
591 |
if prefix: |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
592 |
raise util.Abort( |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
593 |
_('cannot give prefix when archiving to files')) |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
594 |
else: |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
595 |
prefix = archival.tidyprefix(dest, kind, prefix) |
15168 | 596 |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
597 |
def write(name, mode, islink, getdata): |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
598 |
if matchfn and not matchfn(name): |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
599 |
return |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
600 |
data = getdata() |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
601 |
if decode: |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
602 |
data = repo.wwritedata(name, data) |
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
603 |
archiver.addfile(prefix + name, mode, islink, data) |
15168 | 604 |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
605 |
archiver = archival.archivers[kind](dest, mtime or ctx.date()[0]) |
15168 | 606 |
|
607 |
if repo.ui.configbool("ui", "archivemeta", True): |
|
608 |
def metadata(): |
|
609 |
base = 'repo: %s\nnode: %s\nbranch: %s\n' % ( |
|
610 |
hex(repo.changelog.node(0)), hex(node), ctx.branch()) |
|
611 |
||
612 |
tags = ''.join('tag: %s\n' % t for t in ctx.tags() |
|
613 |
if repo.tagtype(t) == 'global') |
|
614 |
if not tags: |
|
615 |
repo.ui.pushbuffer() |
|
616 |
opts = {'template': '{latesttag}\n{latesttagdistance}', |
|
617 |
'style': '', 'patch': None, 'git': None} |
|
618 |
cmdutil.show_changeset(repo.ui, repo, opts).show(ctx) |
|
619 |
ltags, dist = repo.ui.popbuffer().split('\n') |
|
620 |
tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':')) |
|
621 |
tags += 'latesttagdistance: %s\n' % dist |
|
622 |
||
623 |
return base + tags |
|
624 |
||
625 |
write('.hg_archival.txt', 0644, False, metadata) |
|
626 |
||
627 |
for f in ctx: |
|
628 |
ff = ctx.flags(f) |
|
629 |
getdata = ctx[f].data |
|
630 |
if lfutil.isstandin(f): |
|
631 |
path = lfutil.findfile(repo, getdata().strip()) |
|
632 |
f = lfutil.splitstandin(f) |
|
633 |
||
634 |
def getdatafn(): |
|
635 |
try: |
|
636 |
fd = open(path, 'rb') |
|
637 |
return fd.read() |
|
638 |
finally: |
|
639 |
fd.close() |
|
640 |
||
641 |
getdata = getdatafn |
|
642 |
write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata) |
|
643 |
||
644 |
if subrepos: |
|
645 |
for subpath in ctx.substate: |
|
646 |
sub = ctx.sub(subpath) |
|
647 |
try: |
|
648 |
sub.archive(repo.ui, archiver, prefix) |
|
649 |
except TypeError: |
|
650 |
sub.archive(archiver, prefix) |
|
651 |
||
652 |
archiver.done() |
|
653 |
||
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
654 |
# If a largefile is modified, the change is not reflected in its |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
655 |
# standin until a commit. cmdutil.bailifchanged() raises an exception |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
656 |
# if the repo has uncommitted changes. Wrap it to also check if |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
657 |
# largefiles were changed. This is used by bisect and backout. |
15168 | 658 |
def override_bailifchanged(orig, repo): |
659 |
orig(repo) |
|
660 |
repo.lfstatus = True |
|
661 |
modified, added, removed, deleted = repo.status()[:4] |
|
662 |
repo.lfstatus = False |
|
663 |
if modified or added or removed or deleted: |
|
664 |
raise util.Abort(_('outstanding uncommitted changes')) |
|
665 |
||
666 |
# Fetch doesn't use cmdutil.bail_if_changed so override it to add the check |
|
667 |
def override_fetch(orig, ui, repo, *pats, **opts): |
|
668 |
repo.lfstatus = True |
|
669 |
modified, added, removed, deleted = repo.status()[:4] |
|
670 |
repo.lfstatus = False |
|
671 |
if modified or added or removed or deleted: |
|
672 |
raise util.Abort(_('outstanding uncommitted changes')) |
|
673 |
return orig(ui, repo, *pats, **opts) |
|
674 |
||
675 |
def override_forget(orig, ui, repo, *pats, **opts): |
|
676 |
installnormalfilesmatchfn(repo[None].manifest()) |
|
677 |
orig(ui, repo, *pats, **opts) |
|
678 |
restorematchfn() |
|
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
679 |
m = scmutil.match(repo[None], pats, opts) |
15168 | 680 |
|
681 |
try: |
|
682 |
repo.lfstatus = True |
|
683 |
s = repo.status(match=m, clean=True) |
|
684 |
finally: |
|
685 |
repo.lfstatus = False |
|
686 |
forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
687 |
forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()] |
|
688 |
||
689 |
for f in forget: |
|
690 |
if lfutil.standin(f) not in repo.dirstate and not \ |
|
691 |
os.path.isdir(m.rel(lfutil.standin(f))): |
|
692 |
ui.warn(_('not removing %s: file is already untracked\n') |
|
693 |
% m.rel(f)) |
|
694 |
||
695 |
for f in forget: |
|
696 |
if ui.verbose or not m.exact(f): |
|
697 |
ui.status(_('removing %s\n') % m.rel(f)) |
|
698 |
||
699 |
# Need to lock because standin files are deleted then removed from the |
|
700 |
# repository and we could race inbetween. |
|
701 |
wlock = repo.wlock() |
|
702 |
try: |
|
703 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
704 |
for f in forget: |
|
705 |
if lfdirstate[f] == 'a': |
|
706 |
lfdirstate.drop(f) |
|
707 |
else: |
|
708 |
lfdirstate.remove(f) |
|
709 |
lfdirstate.write() |
|
710 |
lfutil.repo_remove(repo, [lfutil.standin(f) for f in forget], |
|
711 |
unlink=True) |
|
712 |
finally: |
|
713 |
wlock.release() |
|
714 |
||
715 |
def getoutgoinglfiles(ui, repo, dest=None, **opts): |
|
716 |
dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
717 |
dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
718 |
revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
719 |
if revs: |
|
720 |
revs = [repo.lookup(rev) for rev in revs] |
|
721 |
||
15224
7c604d8c7e83
largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents:
15170
diff
changeset
|
722 |
remoteui = hg.remoteui |
15168 | 723 |
|
724 |
try: |
|
725 |
remote = hg.repository(remoteui(repo, opts), dest) |
|
726 |
except error.RepoError: |
|
727 |
return None |
|
728 |
o = lfutil.findoutgoing(repo, remote, False) |
|
729 |
if not o: |
|
730 |
return None |
|
731 |
o = repo.changelog.nodesbetween(o, revs)[0] |
|
732 |
if opts.get('newest_first'): |
|
733 |
o.reverse() |
|
734 |
||
735 |
toupload = set() |
|
736 |
for n in o: |
|
737 |
parents = [p for p in repo.changelog.parents(n) if p != node.nullid] |
|
738 |
ctx = repo[n] |
|
739 |
files = set(ctx.files()) |
|
740 |
if len(parents) == 2: |
|
741 |
mc = ctx.manifest() |
|
742 |
mp1 = ctx.parents()[0].manifest() |
|
743 |
mp2 = ctx.parents()[1].manifest() |
|
744 |
for f in mp1: |
|
745 |
if f not in mc: |
|
746 |
files.add(f) |
|
747 |
for f in mp2: |
|
748 |
if f not in mc: |
|
749 |
files.add(f) |
|
750 |
for f in mc: |
|
751 |
if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None): |
|
752 |
files.add(f) |
|
15255
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
753 |
toupload = toupload.union( |
7ab05d752405
largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents:
15254
diff
changeset
|
754 |
set([f for f in files if lfutil.isstandin(f) and f in ctx])) |
15168 | 755 |
return toupload |
756 |
||
757 |
def override_outgoing(orig, ui, repo, dest=None, **opts): |
|
758 |
orig(ui, repo, dest, **opts) |
|
759 |
||
760 |
if opts.pop('large', None): |
|
761 |
toupload = getoutgoinglfiles(ui, repo, dest, **opts) |
|
762 |
if toupload is None: |
|
763 |
ui.status(_('largefiles: No remote repo\n')) |
|
764 |
else: |
|
765 |
ui.status(_('largefiles to upload:\n')) |
|
766 |
for file in toupload: |
|
767 |
ui.status(lfutil.splitstandin(file) + '\n') |
|
768 |
ui.status('\n') |
|
769 |
||
770 |
def override_summary(orig, ui, repo, *pats, **opts): |
|
771 |
orig(ui, repo, *pats, **opts) |
|
772 |
||
773 |
if opts.pop('large', None): |
|
774 |
toupload = getoutgoinglfiles(ui, repo, None, **opts) |
|
775 |
if toupload is None: |
|
776 |
ui.status(_('largefiles: No remote repo\n')) |
|
777 |
else: |
|
778 |
ui.status(_('largefiles: %d to upload\n') % len(toupload)) |
|
779 |
||
780 |
def override_addremove(orig, ui, repo, *pats, **opts): |
|
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
781 |
# Check if the parent or child has largefiles; if so, disallow |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
782 |
# addremove. If there is a symlink in the manifest then getting |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
783 |
# the manifest throws an exception: catch it and let addremove |
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
784 |
# deal with it. |
15168 | 785 |
try: |
786 |
manifesttip = set(repo['tip'].manifest()) |
|
787 |
except util.Abort: |
|
788 |
manifesttip = set() |
|
789 |
try: |
|
790 |
manifestworking = set(repo[None].manifest()) |
|
791 |
except util.Abort: |
|
792 |
manifestworking = set() |
|
793 |
||
794 |
# Manifests are only iterable so turn them into sets then union |
|
795 |
for file in manifesttip.union(manifestworking): |
|
796 |
if file.startswith(lfutil.shortname): |
|
797 |
raise util.Abort( |
|
798 |
_('addremove cannot be run on a repo with largefiles')) |
|
799 |
||
800 |
return orig(ui, repo, *pats, **opts) |
|
801 |
||
15254
dd03d3a9f888
largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents:
15252
diff
changeset
|
802 |
# Calling purge with --all will cause the largefiles to be deleted. |
15168 | 803 |
# Override repo.status to prevent this from happening. |
804 |
def override_purge(orig, ui, repo, *dirs, **opts): |
|
805 |
oldstatus = repo.status |
|
806 |
def override_status(node1='.', node2=None, match=None, ignored=False, |
|
807 |
clean=False, unknown=False, listsubrepos=False): |
|
808 |
r = oldstatus(node1, node2, match, ignored, clean, unknown, |
|
809 |
listsubrepos) |
|
810 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
811 |
modified, added, removed, deleted, unknown, ignored, clean = r |
|
812 |
unknown = [f for f in unknown if lfdirstate[f] == '?'] |
|
813 |
ignored = [f for f in ignored if lfdirstate[f] == '?'] |
|
814 |
return modified, added, removed, deleted, unknown, ignored, clean |
|
815 |
repo.status = override_status |
|
816 |
orig(ui, repo, *dirs, **opts) |
|
817 |
repo.status = oldstatus |
|
818 |
||
819 |
def override_rollback(orig, ui, repo, **opts): |
|
820 |
result = orig(ui, repo, **opts) |
|
821 |
merge.update(repo, node=None, branchmerge=False, force=True, |
|
822 |
partial=lfutil.isstandin) |
|
823 |
lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
824 |
lfiles = lfutil.listlfiles(repo) |
|
825 |
oldlfiles = lfutil.listlfiles(repo, repo[None].parents()[0].rev()) |
|
826 |
for file in lfiles: |
|
827 |
if file in oldlfiles: |
|
828 |
lfdirstate.normallookup(file) |
|
829 |
else: |
|
830 |
lfdirstate.add(file) |
|
831 |
lfdirstate.write() |
|
832 |
return result |