forked from Ghosh-Anisha/OOAD---Version-Control-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commit.java
58 lines (49 loc) · 1.61 KB
/
Commit.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class Commit implements Serializable {
private String ownHash;
private String parentHash;
private String message;
private String datetime;
private HashMap<String, String> blobs;
public Commit(String msg, HashMap<String, String> blobMap, String parent) {
LocalDateTime current = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
message = msg;
datetime = current.format(formatter);
blobs = blobMap;
parentHash = parent;
ownHash = calcHash();
SerializeUtils.writeStringToFile(globalLog(), ".agile/global-log/gl.txt", true);
}
public String calcHash() {
byte[] commitObj = SerializeUtils.toByteArray(this);
return Utils.sha1(commitObj);
}
public String getOwnHash() {
return ownHash;
}
public String getParentHash() {
return parentHash;
}
public String getMessage() {
return message;
}
public String getDatetime() {
return datetime;
}
public HashMap<String, String> getBlobs() {
return blobs;
}
public String globalLog() {
String firstLine = "===\n";
String secondLine = "Commit " + ownHash + "\n";
String thirdLine = datetime + "\n";
String fourthLine = message + "\n";
String fifthLine = "\n";
String allLines = firstLine + secondLine + thirdLine + fourthLine + fifthLine;
return allLines;
}
}