private Iterable<RevCommit> getCommitsFromTag(String treeName) { try { List<Ref> call = git.tagList().call(); Iterable<RevCommit> logs = null; for (Ref ref : call) { if (ref.getName().equals(treeName)) { LogCommand log = git.log(); Ref peeledRef = repository.peel(ref); if (peeledRef.getPeeledObjectId() != null) { log.add(peeledRef.getPeeledObjectId()); } else { log.add(ref.getObjectId()); } logs = log.call(); return logs; } } return null; } catch (GitAPIException e) { throw new VisMinerAPIException(e.getMessage(), e); } catch (MissingObjectException e) { throw new VisMinerAPIException(e.getMessage(), e); } catch (IncorrectObjectTypeException e) { throw new VisMinerAPIException(e.getMessage(), e); } }
/** * find out which branch that specified commit come from. * * @param commit * @return branch name. * @throws GitException */ public String getBranchName(RevCommit commit) throws GitException { Set<Entry<String, Ref>> refs = repository.getAllRefs().entrySet(); if (this.masterRef == null) { this.masterRef = this.findMasterRef(); } boolean commitBelongsToBranch; boolean commitBelongsToMaster; List<String> foundInBranches = new ArrayList<String>(); try { RevWalk walker = new RevWalk(this.repository); RevCommit targetCommit = walker.parseCommit(this.repository.resolve(commit.getName())); for (Entry<String, Ref> ref : refs) { if (ref.getKey().startsWith(Constants.R_HEADS) && !ref.getKey().equals(this.masterRef)) { commitBelongsToBranch = walker.isMergedInto(targetCommit, walker.parseCommit(ref.getValue().getObjectId())); commitBelongsToMaster = false; if (this.masterRef != null) { commitBelongsToMaster = walker.isMergedInto(targetCommit, walker.parseCommit(this.masterRef.getObjectId())); } if (commitBelongsToBranch && !commitBelongsToMaster) { foundInBranches.add(ref.getValue().getName()); } } } } catch (GitException | MissingObjectException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IncorrectObjectTypeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (foundInBranches.size() == 0) { return "master"; } return StringUtils.join(foundInBranches, ", "); }