Kiln » largefiles » Unity
Clone URL:  

updatelfiles: major simplification; implement in terms of _revertlfile

Changeset b30307e35409

Parent 4a16e7e40cbd

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

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

Change 1 of 4 Show Entire File lfcommands.py Stacked
 
397
398
399
 
400
401
402
 
406
407
408
409
 
 
 
410
411
412
 
413
414
415
 
416
417
418
 
427
428
429
 
430
431
432
 
459
460
461
 
462
463
464
465
466
467
468
469
470
 
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
 
 
 
 
 
 
 
514
515
516
 
397
398
399
400
401
402
403
 
407
408
409
 
410
411
412
413
414
415
416
417
418
419
420
421
422
423
 
432
433
434
435
436
437
438
 
465
466
467
468
469
 
 
 
 
470
471
472
473
474
475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
477
478
479
480
481
482
483
484
485
@@ -397,6 +397,7 @@
  wlock.release()    def _revertlfile(repo, lfdirstate, lfile): + ret = 0   abslfile = repo.wjoin(lfile)   absstandin = repo.wjoin(lfutil.standin(lfile))   if os.path.exists(absstandin): @@ -406,13 +407,17 @@
  if expecthash != '' and \   (not os.path.exists(abslfile) or \   expecthash != lfutil.hashfile(abslfile)): - lfutil.copyfromcache(repo, expecthash, lfile) + if not lfutil.copyfromcache(repo, expecthash, lfile): + return False # don't try to set the mode or update the dirstate + ret = 1   mode = os.stat(absstandin).st_mode   if mode != os.stat(abslfile).st_mode:   os.chmod(abslfile, mode) + ret = 1   else:   if os.path.exists(abslfile):   os.unlink(abslfile) + ret = -1   state = repo.dirstate[lfutil.standin(lfile)]   if state == 'n':   lfdirstate.normal(lfile) @@ -427,6 +432,7 @@
  except AttributeError:   # Mercurial <= 1.8   lfdirstate.forget(lfile) + return ret    def cachelfiles(ui, repo, node):   '''cachelfiles ensures that all largefiles needed by the specified revision @@ -459,58 +465,21 @@
  wlock = repo.wlock()   try:   lfdirstate = lfutil.openlfdirstate(ui, repo) + lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)   - lfiles = lfutil.listlfiles(repo) - at = 0 - updated = 0 - removed = 0   printed = False   if lfiles:   ui.status(_('getting changed largefiles\n'))   printed = True + cachelfiles(ui, repo, '.')   - success, missing = cachelfiles(ui, repo, None) - - for lfile in lfiles: - at += 1 - if os.path.exists(repo.wjoin(lfile)) and not \ - os.path.exists(repo.wjoin(lfutil.standin(lfile))): - os.unlink(repo.wjoin(lfile)) - removed += 1 - lfdirstate.forget(lfutil.unixpath(lfile)) - continue - expectedhash = repo[None][lfutil.standin(lfile)].data().strip() - mode = os.stat(repo.wjoin(lfutil.standin(lfile))).st_mode - if not os.path.exists(repo.wjoin(lfile)) or expectedhash != \ - lfutil.hashfile(repo.wjoin(lfile)): - path = lfutil.findfile(repo, expectedhash) - if path: - util.makedirs(os.path.dirname(repo.wjoin(lfile))) - shutil.copy(path, repo.wjoin(lfile)) - os.chmod(repo.wjoin(lfile), mode) - updated += 1 - lfdirstate.normal(lfutil.unixpath(lfile)) - elif os.path.exists(repo.wjoin(lfile)) and mode != \ - os.stat(repo.wjoin(lfile)).st_mode: - os.chmod(repo.wjoin(lfile), mode) - updated += 1 - lfdirstate.normal(lfutil.unixpath(lfile)) - - for lfile in lfdirstate: - if lfile not in lfiles: - if os.path.exists(repo.wjoin(lfile)): - if not printed: - ui.status(_('getting changed largefiles\n')) - printed = True - os.unlink(repo.wjoin(lfile)) - removed += 1 - path = lfutil.unixpath(lfile) - try: - # Mercurial >= 1.9 - lfdirstate.drop(path) - except AttributeError: - # Mercurial <= 1.8 - lfdirstate.forget(path) + updated, removed = 0, 0 + for i in map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles): + updated += i > 0 and i or 0 + removed -= i < 0 and i or 0 + if (removed or updated) and not printed: + ui.status(_('getting changed largefiles\n')) + printed = True     lfdirstate.write()   if printed: