Kiln » largefiles » Unity
Clone URL:  

lfcommands: fold updatelfiles and revertlfiles into one function

they are actually the same operation, modulo printing messages and filtering on
a filelist, so this turns out to be really easy.

Changeset 3c0c2d0eaa7f

Parent b30307e35409

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

Changes to 2 files · Browse files at 3c0c2d0eaa7f Showing diff from parent b30307e35409 Diff from another changeset...

Change 1 of 2 Show Entire File lfcommands.py Stacked
 
380
381
382
383
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
 
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
 
380
381
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
384
385
 
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
448
449
450
451
452
453
454
455
456
457
458
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
@@ -380,60 +380,6 @@
  store = basestore._openstore(repo)   return store.verify(revs, contents=contents)   -def revertlfiles(ui, repo, filelist=None): - wlock = repo.wlock() - try: - lfdirstate = lfutil.openlfdirstate(ui, 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, '.') - - map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles) - lfdirstate.write() - finally: - wlock.release() - -def _revertlfile(repo, lfdirstate, lfile): - ret = 0 - 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)): - 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) - 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) - return ret -  def cachelfiles(ui, repo, node):   '''cachelfiles ensures that all largefiles needed by the specified revision   are present in the repository's largefile cache. @@ -461,33 +407,82 @@
    return ([], [])   -def updatelfiles(ui, repo): +def updatelfiles(ui, repo, filelist=None, printmessage=True):   wlock = repo.wlock()   try:   lfdirstate = lfutil.openlfdirstate(ui, repo)   lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)   + if filelist is not None: + lfiles = [f for f in lfiles if f in filelist] +   printed = False - if lfiles: + if printmessage and lfiles:   ui.status(_('getting changed largefiles\n'))   printed = True   cachelfiles(ui, repo, '.')     updated, removed = 0, 0 - for i in map(lambda f: _revertlfile(repo, lfdirstate, f), lfiles): + for i in map(lambda f: _updatelfile(repo, lfdirstate, f), lfiles): + # increment the appropriate counter according to _updatelfile's + # return value   updated += i > 0 and i or 0   removed -= i < 0 and i or 0 - if (removed or updated) and not printed: + if printmessage and (removed or updated) and not printed:   ui.status(_('getting changed largefiles\n'))   printed = True     lfdirstate.write() - if printed: + if printed and printmessage:   ui.status(_('%d big files updated, %d removed\n') % (updated,   removed))   finally:   wlock.release()   +def _updatelfile(repo, lfdirstate, lfile): + '''updates a single largefile and copies the state of its standin from + the repository's dirstate to its state in the lfdirstate. + + returns 1 if the file was modified, -1 if the file was removed, 0 if the + file was unchanged, and None if the needed largefile was missing from the + cache.''' + ret = 0 + 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)): + if not lfutil.copyfromcache(repo, expecthash, lfile): + return None # 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) + 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) + return ret +  # -- hg commands declarations ------------------------------------------------    
Change 1 of 1 Show Entire File overrides.py Stacked
 
587
588
589
590
 
591
592
593
 
587
588
589
 
590
591
592
593
@@ -587,7 +587,7 @@
  # Mercurial <= 1.8   cmdutil.match = oldmatch   lfileslist = getattr(repo, '_lfilestoupdate', []) - lfcommands.revertlfiles(ui, repo, lfileslist) + lfcommands.updatelfiles(ui, repo, filelist=lfileslist, printmessage=False)   # Empty out the lfiles list so we start fresh next time   repo._lfilestoupdate = []   for lfile in modified: