-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommit.java
More file actions
99 lines (71 loc) · 2.08 KB
/
Commit.java
File metadata and controls
99 lines (71 loc) · 2.08 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package gitlet;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import static gitlet.Utils.*;
/** Represents a gitlet commit object.
* does at a high level.
*
* @author Matthew Koen
*/
public class Commit implements Serializable {
/**
* List all instance variables of the Commit class here with a useful
* comment above them describing what that variable represents and how that
* variable is used. We've provided one example for `message`.
*/
/** The message of this Commit. */
private String parent;
private HashMap<String, String> blobs;
private String iD;
private String time;
private String message;
public Commit(String message, String time) {
this.message = message;
this.time = time;
}
public Commit(String parent, String message, String time, HashMap<String, String> blobs) {
this.message = message;
this.time = time;
this.blobs = blobs;
this.parent = parent;
}
public String getParent() {
return parent;
}
public String getID() {
return iD;
}
public HashMap<String, String> getBlobs() {
return blobs;
}
public void updateBlobs(HashMap<String, String> k) {
blobs = k;
}
public static void saveBlobs(HashMap<String, String> blobs) {
for (String fileName: blobs.keySet()) {
File baseFile = join(Repository.CWD, fileName);
File blob = join(Repository.BLOB_DIR, blobs.get(fileName));
try {
blob.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
byte[] content = readContents(baseFile);
writeContents(blob, content);
}
}
public void updateParent(String parentSHA) {
parent = parentSHA;
}
public void updateID(String identifier) {
this.iD = identifier;
}
public String getTime() {
return time;
}
public String getMessage() {
return message;
}
}