Mercurial > hg
comparison hgext/largefiles/lfcommands.py @ 31654:1af4a1641bdb
largefiles: avoid redundant changectx looking up at each repetitions
These code paths look up changectx at each repetitions, even though
the changectx key isn't changed while loop.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 27 Mar 2017 09:44:35 +0900 |
parents | 8228bc8fed8c |
children | 3e37b479ce2f |
comparison
equal
deleted
inserted
replaced
31653:32d998dc2a00 | 31654:1af4a1641bdb |
---|---|
401 lfiles = lfutil.listlfiles(repo, node) | 401 lfiles = lfutil.listlfiles(repo, node) |
402 if filelist: | 402 if filelist: |
403 lfiles = set(lfiles) & set(filelist) | 403 lfiles = set(lfiles) & set(filelist) |
404 toget = [] | 404 toget = [] |
405 | 405 |
406 ctx = repo[node] | |
406 for lfile in lfiles: | 407 for lfile in lfiles: |
407 try: | 408 try: |
408 expectedhash = repo[node][lfutil.standin(lfile)].data().strip() | 409 expectedhash = ctx[lfutil.standin(lfile)].data().strip() |
409 except IOError as err: | 410 except IOError as err: |
410 if err.errno == errno.ENOENT: | 411 if err.errno == errno.ENOENT: |
411 continue # node must be None and standin wasn't found in wctx | 412 continue # node must be None and standin wasn't found in wctx |
412 raise | 413 raise |
413 if not lfutil.findfile(repo, expectedhash): | 414 if not lfutil.findfile(repo, expectedhash): |
455 lfiles = [f for f in lfiles if f in filelist] | 456 lfiles = [f for f in lfiles if f in filelist] |
456 | 457 |
457 update = {} | 458 update = {} |
458 updated, removed = 0, 0 | 459 updated, removed = 0, 0 |
459 wvfs = repo.wvfs | 460 wvfs = repo.wvfs |
461 wctx = repo[None] | |
460 for lfile in lfiles: | 462 for lfile in lfiles: |
461 rellfile = lfile | 463 rellfile = lfile |
462 rellfileorig = os.path.relpath( | 464 rellfileorig = os.path.relpath( |
463 scmutil.origpath(ui, repo, wvfs.join(rellfile)), | 465 scmutil.origpath(ui, repo, wvfs.join(rellfile)), |
464 start=repo.root) | 466 start=repo.root) |
472 shutil.copyfile(wvfs.join(rellfile), | 474 shutil.copyfile(wvfs.join(rellfile), |
473 wvfs.join(rellfileorig)) | 475 wvfs.join(rellfileorig)) |
474 wvfs.unlinkpath(relstandinorig) | 476 wvfs.unlinkpath(relstandinorig) |
475 expecthash = lfutil.readstandin(repo, lfile) | 477 expecthash = lfutil.readstandin(repo, lfile) |
476 if expecthash != '': | 478 if expecthash != '': |
477 if lfile not in repo[None]: # not switched to normal file | 479 if lfile not in wctx: # not switched to normal file |
478 wvfs.unlinkpath(rellfile, ignoremissing=True) | 480 wvfs.unlinkpath(rellfile, ignoremissing=True) |
479 # use normallookup() to allocate an entry in largefiles | 481 # use normallookup() to allocate an entry in largefiles |
480 # dirstate to prevent lfilesrepo.status() from reporting | 482 # dirstate to prevent lfilesrepo.status() from reporting |
481 # missing files as removed. | 483 # missing files as removed. |
482 lfdirstate.normallookup(lfile) | 484 lfdirstate.normallookup(lfile) |
485 # Remove lfiles for which the standin is deleted, unless the | 487 # Remove lfiles for which the standin is deleted, unless the |
486 # lfile is added to the repository again. This happens when a | 488 # lfile is added to the repository again. This happens when a |
487 # largefile is converted back to a normal file: the standin | 489 # largefile is converted back to a normal file: the standin |
488 # disappears, but a new (normal) file appears as the lfile. | 490 # disappears, but a new (normal) file appears as the lfile. |
489 if (wvfs.exists(rellfile) and | 491 if (wvfs.exists(rellfile) and |
490 repo.dirstate.normalize(lfile) not in repo[None]): | 492 repo.dirstate.normalize(lfile) not in wctx): |
491 wvfs.unlinkpath(rellfile) | 493 wvfs.unlinkpath(rellfile) |
492 removed += 1 | 494 removed += 1 |
493 | 495 |
494 # largefile processing might be slow and be interrupted - be prepared | 496 # largefile processing might be slow and be interrupted - be prepared |
495 lfdirstate.write() | 497 lfdirstate.write() |