Print hashed objects
This commit is contained in:
parent
9634544d68
commit
a010615cf2
13
ugit/cli.py
13
ugit/cli.py
@ -1,6 +1,8 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from . import data
|
||||
|
||||
|
||||
@ -18,6 +20,10 @@ def parse_args():
|
||||
init_parser = commands.add_parser("init")
|
||||
init_parser.set_defaults(func=init)
|
||||
|
||||
cat_file_parser = commands.add_parser("cat-file")
|
||||
cat_file_parser.set_defaults(func=cat_file)
|
||||
cat_file_parser.add_argument("object")
|
||||
|
||||
hash_object_parser = commands.add_parser("hash-object")
|
||||
hash_object_parser.set_defaults(func=hash_object)
|
||||
hash_object_parser.add_argument("file")
|
||||
@ -33,3 +39,8 @@ def init(args):
|
||||
def hash_object(args):
|
||||
with open(args.file, "rb") as f:
|
||||
print(data.hash_object(f.read()))
|
||||
|
||||
|
||||
def cat_file(args):
|
||||
sys.stdout.flush()
|
||||
sys.stdout.buffer.write(data.get_object(args.object))
|
||||
|
@ -15,3 +15,8 @@ def hash_object(data):
|
||||
with open(f"{GIT_DIR}/objects/{oid}", "wb") as out:
|
||||
out.write(data)
|
||||
return oid
|
||||
|
||||
|
||||
def get_object(oid):
|
||||
with open(f"{GIT_DIR}/objects/{oid}", "rb") as f:
|
||||
return f.read()
|
||||
|
Loading…
Reference in New Issue
Block a user