From eb7976e7dddf70f0f4a7d05e3d86a33bf163abf2 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:24 -0500 Subject: remote-hg: trivial cleanups Drop unused "global", and remove redundant comparison of two files. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 2 +- contrib/remote-helpers/test-hg-hg-git.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 96ad30d512..d33c7bafc3 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -538,7 +538,7 @@ def list_head(repo, cur): g_head = (head, node) def do_list(parser): - global branches, bmarks, mode, track_branches + global branches, bmarks, track_branches repo = parser.repo for bmark, node in bookmarks.listbookmarks(repo).iteritems(): diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 84403415f8..0c365737c3 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -455,8 +455,6 @@ test_expect_success 'hg author' ' git_log gitrepo-$x > git-log-$x done && - test_cmp git-log-hg git-log-git && - test_cmp hg-log-hg hg-log-git && test_cmp git-log-hg git-log-git ' -- cgit v1.2.3 From 557399e9bd2d2e8d13fac2ca9dbe4d6aa811e23c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:25 -0500 Subject: remote-hg: get rid of unused exception checks Remove try/except check because we are no longer calling check_output(), which may throw an exception. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index d33c7bafc3..9d6940b927 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -327,11 +327,8 @@ def get_repo(url, alias): myui.setconfig('ui', 'interactive', 'off') myui.fout = sys.stderr - try: - if get_config('remote-hg.insecure') == 'true\n': - myui.setconfig('web', 'cacerts', '') - except subprocess.CalledProcessError: - pass + if get_config('remote-hg.insecure') == 'true\n': + myui.setconfig('web', 'cacerts', '') try: mod = extensions.load(myui, 'hgext.schemes', None) @@ -910,16 +907,13 @@ def main(args): track_branches = True force_push = True - try: - if get_config('remote-hg.hg-git-compat') == 'true\n': - hg_git_compat = True - track_branches = False - if get_config('remote-hg.track-branches') == 'false\n': - track_branches = False - if get_config('remote-hg.force-push') == 'false\n': - force_push = False - except subprocess.CalledProcessError: - pass + if get_config('remote-hg.hg-git-compat') == 'true\n': + hg_git_compat = True + track_branches = False + if get_config('remote-hg.track-branches') == 'false\n': + track_branches = False + if get_config('remote-hg.force-push') == 'false\n': + force_push = False if hg_git_compat: mode = 'hg' -- cgit v1.2.3 From 679e87c02bf02b34fe4dba5bd09e17269223c96f Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:26 -0500 Subject: remote-hg: enable track-branches in hg-git mode The user can turn this off. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 1 - contrib/remote-helpers/test-hg-hg-git.sh | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 9d6940b927..de3a96ebe4 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -909,7 +909,6 @@ def main(args): if get_config('remote-hg.hg-git-compat') == 'true\n': hg_git_compat = True - track_branches = False if get_config('remote-hg.track-branches') == 'false\n': track_branches = False if get_config('remote-hg.force-push') == 'false\n': diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 0c365737c3..7f579c8436 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -102,6 +102,7 @@ setup () { ) >> "$HOME"/.hgrc && git config --global receive.denycurrentbranch warn git config --global remote-hg.hg-git-compat true + git config --global remote-hg.track-branches false HGEDITOR=/usr/bin/true -- cgit v1.2.3 From 760ee1c70a4dbbc792a4bb31731576d8648d24f4 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:27 -0500 Subject: remote-hg: add new get_config_bool() helper No functional changes. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index de3a96ebe4..4a5c72ffea 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -87,6 +87,15 @@ def get_config(config): output, _ = process.communicate() return output +def get_config_bool(config, default=False): + value = get_config(config).rstrip('\n') + if value == "true": + return True + elif value == "false": + return False + else: + return default + class Marks: def __init__(self, path): @@ -327,7 +336,7 @@ def get_repo(url, alias): myui.setconfig('ui', 'interactive', 'off') myui.fout = sys.stderr - if get_config('remote-hg.insecure') == 'true\n': + if get_config_bool('remote-hg.insecure'): myui.setconfig('web', 'cacerts', '') try: @@ -903,16 +912,9 @@ def main(args): url = args[2] peer = None - hg_git_compat = False - track_branches = True - force_push = True - - if get_config('remote-hg.hg-git-compat') == 'true\n': - hg_git_compat = True - if get_config('remote-hg.track-branches') == 'false\n': - track_branches = False - if get_config('remote-hg.force-push') == 'false\n': - force_push = False + hg_git_compat = get_config_bool('remote-hg.hg-git-compat') + track_branches = get_config_bool('remote-hg.track-branches', True) + force_push = get_config_bool('remote-hg.force-push', True) if hg_git_compat: mode = 'hg' -- cgit v1.2.3 From 637333673a156898087e87f551a6eb1f9405e39d Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:28 -0500 Subject: remote-hg: fix new branch creation When a user creates a new branch with git: % git checkout -b branches/devel and then pushes this branch % git push origin branches/devel which is the way to push new mercurial branches, we do want to create a branch, but the command would fail without newbranch=True. This only matters when force_push=False, but setting newbranch=True unconditionally does not hurt. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 4a5c72ffea..3cf9b4c24a 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -856,7 +856,7 @@ def do_export(parser): continue if peer: - parser.repo.push(peer, force=force_push) + parser.repo.push(peer, force=force_push, newbranch=True) # handle bookmarks for bmark, node in p_bmarks: -- cgit v1.2.3 From 06f42133550725d360c9b6acc3b3fa223fee6c47 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:29 -0500 Subject: remote-hg: disable forced push by default In certain situations we might end up pushing garbage revisions (e.g. in a rebase), and the patches to deal with that haven't been merged yet. So let's disable forced pushes by default. We are essentially reverting back to the old v1.8.2 behavior, to minimize the possibility of regressions, but in a way the user can configure. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 3cf9b4c24a..53412dd91f 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -914,7 +914,7 @@ def main(args): hg_git_compat = get_config_bool('remote-hg.hg-git-compat') track_branches = get_config_bool('remote-hg.track-branches', True) - force_push = get_config_bool('remote-hg.force-push', True) + force_push = get_config_bool('remote-hg.force-push') if hg_git_compat: mode = 'hg' -- cgit v1.2.3 From 9ed920a680ca1999714f287672a31fa862f95e3f Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:30 -0500 Subject: remote-hg: don't push fake 'master' bookmark We skip it locally, but not for the remote, so let's do so. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 53412dd91f..beb864b57e 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -873,7 +873,8 @@ def do_export(parser): if bmark == 'master' and 'master' not in parser.repo._bookmarks: # fake bookmark - pass + print "ok %s" % ref + continue elif bookmarks.pushbookmark(parser.repo, bmark, old, new): # updated locally pass -- cgit v1.2.3 From 24317ef32ac3111ed00792f9b2921dc19dd28fe2 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 13 May 2013 23:36:31 -0500 Subject: remote-hg: update bookmarks when pulling Otherwise, the user would never ever see new bookmarks, only the ones that (s)he initially cloned. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 3 +++ 1 file changed, 3 insertions(+) (limited to 'contrib') diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index beb864b57e..dc276afb1b 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -363,6 +363,9 @@ def get_repo(url, alias): die('Repository error') repo.pull(peer, heads=None, force=True) + rb = peer.listkeys('bookmarks') + bookmarks.updatefromremote(myui, repo, rb, url) + return repo def rev_to_mark(rev): -- cgit v1.2.3