remote-hg: add new get_config_bool() helper
No functional changes. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 13, 2013 at 23:36 UTC
760ee1c70a4dbbc792a4bb31731576d8648d24f4
1 file changed
+13
-11
contrib/remote-helpers/git-remote-hg
+13
-11
@@ -87,6 +87,15 @@ def get_config(config):
87
output, _ = process.communicate()
88
return output
89
90
+def get_config_bool(config, default=False):
91
+ value = get_config(config).rstrip('\n')
92
+ if value == "true":
93
+ return True
94
+ elif value == "false":
95
+ return False
96
+ else:
97
+ return default
98
+
99
class Marks:
100
101
def __init__(self, path):
@@ -327,7 +336,7 @@ def get_repo(url, alias):
336
myui.setconfig('ui', 'interactive', 'off')
337
myui.fout = sys.stderr
338
330
- if get_config('remote-hg.insecure') == 'true\n':
339
+ if get_config_bool('remote-hg.insecure'):
340
myui.setconfig('web', 'cacerts', '')
341
342
try:
@@ -903,16 +912,9 @@ def main(args):
912
url = args[2]
913
peer = None
914
906
- hg_git_compat = False
907
- track_branches = True
908
- force_push = True
909
-
910
- if get_config('remote-hg.hg-git-compat') == 'true\n':
911
- hg_git_compat = True
912
- if get_config('remote-hg.track-branches') == 'false\n':
913
- track_branches = False
914
- if get_config('remote-hg.force-push') == 'false\n':
915
- force_push = False
915
+ hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
916
+ track_branches = get_config_bool('remote-hg.track-branches', True)
917
+ force_push = get_config_bool('remote-hg.force-push', True)
918
919
if hg_git_compat:
920
mode = 'hg'