-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStagingArea.java
More file actions
51 lines (37 loc) · 1.37 KB
/
StagingArea.java
File metadata and controls
51 lines (37 loc) · 1.37 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
package gitlet;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import static gitlet.Utils.*;
public class StagingArea implements Serializable {
protected HashMap<String, Blob> files = new HashMap<String, Blob>();
protected HashMap<String, String> fileHash = new HashMap<String, String>();
protected ArrayList<String> removeFiles = new ArrayList<>();
protected Commit associatedCommit;
protected ArrayList<String> untracked = new ArrayList<String>();
public StagingArea() { }
public void stageAddition(String fileTxt) {
File f = new File(Repository.CWD, fileTxt);
Blob b = new Blob(fileTxt, f);
if (removeFiles.contains(fileTxt)) {
Commit parentCommit = Repository.commitHEAD();
StagingArea parStage = Repository.stageHEAD();
if (parStage.fileHash.get(fileTxt).equals(sha1(serialize(b)))) {
removeFiles.remove(fileTxt);
return;
}
removeFiles.remove(fileTxt);
}
files.put(sha1(serialize(b)), b);
fileHash.put(fileTxt, sha1(serialize(b)));
}
public void stageRemove(String fileTxt) {
if (!removeFiles.contains(fileTxt)) {
removeFiles.add(fileTxt);
}
}
public void addCommit(Commit c) {
associatedCommit = c;
}
}