##// END OF EJS Templates
largefiles: use the convert extension for 'lfconvert --to-normal'...
Matt Harbison -
r25325:fcd2f9b0 default
parent child Browse files
Show More
@@ -16,6 +16,9 b' from mercurial import util, match as mat'
16 from mercurial.i18n import _
16 from mercurial.i18n import _
17 from mercurial.lock import release
17 from mercurial.lock import release
18
18
19 from hgext.convert import convcmd
20 from hgext.convert import filemap
21
19 import lfutil
22 import lfutil
20 import basestore
23 import basestore
21
24
@@ -70,12 +73,6 b' def lfconvert(ui, src, dest, *pats, **op'
70 success = False
73 success = False
71 dstwlock = dstlock = None
74 dstwlock = dstlock = None
72 try:
75 try:
73 # Lock destination to prevent modification while it is converted to.
74 # Don't need to lock src because we are just reading from its history
75 # which can't change.
76 dstwlock = rdst.wlock()
77 dstlock = rdst.lock()
78
79 # Get a list of all changesets in the source. The easy way to do this
76 # Get a list of all changesets in the source. The easy way to do this
80 # is to simply walk the changelog, using changelog.nodesbetween().
77 # is to simply walk the changelog, using changelog.nodesbetween().
81 # Take a look at mercurial/revlog.py:639 for more details.
78 # Take a look at mercurial/revlog.py:639 for more details.
@@ -84,6 +81,12 b' def lfconvert(ui, src, dest, *pats, **op'
84 rsrc.heads())[0])
81 rsrc.heads())[0])
85 revmap = {node.nullid: node.nullid}
82 revmap = {node.nullid: node.nullid}
86 if tolfile:
83 if tolfile:
84 # Lock destination to prevent modification while it is converted to.
85 # Don't need to lock src because we are just reading from its
86 # history which can't change.
87 dstwlock = rdst.wlock()
88 dstlock = rdst.lock()
89
87 lfiles = set()
90 lfiles = set()
88 normalfiles = set()
91 normalfiles = set()
89 if not pats:
92 if not pats:
@@ -118,16 +121,51 b' def lfconvert(ui, src, dest, *pats, **op'
118 rdst.requirements.add('largefiles')
121 rdst.requirements.add('largefiles')
119 rdst._writerequirements()
122 rdst._writerequirements()
120 else:
123 else:
121 for ctx in ctxs:
124 class lfsource(filemap.filemap_source):
122 ui.progress(_('converting revisions'), ctx.rev(),
125 def __init__(self, ui, source):
123 unit=_('revision'), total=rsrc['tip'].rev())
126 super(lfsource, self).__init__(ui, source, None)
124 _addchangeset(ui, rsrc, rdst, ctx, revmap)
127 self.filemapper.rename[lfutil.shortname] = '.'
128
129 def getfile(self, name, rev):
130 realname, realrev = rev
131 f = super(lfsource, self).getfile(name, rev)
132
133 if (not realname.startswith(lfutil.shortnameslash)
134 or f[0] is None):
135 return f
136
137 # Substitute in the largefile data for the hash
138 hash = f[0].strip()
139 path = lfutil.findfile(rsrc, hash)
125
140
126 ui.progress(_('converting revisions'), None)
141 if path is None:
142 raise util.Abort(_("missing largefile for \'%s\' in %s")
143 % (realname, realrev))
144 fp = open(path, 'rb')
145
146 try:
147 return (fp.read(), f[1])
148 finally:
149 fp.close()
150
151 class converter(convcmd.converter):
152 def __init__(self, ui, source, dest, revmapfile, opts):
153 src = lfsource(ui, source)
154
155 super(converter, self).__init__(ui, src, dest, revmapfile,
156 opts)
157
158 found, missing = downloadlfiles(ui, rsrc)
159 if missing != 0:
160 raise util.Abort(_("all largefiles must be present locally"))
161
162 convcmd.converter = converter
163 convcmd.convert(ui, src, dest)
127 success = True
164 success = True
128 finally:
165 finally:
129 rdst.dirstate.clear()
166 if tolfile:
130 release(dstlock, dstwlock)
167 rdst.dirstate.clear()
168 release(dstlock, dstwlock)
131 if not success:
169 if not success:
132 # we failed, remove the new directory
170 # we failed, remove the new directory
133 shutil.rmtree(rdst.root)
171 shutil.rmtree(rdst.root)
@@ -226,6 +226,7 b' add another largefile to the new largefi'
226 $ hg commit -m "add anotherlarge (should be a largefile)"
226 $ hg commit -m "add anotherlarge (should be a largefile)"
227 $ cat .hglf/anotherlarge
227 $ cat .hglf/anotherlarge
228 3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3
228 3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3
229 $ hg tag mytag
229 $ cd ..
230 $ cd ..
230
231
231 round-trip: converting back to a normal (non-largefiles) repo with
232 round-trip: converting back to a normal (non-largefiles) repo with
@@ -233,25 +234,30 b' round-trip: converting back to a normal '
233 $ cd largefiles-repo
234 $ cd largefiles-repo
234 $ hg lfconvert --to-normal . ../normal-repo
235 $ hg lfconvert --to-normal . ../normal-repo
235 initializing destination ../normal-repo
236 initializing destination ../normal-repo
237 0 additional largefiles cached
238 scanning source...
239 sorting...
240 converting...
241 7 add large, normal1
242 6 add sub/*
243 5 rename sub/ to stuff/
244 4 add normal3, modify sub/*
245 3 remove large, normal3
246 2 merge
247 1 add anotherlarge (should be a largefile)
248 0 Added tag mytag for changeset abacddda7028
236 $ cd ../normal-repo
249 $ cd ../normal-repo
237 $ cat >> .hg/hgrc <<EOF
250 $ cat >> .hg/hgrc <<EOF
238 > [extensions]
251 > [extensions]
239 > largefiles = !
252 > largefiles = !
240 > EOF
253 > EOF
241
254
242 # Hmmm: the changeset ID for rev 5 is different from the original
243 # normal repo (../bigfile-repo), because the changelog filelist
244 # differs between the two incarnations of rev 5: this repo includes
245 # 'large' in the list, but ../bigfile-repo does not. Since rev 5
246 # removes 'large' relative to the first parent in both repos, it seems
247 # to me that lfconvert is doing a *better* job than
248 # "hg remove" + "hg merge" + "hg commit".
249 # $ hg -R ../bigfile-repo debugdata -c 5
250 # $ hg debugdata -c 5
251 $ hg log -G --template "{rev}:{node|short} {desc|firstline}\n"
255 $ hg log -G --template "{rev}:{node|short} {desc|firstline}\n"
252 o 6:1635824e6f59 add anotherlarge (should be a largefile)
256 o 7:b5fedc110b9d Added tag mytag for changeset 867ab992ecf4
253 |
257 |
254 o 5:7215f8deeaaf merge
258 o 6:867ab992ecf4 add anotherlarge (should be a largefile)
259 |
260 o 5:4884f215abda merge
255 |\
261 |\
256 | o 4:7285f817b77e remove large, normal3
262 | o 4:7285f817b77e remove large, normal3
257 | |
263 | |
@@ -264,8 +270,9 b' round-trip: converting back to a normal '
264 o 0:117b8328f97a add large, normal1
270 o 0:117b8328f97a add large, normal1
265
271
266 $ hg update
272 $ hg update
267 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
273 5 files updated, 0 files merged, 0 files removed, 0 files unresolved
268 $ hg locate
274 $ hg locate
275 .hgtags
269 anotherlarge
276 anotherlarge
270 normal1
277 normal1
271 stuff/maybelarge.dat
278 stuff/maybelarge.dat
@@ -284,15 +291,18 b' from the working dir on a convert.'
284 scanning source...
291 scanning source...
285 sorting...
292 sorting...
286 converting...
293 converting...
287 6 add large, normal1
294 7 add large, normal1
288 5 add sub/*
295 6 add sub/*
289 4 rename sub/ to stuff/
296 5 rename sub/ to stuff/
290 3 add normal3, modify sub/*
297 4 add normal3, modify sub/*
291 2 remove large, normal3
298 3 remove large, normal3
292 1 merge
299 2 merge
293 0 add anotherlarge (should be a largefile)
300 1 add anotherlarge (should be a largefile)
301 0 Added tag mytag for changeset abacddda7028
294
302
295 $ hg -R largefiles-repo-hg log -G --template "{rev}:{node|short} {desc|firstline}\n"
303 $ hg -R largefiles-repo-hg log -G --template "{rev}:{node|short} {desc|firstline}\n"
304 o 7:2f08f66459b7 Added tag mytag for changeset 17126745edfd
305 |
296 o 6:17126745edfd add anotherlarge (should be a largefile)
306 o 6:17126745edfd add anotherlarge (should be a largefile)
297 |
307 |
298 o 5:9cc5aa7204f0 merge
308 o 5:9cc5aa7204f0 merge
@@ -315,8 +325,8 b' process.'
315 checking manifests
325 checking manifests
316 crosschecking files in changesets and manifests
326 crosschecking files in changesets and manifests
317 checking files
327 checking files
318 8 files, 7 changesets, 12 total revisions
328 9 files, 8 changesets, 13 total revisions
319 searching 7 changesets for largefiles
329 searching 8 changesets for largefiles
320 changeset 0:d4892ec57ce2: large references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/2e000fa7e85759c7f4c254d4d9c33ef481e459a7 (glob)
330 changeset 0:d4892ec57ce2: large references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/2e000fa7e85759c7f4c254d4d9c33ef481e459a7 (glob)
321 changeset 1:334e5237836d: sub/maybelarge.dat references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c (glob)
331 changeset 1:334e5237836d: sub/maybelarge.dat references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c (glob)
322 changeset 2:261ad3f3f037: stuff/maybelarge.dat references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c (glob)
332 changeset 2:261ad3f3f037: stuff/maybelarge.dat references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c (glob)
@@ -336,6 +346,18 b' Ensure the largefile can be cached in th'
336 $ rm -f "${USERCACHE}"/*
346 $ rm -f "${USERCACHE}"/*
337 $ hg lfconvert --to-normal issue3519 normalized3519
347 $ hg lfconvert --to-normal issue3519 normalized3519
338 initializing destination normalized3519
348 initializing destination normalized3519
349 4 additional largefiles cached
350 scanning source...
351 sorting...
352 converting...
353 7 add large, normal1
354 6 add sub/*
355 5 rename sub/ to stuff/
356 4 add normal3, modify sub/*
357 3 remove large, normal3
358 2 merge
359 1 add anotherlarge (should be a largefile)
360 0 Added tag mytag for changeset abacddda7028
339
361
340 Ensure the abort message is useful if a largefile is entirely unavailable
362 Ensure the abort message is useful if a largefile is entirely unavailable
341 $ rm -rf normalized3519
363 $ rm -rf normalized3519
@@ -344,8 +366,20 b' Ensure the abort message is useful if a '
344 $ rm largefiles-repo/.hg/largefiles/*
366 $ rm largefiles-repo/.hg/largefiles/*
345 $ hg lfconvert --to-normal issue3519 normalized3519
367 $ hg lfconvert --to-normal issue3519 normalized3519
346 initializing destination normalized3519
368 initializing destination normalized3519
369 anotherlarge: largefile 3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3 not available from file:/*/$TESTTMP/largefiles-repo (glob)
370 stuff/maybelarge.dat: largefile 76236b6a2c6102826c61af4297dd738fb3b1de38 not available from file:/*/$TESTTMP/largefiles-repo (glob)
371 stuff/maybelarge.dat: largefile 76236b6a2c6102826c61af4297dd738fb3b1de38 not available from file:/*/$TESTTMP/largefiles-repo (glob)
372 sub/maybelarge.dat: largefile 76236b6a2c6102826c61af4297dd738fb3b1de38 not available from file:/*/$TESTTMP/largefiles-repo (glob)
347 large: largefile 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 not available from file:/*/$TESTTMP/largefiles-repo (glob)
373 large: largefile 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 not available from file:/*/$TESTTMP/largefiles-repo (glob)
348 abort: missing largefile 'large' from revision d4892ec57ce212905215fad1d9018f56b99202ad
374 sub/maybelarge.dat: largefile 76236b6a2c6102826c61af4297dd738fb3b1de38 not available from file:/*/$TESTTMP/largefiles-repo (glob)
375 large: largefile 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 not available from file:/*/$TESTTMP/largefiles-repo (glob)
376 stuff/maybelarge.dat: largefile 34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c not available from file:/*/$TESTTMP/largefiles-repo (glob)
377 large: largefile 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 not available from file:/*/$TESTTMP/largefiles-repo (glob)
378 sub/maybelarge.dat: largefile 34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c not available from file:/*/$TESTTMP/largefiles-repo (glob)
379 large: largefile 2e000fa7e85759c7f4c254d4d9c33ef481e459a7 not available from file:/*/$TESTTMP/largefiles-repo (glob)
380 0 additional largefiles cached
381 11 largefiles failed to download
382 abort: all largefiles must be present locally
349 [255]
383 [255]
350
384
351
385
General Comments 0
You need to be logged in to leave comments. Login now