/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * * @return * @throws IOException * @throws GitException */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException { Map<ObjectId, Revision> revisions = new HashMap<ObjectId, Revision>(); List<Branch> branches = git.getRemoteBranches(); for (Branch b : branches) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } return revisions.values(); }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * * @return * @throws IOException * @throws GitException */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException { Map<ObjectId, Revision> revisions = new HashMap<ObjectId, Revision>(); List<Branch> branches = git.getRemoteBranches(); for (Branch b : branches) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } return revisions.values(); }
/** * This method is aimed to normalize all the branches to the same naming * convention, as {@link GitClient#getBranchesContaining(String, boolean)} * returns branches with "remotes/" prefix. * @param branches branches, retrieved from git client * @return list of branches without the "remote/" prefix. */ private List<Branch> normalizeBranches(List<Branch> branches) { final List<Branch> normalBranches = new ArrayList<>(branches.size()); final String remotesPrefix = "remotes/"; for (Branch initialBranch : branches) { final String initialBranchName = initialBranch.getName(); final Branch normalBranch; if (initialBranchName.startsWith(remotesPrefix)) { final String normalName = initialBranchName.substring(remotesPrefix.length()); normalBranch = new Branch(normalName, initialBranch.getSHA1()); } else { normalBranch = initialBranch; } normalBranches.add(normalBranch); } return normalBranches; }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * @return list of revisions * @throws IOException on input or output error * @throws GitException on git error * @throws InterruptedException when interrupted */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException, InterruptedException { Map<ObjectId, Revision> revisions = new HashMap<>(); for (Branch b : git.getRemoteBranches()) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } for (String tag : git.getTagNames(null)) { String tagRef = Constants.R_TAGS + tag; ObjectId objectId = git.revParse(tagRef); Revision r = revisions.get(objectId); if (r == null) { r = new Revision(objectId); revisions.put(objectId, r); } r.getBranches().add(new Branch(tagRef, objectId)); } return revisions.values(); }
assertEquals(1, revs.iterator().next().getBranches().size()); assertEquals(singleBranch, revs.iterator().next().getBranches().iterator().next().getName()); assertEquals(fetchHead, revs.iterator().next().getBranches().iterator().next().getSHA1()); assertEquals(1, revs.iterator().next().getBranches().size()); assertEquals(patchsetRefspec, revs.iterator().next().getBranches().iterator().next().getName()); assertEquals(patchsetRevision, revs.iterator().next().getBranches().iterator().next().getSHA1());