-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommits.py
More file actions
28 lines (22 loc) · 853 Bytes
/
commits.py
File metadata and controls
28 lines (22 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import file_utils
from time_utils import *
from hash_utils import *
class Commit:
empty = ()
def __init__(self, msg="", parent=empty, time=None):
self.message = msg
if time:
self.time_stamp = time
else:
self.time_stamp = get_current_time()
self.parent = parent
self.blobs = {}
def add_file(self, filename):
file = os.path.join(file_utils.get_staging_dir(), filename)
blob_id = file_utils.write_blob(file)
self.blobs[filename] = blob_id
def clean_str(self):
return "commit " + hash_commit(self) + "\n" + "Date: " + get_time_stamp(self.time_stamp) + "\n" + self.message# + "\n" + str(self.blobs)
def __str__(self):
return "Date: " + get_time_stamp(self.time_stamp) + "\n\n\t" + self.message + "\n" + str(self.blobs)