Skip to content

Commit

Permalink
add queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ffanyt authored Jan 27, 2023
1 parent 5fdacfe commit f915eb6
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions proj2/gitlet/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Queue;

import static gitlet.Utils.*;

Expand Down Expand Up @@ -477,7 +478,8 @@ private static Commit merge2NewCommit(Commit split, Commit head, Commit other, S
return mergeCommit;
}
private static void updateStage(Commit split,
Commit head, Commit other, List allFileName) {
Commit head, Commit other,
List allFileName) {
HashMap splitBlob = split.getBlob();
HashMap headBlob = head.getBlob();
HashMap otherBlob = other.getBlob();
Expand Down Expand Up @@ -585,7 +587,8 @@ private static void rmStage(String blobHash) {
Stage stage = new Stage(blob);
stage.saveRemove();
}
private static void conflict(String headBlobHash, String otherBlobHash, boolean head, boolean other) {
private static void conflict(String headBlobHash,
String otherBlobHash, boolean head, boolean other) {
String headContent;
String otherContent;
Blob headBlob = null;
Expand Down Expand Up @@ -639,10 +642,10 @@ private static void checkIfSplitDiffOther(Commit split, Commit given) {
private static Commit findSplitPoint(Commit curCommit, Commit givenCommit) {
List curParentList = curCommit.getParent();
String curHash = curCommit.getHashcode();
HashMap curParentHashM = getParentMap(curParentList, curHash);
HashMap curParentHashM = getParentMap(curCommit, curHash);
List givenParentList = givenCommit.getParent();
String givenHash = givenCommit.getHashcode();
HashMap givenParentHashM = getParentMap(givenParentList, givenHash);
HashMap givenParentHashM = getParentMap(givenCommit, givenHash);
Object splitHash = null;
for (int i = 0; curParentHashM.containsKey(i); i++) {
Object parent = curParentHashM.get(i);
Expand All @@ -669,17 +672,36 @@ private static void getFileFromBlob(HashMap blobNode, List list) {
}
}
}
private static HashMap getParentMap(List parentList, String cur) {
private static HashMap getParentMap(Commit curCommit, String cur) {
int count = 0;
Queue<Commit> a = null;
a.add(curCommit);
List parentList;
HashMap parentHashMap = new HashMap<Integer, String>();
parentHashMap.put(count, cur);
while (parentList.size() != 0) {
while (!a.isEmpty()){
count += 1;
Object parentID = parentList.get(0);
parentHashMap.put(count, parentID.toString());
Commit curParentCommit = Commit.readCommit(parentID.toString());
parentList = curParentCommit.getParent();
parentList = a.poll().getParent();
for (int i = 0; i < parentList.size(); i++) {
Object parentID = parentList.get(i);
parentHashMap.put(count, parentID.toString());
Commit curParentCommit = Commit.readCommit(parentID.toString());
a.add(curParentCommit);
}

}
// while (parentList.size() != 0) {
// count += 1;
// parentList = a.poll().getParent();
// for (int i = 0; i < parentList.size(); i++) {
// Object parentID = parentList.get(i);
// parentHashMap.put(count, parentID.toString());
// Commit curParentCommit = Commit.readCommit(parentID.toString());
// a.add(curParentCommit);
// parentList = curParentCommit.getParent();
// }
//
// }
return parentHashMap;
}
private static String readHeadBranch() {
Expand Down

0 comments on commit f915eb6

Please sign in to comment.