Mercurial > hg
comparison mercurial/copies.py @ 30138:733fb9f7bc92
checkcopies: extract the '_related' closure
There is not need for it to be a closure.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 11 Oct 2016 01:29:08 +0200 |
parents | f85f9e069e09 |
children | 0106f93ca1d5 |
comparison
equal
deleted
inserted
replaced
30137:f85f9e069e09 | 30138:733fb9f7bc92 |
---|---|
452 "dst: '%s'\n") % (f, df)) | 452 "dst: '%s'\n") % (f, df)) |
453 break | 453 break |
454 | 454 |
455 return copy, movewithdir, diverge, renamedelete | 455 return copy, movewithdir, diverge, renamedelete |
456 | 456 |
457 def _related(f1, f2, limit): | |
458 """return True if f1 and f2 filectx have a common ancestor | |
459 | |
460 Walk back to common ancestor to see if the two files originate | |
461 from the same file. Since workingfilectx's rev() is None it messes | |
462 up the integer comparison logic, hence the pre-step check for | |
463 None (f1 and f2 can only be workingfilectx's initially). | |
464 """ | |
465 | |
466 if f1 == f2: | |
467 return f1 # a match | |
468 | |
469 g1, g2 = f1.ancestors(), f2.ancestors() | |
470 try: | |
471 f1r, f2r = f1.linkrev(), f2.linkrev() | |
472 | |
473 if f1r is None: | |
474 f1 = next(g1) | |
475 if f2r is None: | |
476 f2 = next(g2) | |
477 | |
478 while True: | |
479 f1r, f2r = f1.linkrev(), f2.linkrev() | |
480 if f1r > f2r: | |
481 f1 = next(g1) | |
482 elif f2r > f1r: | |
483 f2 = next(g2) | |
484 elif f1 == f2: | |
485 return f1 # a match | |
486 elif f1r == f2r or f1r < limit or f2r < limit: | |
487 return False # copy no longer relevant | |
488 except StopIteration: | |
489 return False | |
490 | |
457 def _checkcopies(ctx, f, m1, m2, base, limit, diverge, copy, fullcopy): | 491 def _checkcopies(ctx, f, m1, m2, base, limit, diverge, copy, fullcopy): |
458 """ | 492 """ |
459 check possible copies of f from m1 to m2 | 493 check possible copies of f from m1 to m2 |
460 | 494 |
461 ctx = starting context for f in m1 | 495 ctx = starting context for f in m1 |
474 once it "goes behind a certain revision". | 508 once it "goes behind a certain revision". |
475 """ | 509 """ |
476 | 510 |
477 mb = base.manifest() | 511 mb = base.manifest() |
478 getfctx = _makegetfctx(ctx) | 512 getfctx = _makegetfctx(ctx) |
479 | |
480 def _related(f1, f2, limit): | |
481 # Walk back to common ancestor to see if the two files originate | |
482 # from the same file. Since workingfilectx's rev() is None it messes | |
483 # up the integer comparison logic, hence the pre-step check for | |
484 # None (f1 and f2 can only be workingfilectx's initially). | |
485 | |
486 if f1 == f2: | |
487 return f1 # a match | |
488 | |
489 g1, g2 = f1.ancestors(), f2.ancestors() | |
490 try: | |
491 f1r, f2r = f1.linkrev(), f2.linkrev() | |
492 | |
493 if f1r is None: | |
494 f1 = next(g1) | |
495 if f2r is None: | |
496 f2 = next(g2) | |
497 | |
498 while True: | |
499 f1r, f2r = f1.linkrev(), f2.linkrev() | |
500 if f1r > f2r: | |
501 f1 = next(g1) | |
502 elif f2r > f1r: | |
503 f2 = next(g2) | |
504 elif f1 == f2: | |
505 return f1 # a match | |
506 elif f1r == f2r or f1r < limit or f2r < limit: | |
507 return False # copy no longer relevant | |
508 except StopIteration: | |
509 return False | |
510 | 513 |
511 of = None | 514 of = None |
512 seen = set([f]) | 515 seen = set([f]) |
513 for oc in getfctx(f, m1[f]).ancestors(): | 516 for oc in getfctx(f, m1[f]).ancestors(): |
514 ocr = oc.linkrev() | 517 ocr = oc.linkrev() |