From a5e0ddd358c9dea27965b8759a1b56da5fe2e8f7 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 4 Dec 2022 09:26:01 +0100 Subject: [PATCH] shell: git-evtag-compute-py: port to python 3 From https://github.com/cgwalters/git-evtag commit 2eaa213 (git-evtag-compute-py: Port to Python 3, 2021-05-05). --- shell/bin/git-evtag-compute-py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/shell/bin/git-evtag-compute-py b/shell/bin/git-evtag-compute-py index 0babc5c..72e86b8 100755 --- a/shell/bin/git-evtag-compute-py +++ b/shell/bin/git-evtag-compute-py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # An implementation of Git-EVTag in a mixture of Python and # git-as-subprocess. Slower than C, but easier to understand @@ -41,17 +41,18 @@ def checksum_bytes(otype, buf): return blen def checksum_object(repo, objid): + assert objid is not None p = subprocess.Popen(['git', 'cat-file', '--batch'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True, cwd=repo) - p.stdin.write(objid + '\n') + p.stdin.write(objid.encode('ascii') + b'\n') p.stdin.close() - (objid,objtype,lenstr) = p.stdout.readline().split(None, 2) + (objid,objtype,lenstr) = p.stdout.readline().decode('ascii').split(None, 2) olen = int(lenstr) lenstr = lenstr.strip() - buf = "{0} {1}\000".format(objtype, lenstr) + buf = "{0} {1}\000".format(objtype, lenstr).encode('ascii') checksum_bytes(objtype, buf) stats[objtype] += 1 @@ -59,7 +60,7 @@ def checksum_object(repo, objid): if objtype == 'commit': buf = p.stdout.readline() olen -= checksum_bytes(objtype, buf) - (treestr, treeobjid) = buf.split(None, 1) + (treestr, treeobjid) = buf.decode('ascii').split(None, 1) treeobjid = treeobjid.strip() assert treestr == 'tree' else: @@ -76,7 +77,7 @@ def checksum_object(repo, objid): raise subprocess.CalledProcessError(p.returncode, 'git cat-file') return treeobjid -def checksum_tree(repo, objid): +def checksum_tree(repo, path, objid): checksum_object(repo, objid) p = subprocess.Popen(['git', 'ls-tree', objid], stdin=DEVNULL, @@ -84,14 +85,14 @@ def checksum_tree(repo, objid): close_fds=True, cwd=repo) for line in p.stdout: - (mode, otype, subid, fname) = line.split(None, 3) + (mode, otype, subid, fname) = line.decode('ascii').split(None, 3) fname = fname.strip() if otype == 'blob': checksum_object(repo, subid) elif otype == 'tree': - checksum_tree(repo, subid) + checksum_tree(repo, os.path.join(path, fname), subid) elif otype == 'commit': - checksum_repo(os.path.join(repo, fname), subid) + checksum_repo(os.path.join(repo, path, fname), subid) else: assert False p.wait() @@ -100,7 +101,7 @@ def checksum_tree(repo, objid): def checksum_repo(repo, objid): treeid = checksum_object(repo, objid) - checksum_tree(repo, treeid) + checksum_tree(repo, '.', treeid) checksum_repo('.', opts.rev) -- 2.43.2