Kiln » largefiles » Unity
Clone URL:  

revertlfiles: major cleanup and simplification

Changeset 4a16e7e40cbd

Parent 0a2b4117dbb2

by Profile picture of User 521Andrew Pritchard <andrewp@fogcreek.com>

Changes to one file · Browse files at 4a16e7e40cbd Showing diff from parent 0a2b4117dbb2 Diff from another changeset...

Change 1 of 1 Show Entire File lfcommands.py Stacked
 
384
385
386
387
388
389
 
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
 
441
442
443
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
446
447
 
384
385
386
 
 
 
387
388
389
390
391
392
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
@@ -384,64 +384,50 @@
  wlock = repo.wlock()   try:   lfdirstate = lfutil.openlfdirstate(ui, repo) - - lfiles = lfutil.listlfiles(repo) - + lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)   if filelist is not None:   lfiles = [f for f in lfiles if f in filelist]     if lfiles:   cachelfiles(ui, repo, '.')   - for lfile in lfiles: - if not os.path.exists(repo.wjoin(lfutil.standin(lfile))): - lfdirstate.remove(lfile) - continue - if os.path.exists(repo.wjoin(lfutil.standin(lfile + '.orig'))): - shutil.copyfile(repo.wjoin(lfile), repo.wjoin(lfile + '.orig')) - expectedhash = lfutil.readstandin(repo, lfile) - mode = os.stat(repo.wjoin(lfutil.standin(lfile))).st_mode - if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \ - lfutil.hashrepofile(repo, lfile): - lfutil.copyfromcache(repo, expectedhash, lfile) - if os.path.exists(repo.wjoin(lfile)) and mode != \ - os.stat(repo.wjoin(lfile)).st_mode: - os.chmod(repo.wjoin(lfile), mode) - if lfutil.standin(lfile) not in repo['.']: - lfdirstate.add(lfile) - elif expectedhash == lfutil.readstandin(repo, lfile, '.'): - lfdirstate.normal(lfile) - - removed = 0 - for lfile in lfdirstate: - if filelist is None or lfile in filelist: - if not os.path.exists(repo.wjoin(lfutil.standin(lfile))): - if os.path.exists(repo.wjoin(lfile)): - os.unlink(repo.wjoin(lfile)) - removed += 1 - if lfutil.standin(lfile) in repo['.']: - lfdirstate.remove(lfile) - else: - lfdirstate.forget(lfile) - else: - state = repo.dirstate[lfutil.standin(lfile)] - if state == 'n': - lfdirstate.normal(lfile) - elif state == 'r': - lfdirstate.remove(lfile) - elif state == 'a': - lfdirstate.add(lfile) - elif state == '?': - try: - # Mercurial >= 1.9 - lfdirstate.drop(lfile) - except AttributeError: - # Mercurial <= 1.8 - lfdirstate.forget(lfile) + map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles)   lfdirstate.write()   finally:   wlock.release()   +def _revertlfile(repo, lfdirstate, lfile): + abslfile = repo.wjoin(lfile) + absstandin = repo.wjoin(lfutil.standin(lfile)) + if os.path.exists(absstandin): + if os.path.exists(absstandin+'.orig'): + shutil.copyfile(abslfile, abslfile+'.orig') + expecthash = lfutil.readstandin(repo, lfile) + if expecthash != '' and \ + (not os.path.exists(abslfile) or \ + expecthash != lfutil.hashfile(abslfile)): + lfutil.copyfromcache(repo, expecthash, lfile) + mode = os.stat(absstandin).st_mode + if mode != os.stat(abslfile).st_mode: + os.chmod(abslfile, mode) + else: + if os.path.exists(abslfile): + os.unlink(abslfile) + state = repo.dirstate[lfutil.standin(lfile)] + if state == 'n': + lfdirstate.normal(lfile) + elif state == 'r': + lfdirstate.remove(lfile) + elif state == 'a': + lfdirstate.add(lfile) + elif state == '?': + try: + # Mercurial >= 1.9 + lfdirstate.drop(lfile) + except AttributeError: + # Mercurial <= 1.8 + lfdirstate.forget(lfile) +  def cachelfiles(ui, repo, node):   '''cachelfiles ensures that all largefiles needed by the specified revision   are present in the repository's largefile cache.