remote-hg: add branch_tip() helper

Idea from gitifyhg, the backwards compatibility is how Mercurial used to do it. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Apr 22, 2013 at 16:55 UTC aeebca0bd280a67003545d36f1886bfdcd9318fe
1 file changed +8 -3
contrib/remote-helpers/git-remote-hg
+8 -3
@@ -457,6 +457,13 @@ def do_capabilities(parser):
457
458 print
459
460 +def branch_tip(repo, branch):
461 + # older versions of mercurial don't have this
462 + if hasattr(repo, 'branchtip'):
463 + return repo.branchtip(branch)
464 + else:
465 + return repo.branchtags()[branch]
466 +
467 def get_branch_tip(repo, branch):
468 global branches
469
@@ -467,9 +474,7 @@ def get_branch_tip(repo, branch):
474 # verify there's only one head
475 if (len(heads) > 1):
476 warn("Branch '%s' has more than one head, consider merging" % branch)
470 - # older versions of mercurial don't have this
471 - if hasattr(repo, "branchtip"):
472 - return repo.branchtip(branch)
477 + return branch_tip(repo, branch)
478
479 return heads[0]
480