Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/filemerge.py @ 26512:4c52dd406adc
filemerge: indent filemerge.filemerge
This will make upcoming patches much easier to review.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 06 Oct 2015 17:39:13 -0700 |
parents | a4da463df6cf |
children | 01224c28e0ed |
comparison
equal
deleted
inserted
replaced
26511:bb3d961c1648 | 26512:4c52dd406adc |
---|---|
439 fco = other file context | 439 fco = other file context |
440 fca = ancestor file context | 440 fca = ancestor file context |
441 fcd = local file context for current/destination file | 441 fcd = local file context for current/destination file |
442 """ | 442 """ |
443 | 443 |
444 def temp(prefix, ctx): | 444 if True: |
445 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) | 445 def temp(prefix, ctx): |
446 (fd, name) = tempfile.mkstemp(prefix=pre) | 446 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) |
447 data = repo.wwritedata(ctx.path(), ctx.data()) | 447 (fd, name) = tempfile.mkstemp(prefix=pre) |
448 f = os.fdopen(fd, "wb") | 448 data = repo.wwritedata(ctx.path(), ctx.data()) |
449 f.write(data) | 449 f = os.fdopen(fd, "wb") |
450 f.close() | 450 f.write(data) |
451 return name | 451 f.close() |
452 | 452 return name |
453 if not fco.cmp(fcd): # files identical? | 453 |
454 return None | 454 if not fco.cmp(fcd): # files identical? |
455 | 455 return None |
456 ui = repo.ui | 456 |
457 fd = fcd.path() | 457 ui = repo.ui |
458 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary() | 458 fd = fcd.path() |
459 symlink = 'l' in fcd.flags() + fco.flags() | 459 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary() |
460 tool, toolpath = _picktool(repo, ui, fd, binary, symlink) | 460 symlink = 'l' in fcd.flags() + fco.flags() |
461 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % | 461 tool, toolpath = _picktool(repo, ui, fd, binary, symlink) |
462 (tool, fd, binary, symlink)) | 462 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % |
463 | 463 (tool, fd, binary, symlink)) |
464 if tool in internals: | 464 |
465 func = internals[tool] | 465 if tool in internals: |
466 trymerge = func.trymerge | 466 func = internals[tool] |
467 onfailure = func.onfailure | 467 trymerge = func.trymerge |
468 else: | 468 onfailure = func.onfailure |
469 func = _xmerge | 469 else: |
470 trymerge = True | 470 func = _xmerge |
471 onfailure = _("merging %s failed!\n") | 471 trymerge = True |
472 | 472 onfailure = _("merging %s failed!\n") |
473 toolconf = tool, toolpath, binary, symlink | 473 |
474 | 474 toolconf = tool, toolpath, binary, symlink |
475 if not trymerge: | 475 |
476 return func(repo, mynode, orig, fcd, fco, fca, toolconf) | 476 if not trymerge: |
477 | 477 return func(repo, mynode, orig, fcd, fco, fca, toolconf) |
478 a = repo.wjoin(fd) | 478 |
479 b = temp("base", fca) | 479 a = repo.wjoin(fd) |
480 c = temp("other", fco) | 480 b = temp("base", fca) |
481 back = a + ".orig" | 481 c = temp("other", fco) |
482 util.copyfile(a, back) | 482 back = a + ".orig" |
483 | 483 util.copyfile(a, back) |
484 if orig != fco.path(): | 484 |
485 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd)) | 485 if orig != fco.path(): |
486 else: | 486 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd)) |
487 ui.status(_("merging %s\n") % fd) | 487 else: |
488 | 488 ui.status(_("merging %s\n") % fd) |
489 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) | 489 |
490 | 490 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) |
491 markerstyle = ui.config('ui', 'mergemarkers', 'basic') | 491 |
492 if not labels: | 492 markerstyle = ui.config('ui', 'mergemarkers', 'basic') |
493 labels = _defaultconflictlabels | 493 if not labels: |
494 if markerstyle != 'basic': | 494 labels = _defaultconflictlabels |
495 labels = _formatlabels(repo, fcd, fco, fca, labels) | 495 if markerstyle != 'basic': |
496 | 496 labels = _formatlabels(repo, fcd, fco, fca, labels) |
497 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, | 497 |
498 (a, b, c, back), labels=labels) | 498 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, |
499 if not needcheck: | 499 (a, b, c, back), labels=labels) |
500 if not needcheck: | |
501 if r: | |
502 if onfailure: | |
503 ui.warn(onfailure % fd) | |
504 else: | |
505 util.unlink(back) | |
506 | |
507 util.unlink(b) | |
508 util.unlink(c) | |
509 return r | |
510 | |
511 if not r and (_toolbool(ui, tool, "checkconflicts") or | |
512 'conflicts' in _toollist(ui, tool, "check")): | |
513 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(), | |
514 re.MULTILINE): | |
515 r = 1 | |
516 | |
517 checked = False | |
518 if 'prompt' in _toollist(ui, tool, "check"): | |
519 checked = True | |
520 if ui.promptchoice(_("was merge of '%s' successful (yn)?" | |
521 "$$ &Yes $$ &No") % fd, 1): | |
522 r = 1 | |
523 | |
524 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or | |
525 'changed' in | |
526 _toollist(ui, tool, "check")): | |
527 if filecmp.cmp(a, back): | |
528 if ui.promptchoice(_(" output file %s appears unchanged\n" | |
529 "was merge successful (yn)?" | |
530 "$$ &Yes $$ &No") % fd, 1): | |
531 r = 1 | |
532 | |
533 if _toolbool(ui, tool, "fixeol"): | |
534 _matcheol(a, back) | |
535 | |
500 if r: | 536 if r: |
501 if onfailure: | 537 if onfailure: |
502 ui.warn(onfailure % fd) | 538 ui.warn(onfailure % fd) |
503 else: | 539 else: |
504 util.unlink(back) | 540 util.unlink(back) |
505 | 541 |
506 util.unlink(b) | 542 util.unlink(b) |
507 util.unlink(c) | 543 util.unlink(c) |
508 return r | 544 return r |
509 | 545 |
510 if not r and (_toolbool(ui, tool, "checkconflicts") or | |
511 'conflicts' in _toollist(ui, tool, "check")): | |
512 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(), | |
513 re.MULTILINE): | |
514 r = 1 | |
515 | |
516 checked = False | |
517 if 'prompt' in _toollist(ui, tool, "check"): | |
518 checked = True | |
519 if ui.promptchoice(_("was merge of '%s' successful (yn)?" | |
520 "$$ &Yes $$ &No") % fd, 1): | |
521 r = 1 | |
522 | |
523 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or | |
524 'changed' in _toollist(ui, tool, "check")): | |
525 if filecmp.cmp(a, back): | |
526 if ui.promptchoice(_(" output file %s appears unchanged\n" | |
527 "was merge successful (yn)?" | |
528 "$$ &Yes $$ &No") % fd, 1): | |
529 r = 1 | |
530 | |
531 if _toolbool(ui, tool, "fixeol"): | |
532 _matcheol(a, back) | |
533 | |
534 if r: | |
535 if onfailure: | |
536 ui.warn(onfailure % fd) | |
537 else: | |
538 util.unlink(back) | |
539 | |
540 util.unlink(b) | |
541 util.unlink(c) | |
542 return r | |
543 | |
544 # tell hggettext to extract docstrings from these functions: | 546 # tell hggettext to extract docstrings from these functions: |
545 i18nfunctions = internals.values() | 547 i18nfunctions = internals.values() |