##// 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 16 from mercurial.i18n import _
17 17 from mercurial.lock import release
18 18
19 from hgext.convert import convcmd
20 from hgext.convert import filemap
21
19 22 import lfutil
20 23 import basestore
21 24
@@ -70,12 +73,6 b' def lfconvert(ui, src, dest, *pats, **op'
70 73 success = False
71 74 dstwlock = dstlock = None
72 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 76 # Get a list of all changesets in the source. The easy way to do this
80 77 # is to simply walk the changelog, using changelog.nodesbetween().
81 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 81 rsrc.heads())[0])
85 82 revmap = {node.nullid: node.nullid}
86 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 90 lfiles = set()
88 91 normalfiles = set()
89 92 if not pats:
@@ -118,16 +121,51 b' def lfconvert(ui, src, dest, *pats, **op'
118 121 rdst.requirements.add('largefiles')
119 122 rdst._writerequirements()
120 123 else:
121 for ctx in ctxs:
122 ui.progress(_('converting revisions'), ctx.rev(),
123 unit=_('revision'), total=rsrc['tip'].rev())
124 _addchangeset(ui, rsrc, rdst, ctx, revmap)
124 class lfsource(filemap.filemap_source):
125 def __init__(self, ui, source):
126 super(lfsource, self).__init__(ui, source, None)
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 164 success = True
128 165 finally:
129 rdst.dirstate.clear()
130 release(dstlock, dstwlock)
166 if tolfile:
167 rdst.dirstate.clear()
168 release(dstlock, dstwlock)
131 169 if not success:
132 170 # we failed, remove the new directory
133 171 shutil.rmtree(rdst.root)
@@ -226,6 +226,7 b' add another largefile to the new largefi'
226 226 $ hg commit -m "add anotherlarge (should be a largefile)"
227 227 $ cat .hglf/anotherlarge
228 228 3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3
229 $ hg tag mytag
229 230 $ cd ..
230 231
231 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 234 $ cd largefiles-repo
234 235 $ hg lfconvert --to-normal . ../normal-repo
235 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 249 $ cd ../normal-repo
237 250 $ cat >> .hg/hgrc <<EOF
238 251 > [extensions]
239 252 > largefiles = !
240 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 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 262 | o 4:7285f817b77e remove large, normal3
257 263 | |
@@ -264,8 +270,9 b' round-trip: converting back to a normal '
264 270 o 0:117b8328f97a add large, normal1
265 271
266 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 274 $ hg locate
275 .hgtags
269 276 anotherlarge
270 277 normal1
271 278 stuff/maybelarge.dat
@@ -284,15 +291,18 b' from the working dir on a convert.'
284 291 scanning source...
285 292 sorting...
286 293 converting...
287 6 add large, normal1
288 5 add sub/*
289 4 rename sub/ to stuff/
290 3 add normal3, modify sub/*
291 2 remove large, normal3
292 1 merge
293 0 add anotherlarge (should be a largefile)
294 7 add large, normal1
295 6 add sub/*
296 5 rename sub/ to stuff/
297 4 add normal3, modify sub/*
298 3 remove large, normal3
299 2 merge
300 1 add anotherlarge (should be a largefile)
301 0 Added tag mytag for changeset abacddda7028
294 302
295 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 306 o 6:17126745edfd add anotherlarge (should be a largefile)
297 307 |
298 308 o 5:9cc5aa7204f0 merge
@@ -315,8 +325,8 b' process.'
315 325 checking manifests
316 326 crosschecking files in changesets and manifests
317 327 checking files
318 8 files, 7 changesets, 12 total revisions
319 searching 7 changesets for largefiles
328 9 files, 8 changesets, 13 total revisions
329 searching 8 changesets for largefiles
320 330 changeset 0:d4892ec57ce2: large references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/2e000fa7e85759c7f4c254d4d9c33ef481e459a7 (glob)
321 331 changeset 1:334e5237836d: sub/maybelarge.dat references missing $TESTTMP/largefiles-repo-hg/.hg/largefiles/34e163be8e43c5631d8b92e9c43ab0bf0fa62b9c (glob)
322 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 346 $ rm -f "${USERCACHE}"/*
337 347 $ hg lfconvert --to-normal issue3519 normalized3519
338 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 362 Ensure the abort message is useful if a largefile is entirely unavailable
341 363 $ rm -rf normalized3519
@@ -344,8 +366,20 b' Ensure the abort message is useful if a '
344 366 $ rm largefiles-repo/.hg/largefiles/*
345 367 $ hg lfconvert --to-normal issue3519 normalized3519
346 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 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 383 [255]
350 384
351 385
General Comments 0
You need to be logged in to leave comments. Login now