From 9b8e0ec2c011a7eb69dddcbf1f19993033aaaea7 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 3 Jun 2019 16:22:27 -0500 Subject: [PATCH] Refactor memfilectx() method It's getting hairy. Signed-off-by: Felipe Contreras --- git-remote-hg | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 26d1f6c..3055435 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -771,6 +771,12 @@ def c_style_unescape(string): return string.decode('string-escape')[1:-1] return string +def make_memfilectx(repo, changectx, path, data, islink=False, isexec=False, copied=None): + if check_version(3, 1): + return context.memfilectx(repo, path, data, islink, isexec, copied) + else: + return context.memfilectx(path, data, islink, isexec, copied) + def parse_commit(parser): from_mark = merge_mark = None @@ -831,23 +837,13 @@ def parse_commit(parser): ctx = of['ctx'] is_exec = ctx.isexec() is_link = ctx.islink() - if check_version(3, 1): - return context.memfilectx(repo, f, ctx.data(), - is_link, is_exec) - else: - return context.memfilectx(f, ctx.data(), - is_link, is_exec) + return make_memfilectx(repo, memctx, f, ctx.data(), is_link, is_exec) else: return of['ctx'] is_exec = of['mode'] == 'x' is_link = of['mode'] == 'l' rename = of.get('rename', None) - if check_version(3, 1): - return context.memfilectx(repo, f, of['data'], - is_link, is_exec, rename) - else: - return context.memfilectx(f, of['data'], - is_link, is_exec, rename) + return make_memfilectx(repo, memctx, f, of['data'], is_link, is_exec, rename) repo = parser.repo @@ -956,10 +952,7 @@ def write_tag(repo, tag, node, msg, author): except error.LookupError: data = "" content = data + "%s %s\n" % (node, tag) - if check_version(3, 1): - return context.memfilectx(repo, f, content, False, False, None) - else: - return context.memfilectx(f, content, False, False, None) + return make_memfilectx(repo, memctx, f, content) p1 = tip.hex() p2 = '0' * 40