Initial commit
This commit is contained in:
25
git/get_hash.py
Normal file
25
git/get_hash.py
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
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}")
|
||||
Reference in New Issue
Block a user