-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit.py
More file actions
20 lines (16 loc) · 816 Bytes
/
Copy pathcommit.py
File metadata and controls
20 lines (16 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from datetime import datetime
import hashlib
class Commit:
"""A commit object with message, timestamp, and unique hash."""
def __init__(self, message, hash_code=None, timestamp=None):
"""Initialize commit with message and optional hash/timestamp."""
self.timestamp = timestamp or datetime.now().isoformat()
self.message = message
self.hash_code = hash_code or self._generate_hash()
def _generate_hash(self):
"""Generate a short SHA-1 hash from timestamp and message."""
data = f"{self.timestamp}_{self.message}".encode()
return hashlib.sha1(data).hexdigest()[:10]
def __str__(self):
"""Return Git-like string representation of the commit."""
return f"commit {self.hash_code}\nDate: {self.timestamp}\n\n {self.message}"