26 lines
664 B
Python
26 lines
664 B
Python
|
|
import hashlib
|
|
import zlib
|
|
import sys
|
|
|
|
def calculate_git_hash(file_path):
|
|
# Read the file content
|
|
with open(file_path, 'rb') as f:
|
|
content = f.read()
|
|
|
|
# Decompress the zlib-compressed content
|
|
decompressed_content = zlib.decompress(content)
|
|
|
|
# Calculate the SHA-1 hash of the decompressed content
|
|
sha1 = hashlib.sha1(decompressed_content).hexdigest()
|
|
|
|
return sha1
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) != 2:
|
|
print("Usage: python get_hash.py <path_to_git_object_file>")
|
|
else:
|
|
file_path = sys.argv[1]
|
|
hash_value = calculate_git_hash(file_path)
|
|
print(f"{hash_value}")
|