This commit is contained in:
Suzanne Soy 2021-02-21 21:40:21 +00:00
parent b62032e931
commit 7bda175b43
2 changed files with 37 additions and 13 deletions

View File

@ -19,10 +19,24 @@ jobs:
experimental-features = nix-command flakes
- name: build dependencies
run: nix build path://$PWD/
- name: python3 --version
run: PATH="$PWD/result/bin" python3 --version
- name: awk --version
run: PATH="$PWD/result/bin" awk --version
- name: sh --version
run: PATH="$PWD/result/bin" sh --version
- name: sha256sum --version
run: PATH="$PWD/result/bin" sha256sum --version
- name: sqlite3 --version
run: PATH="$PWD/result/bin" sqlite3 --version
- name: git --version
run: PATH="$PWD/result/bin" git --version
- name: Run tests
run: PATH="$PWD/result/bin:$PATH" ./test.py
run: PATH="$PWD/result/bin" python3 ./test.py
- name: Run tests
run: PATH="$PWD/result/bin" ./test.py
run: PATH="$PWD/result/bin" python3 ./test.py
- uses: actions/upload-artifact@v2
with:
name: debug-git.tar.gz

View File

@ -5,12 +5,14 @@ import sys
import subprocess
def hashFile(filename):
#print("hashFile " + filename)
return subprocess.check_output(['sha256sum', '--binary', '--zero', filename])[0:64]
result = subprocess.check_output(['sha256sum', '--binary', '--zero', filename])[0:64]
print("hashFile("+x+") = "+str(result), file=sys.stderr)
return result
def hash1(bytes):
#print("hash1 " + bytes)
return subprocess.check_output(['sha256sum', '--binary', '--zero'], input=bytes)[0:64]
result = subprocess.check_output(['sha256sum', '--binary', '--zero'], input=bytes)[0:64]
print("hash1("+x+") = "+str(result), file=sys.stderr)
return result
#
# TODO: use this to get the hashes and names for all roots of the DAG (commits that are reachable only through one (or several) direct branch names, but not transitively as ancestors of other commits)
@ -35,10 +37,14 @@ def ref_exists(path, ref):
def hashGit(path):
FETCH_HEAD = "FETCH_HEAD" if ref_exists(path, "FETCH_HEAD") else ''
HEAD = "HEAD" if ref_exists(path, "HEAD") else ''
return subprocess.check_output(['sh', '-c', git_command.format(HEAD=HEAD, FETCH_HEAD=FETCH_HEAD)], cwd=path)
result = subprocess.check_output(['sh', '-c', git_command.format(HEAD=HEAD, FETCH_HEAD=FETCH_HEAD)], cwd=path)
print("hashGit("+x+") = "+str(result), file=sys.stderr)
return result
def hashSqlite3(path):
return subprocess.check_output(['sh', '-c', 'sqlite3 "$1" .dump | sort | sha256sum --binary --zero', '--', os.path.abspath(path)])
result= subprocess.check_output(['sh', '-c', 'sqlite3 "$1" .dump | sort | sha256sum --binary --zero', '--', os.path.abspath(path)])
print("hashSqlite3("+x+") = "+str(result), file=sys.stderr)
return result
def ignore_exitcode(cmd, **kwargs):
try:
@ -52,24 +58,28 @@ def is_git(x):
ignore_exitcode("git rev-parse --is-inside-work-tree 2>/dev/null", cwd=x, shell=True).strip() == b'true')
# TODO: if a file which is inside a larger git dir is passed on the CLI, this still returns True :-(
def recur(x):
def recur(depth, x):
#print(x)
# initial list of paths
if isinstance(x, list):
return b'root\0' + b''.join(recur(os.path.abspath(path)) + b' ' + path.encode('utf-8') + b'\0' for path in sorted(x))
print("ROOT " + str(depth) + ' ' + x, file=sys.stderr)
return b'root\0' + b''.join(recur(depth + 1, os.path.abspath(path)) + b' ' + path.encode('utf-8') + b'\0' for path in sorted(x))
# GIT repo
elif is_git(x):
#print("GIT DIR " + x, file=sys.stderr)
print("GIT DIR " + str(depth) + ' ' + x, file=sys.stderr)
return hash1(b'git-versioned folder\0' + hashGit(x))
# directory
elif os.path.isdir(x):
return hash1(b'directory\0' + b''.join(recur(os.path.join(x, entry)) + b' ' + entry.encode('utf-8') + b'\0' for entry in os.listdir(x)))
print("DIR " + str(depth) + ' ' + x, file=sys.stderr)
return hash1(b'directory\0' + b''.join(recur(depth + 1, os.path.join(x, entry)) + b' ' + entry.encode('utf-8') + b'\0' for entry in os.listdir(x)))
elif b'SQLite 3.x database' in subprocess.check_output(["file", x]):
print("SQLITE3 " + str(depth) + ' ' + x, file=sys.stderr)
return hashSqlite3(x)
# Just a file
elif os.path.isfile(x):
print("PLAIN FILE " + str(depth) + ' ' + x, file=sys.stderr)
return hashFile(x)
else:
sys.exit("unknown file type for %s" % os.path.abspath(x))
print(hash1(recur(sys.argv[1:])).decode('utf-8'))
print(hash1(recur(0, sys.argv[1:])).decode('utf-8'))