Skip to content
Snippets Groups Projects
Commit 3c348ffb authored by Jack MacLauchlan CS2015's avatar Jack MacLauchlan CS2015
Browse files

can read hash of issues stored

parent 882f74d2
No related branches found
No related tags found
1 merge request!2Commit tree
package command;
import git.IssueReader;
import issueData.IssueRepository;
public class CommandLs implements Command {
@Override
public void execute() {
IssueRepository issueRepository = new IssueRepository();
issueRepository.getIssues().forEach(System.out::println);
// IssueRepository issueRepository = new IssueRepository();
// issueRepository.getIssues().forEach(System.out::println);
IssueReader issueReader = new IssueReader();
issueReader.walkTree();
}
}
package git;
import issueData.Issue;
import org.eclipse.jgit.treewalk.TreeWalk;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class IssueReader {
private IssueRepo repo;
private List<Issue> issues;
public IssueReader() {
this.repo = new IssueRepo();
this.issues = new ArrayList<>();
}
public void walkTree() {
try (TreeWalk treeWalk = new TreeWalk(repo.getRepository())) {
treeWalk.addTree(repo.getCurrentCommit().getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
if(issues.isEmpty() || !exists(treeWalk.getPathString())){
Issue issue = new Issue();
issue.setOriginalHash(trimPath(treeWalk.getPathString()));
issues.add(issue);
System.out.println("create");
}
// System.out.println(treeWalk.getPathString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean exists(String path){
for(Issue issue : issues) {
if(issue.getOriginalHash().equals(trimPath(path))) return true;
}
return false;
}
public String trimPath(String path){
return path.split("/")[0];
}
}
......@@ -57,7 +57,6 @@ public class IssueRepo {
commitBuilder.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[]{}));
}
//update issues branch ref to point to new commit
ObjectId newCommit = oi.insert(commitBuilder);
RefUpdate update = repository.updateRef("refs/heads/issues");
......@@ -88,7 +87,7 @@ public class IssueRepo {
return issuesTreeFormatter;
}
private RevCommit getCurrentCommit() throws IOException {
public RevCommit getCurrentCommit() throws IOException {
Ref issueRef = repository.findRef("refs/heads/issues");
RevCommit commit;
......@@ -117,5 +116,7 @@ public class IssueRepo {
}
}
public Repository getRepository() {
return repository;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment