Mercurial > hg
comparison mercurial/copies.py @ 26315:3c6902ed9f07
copies: rename ctx() to getfctx() for clarity
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 19 Aug 2015 13:09:54 -0500 |
parents | 38f92d12357c |
children | d5618e210191 |
comparison
equal
deleted
inserted
replaced
26314:119202d4d7a4 | 26315:3c6902ed9f07 |
---|---|
281 m2 = c2.manifest() | 281 m2 = c2.manifest() |
282 ma = ca.manifest() | 282 ma = ca.manifest() |
283 | 283 |
284 | 284 |
285 def setupctx(ctx): | 285 def setupctx(ctx): |
286 """return a 'makectx' function suitable for checkcopies usage from ctx | 286 """return a 'getfctx' function suitable for checkcopies usage |
287 | 287 |
288 We have to re-setup the function building 'filectx' for each | 288 We have to re-setup the function building 'filectx' for each |
289 'checkcopies' to ensure the linkrev adjustement is properly setup for | 289 'checkcopies' to ensure the linkrev adjustement is properly setup for |
290 each. Linkrev adjustment is important to avoid bug in rename | 290 each. Linkrev adjustment is important to avoid bug in rename |
291 detection. Moreover, having a proper '_ancestrycontext' setup ensures | 291 detection. Moreover, having a proper '_ancestrycontext' setup ensures |
326 addedinm1 = m1.filesnotin(ma) | 326 addedinm1 = m1.filesnotin(ma) |
327 addedinm2 = m2.filesnotin(ma) | 327 addedinm2 = m2.filesnotin(ma) |
328 u1, u2 = _computenonoverlap(repo, c1, c2, addedinm1, addedinm2) | 328 u1, u2 = _computenonoverlap(repo, c1, c2, addedinm1, addedinm2) |
329 | 329 |
330 for f in u1: | 330 for f in u1: |
331 ctx = setupctx(c1) | 331 getfctx = setupctx(c1) |
332 checkcopies(ctx, f, m1, m2, ca, limit, diverge, copy, fullcopy) | 332 checkcopies(getfctx, f, m1, m2, ca, limit, diverge, copy, fullcopy) |
333 | 333 |
334 for f in u2: | 334 for f in u2: |
335 ctx = setupctx(c2) | 335 getfctx = setupctx(c2) |
336 checkcopies(ctx, f, m2, m1, ca, limit, diverge, copy, fullcopy) | 336 checkcopies(getfctx, f, m2, m1, ca, limit, diverge, copy, fullcopy) |
337 | 337 |
338 renamedelete = {} | 338 renamedelete = {} |
339 renamedelete2 = set() | 339 renamedelete2 = set() |
340 diverge2 = set() | 340 diverge2 = set() |
341 for of, fl in diverge.items(): | 341 for of, fl in diverge.items(): |
353 if bothnew: | 353 if bothnew: |
354 repo.ui.debug(" unmatched files new in both:\n %s\n" | 354 repo.ui.debug(" unmatched files new in both:\n %s\n" |
355 % "\n ".join(bothnew)) | 355 % "\n ".join(bothnew)) |
356 bothdiverge, _copy, _fullcopy = {}, {}, {} | 356 bothdiverge, _copy, _fullcopy = {}, {}, {} |
357 for f in bothnew: | 357 for f in bothnew: |
358 ctx = setupctx(c1) | 358 getfctx = setupctx(c1) |
359 checkcopies(ctx, f, m1, m2, ca, limit, bothdiverge, _copy, _fullcopy) | 359 checkcopies(getfctx, f, m1, m2, ca, limit, bothdiverge, |
360 ctx = setupctx(c2) | 360 _copy, _fullcopy) |
361 checkcopies(ctx, f, m2, m1, ca, limit, bothdiverge, _copy, _fullcopy) | 361 getfctx = setupctx(c2) |
362 checkcopies(getfctx, f, m2, m1, ca, limit, bothdiverge, | |
363 _copy, _fullcopy) | |
362 for of, fl in bothdiverge.items(): | 364 for of, fl in bothdiverge.items(): |
363 if len(fl) == 2 and fl[0] == fl[1]: | 365 if len(fl) == 2 and fl[0] == fl[1]: |
364 copy[fl[0]] = of # not actually divergent, just matching renames | 366 copy[fl[0]] = of # not actually divergent, just matching renames |
365 | 367 |
366 if fullcopy and repo.ui.debugflag: | 368 if fullcopy and repo.ui.debugflag: |
436 "dst: '%s'\n") % (f, df)) | 438 "dst: '%s'\n") % (f, df)) |
437 break | 439 break |
438 | 440 |
439 return copy, movewithdir, diverge, renamedelete | 441 return copy, movewithdir, diverge, renamedelete |
440 | 442 |
441 def checkcopies(ctx, f, m1, m2, ca, limit, diverge, copy, fullcopy): | 443 def checkcopies(getfctx, f, m1, m2, ca, limit, diverge, copy, fullcopy): |
442 """ | 444 """ |
443 check possible copies of f from m1 to m2 | 445 check possible copies of f from m1 to m2 |
444 | 446 |
445 ctx = function accepting (filename, node) that returns a filectx. | 447 getfctx = function accepting (filename, node) that returns a filectx. |
446 f = the filename to check | 448 f = the filename to check |
447 m1 = the source manifest | 449 m1 = the source manifest |
448 m2 = the destination manifest | 450 m2 = the destination manifest |
449 ca = the changectx of the common ancestor | 451 ca = the changectx of the common ancestor |
450 limit = the rev number to not search beyond | 452 limit = the rev number to not search beyond |
486 except StopIteration: | 488 except StopIteration: |
487 return False | 489 return False |
488 | 490 |
489 of = None | 491 of = None |
490 seen = set([f]) | 492 seen = set([f]) |
491 for oc in ctx(f, m1[f]).ancestors(): | 493 for oc in getfctx(f, m1[f]).ancestors(): |
492 ocr = oc.linkrev() | 494 ocr = oc.linkrev() |
493 of = oc.path() | 495 of = oc.path() |
494 if of in seen: | 496 if of in seen: |
495 # check limit late - grab last rename before | 497 # check limit late - grab last rename before |
496 if ocr < limit: | 498 if ocr < limit: |
501 fullcopy[f] = of # remember for dir rename detection | 503 fullcopy[f] = of # remember for dir rename detection |
502 if of not in m2: | 504 if of not in m2: |
503 continue # no match, keep looking | 505 continue # no match, keep looking |
504 if m2[of] == ma.get(of): | 506 if m2[of] == ma.get(of): |
505 break # no merge needed, quit early | 507 break # no merge needed, quit early |
506 c2 = ctx(of, m2[of]) | 508 c2 = getfctx(of, m2[of]) |
507 cr = _related(oc, c2, ca.rev()) | 509 cr = _related(oc, c2, ca.rev()) |
508 if cr and (of == f or of == c2.path()): # non-divergent | 510 if cr and (of == f or of == c2.path()): # non-divergent |
509 copy[f] = of | 511 copy[f] = of |
510 of = None | 512 of = None |
511 break | 513 break |