List of usage examples for org.eclipse.jgit.revwalk RevWalkUtils count
public static int count(final RevWalk walk, final RevCommit start, final RevCommit end) throws MissingObjectException, IncorrectObjectTypeException, IOException
start
until a commit that is reachable from end
is encountered. From source file:com.github.pascalgn.maven.properties.GitProperties.java
License:Apache License
private void addProperties(Map<String, String> map) throws IOException { Repository repository = new FileRepositoryBuilder().setWorkTree(new File(".")).readEnvironment() .findGitDir().setMustExist(true).build(); logger.debug("Using git repository: " + repository.getDirectory()); ObjectId head = repository.resolve("HEAD"); if (head == null) { throw new IllegalStateException("No such revision: HEAD"); }//from w w w . j ava2 s . co m String branch = nullToEmpty(repository.getBranch()); map.put("git.branch", branch); String commitId = head.name(); map.put("git.commit.id", commitId); String commitIdAbbrev = repository.newObjectReader().abbreviate(head).name(); map.put("git.commit.id.abbrev", commitIdAbbrev); RevWalk walk = new RevWalk(repository); walk.setRetainBody(false); RevCommit headCommit = walk.parseCommit(head); int count = RevWalkUtils.count(walk, headCommit, null); map.put("git.count", Integer.toString(count)); String color = commitId.substring(0, 6); map.put("git.commit.color.value", color); map.put("git.commit.color.name", ColorHelper.getColorName(color)); map.put("git.commit.color.lightness", Integer.toString(ColorHelper.getLightness(color))); map.put("git.commit.color.foreground", ColorHelper.getForeground(color)); map.put("git.build.datetime.simple", getFormattedDate()); }
From source file:com.verigreen.jgit.JGitOperator.java
License:Apache License
boolean isRefBehind(Ref behind, Ref tracking) throws IOException { RevWalk walk = new RevWalk(_git.getRepository()); try {/*from www . j a va 2 s. c o m*/ RevCommit behindCommit = walk.parseCommit(behind.getObjectId()); RevCommit trackingCommit = walk.parseCommit(tracking.getObjectId()); walk.setRevFilter(RevFilter.MERGE_BASE); walk.markStart(behindCommit); walk.markStart(trackingCommit); RevCommit mergeBase = walk.next(); walk.reset(); walk.setRevFilter(RevFilter.ALL); int aheadCount = RevWalkUtils.count(walk, behindCommit, mergeBase); int behindCount = RevWalkUtils.count(walk, trackingCommit, mergeBase); return behindCount > aheadCount ? true : false; } catch (Throwable e) { throw new RuntimeException(String.format("Failed to check if [%s] behind [%s]", behind, tracking), e); } finally { walk.dispose(); } }
From source file:org.ajoberstar.reckon.core.git.GitInventorySupplier.java
License:Apache License
@Override public VcsInventory getInventory() { try (RevWalk walk = new RevWalk(repo)) { walk.setRetainBody(false);/*www. ja v a 2 s.com*/ ObjectId headObjectId = repo.getRefDatabase().getRef("HEAD").getObjectId(); if (headObjectId == null) { logger.debug("No HEAD commit. Presuming repo is empty."); return new VcsInventory(null, null, null, null, 0, null, null); } logger.debug("Found HEAD commit {}", headObjectId); RevCommit headCommit = walk.parseCommit(headObjectId); Set<TaggedVersion> taggedVersions = getTaggedVersions(walk); logger.debug("Found tagged versions: {}", taggedVersions); Version currentVersion = findCurrent(headCommit, taggedVersions.stream()).map(TaggedVersion::getVersion) .orElse(null); TaggedVersion baseNormal = findBase(walk, headCommit, taggedVersions.stream().filter(TaggedVersion::isNormal)); TaggedVersion baseVersion = findBase(walk, headCommit, taggedVersions.stream()); int commitsSinceBase = RevWalkUtils.count(walk, headCommit, baseNormal.getCommit()); Set<TaggedVersion> parallelCandidates = findParallelCandidates(walk, headCommit, taggedVersions); Set<RevCommit> taggedCommits = taggedVersions.stream().map(TaggedVersion::getCommit) .collect(Collectors.toSet()); Set<Version> parallelVersions = parallelCandidates.stream() .map(version -> findParallel(walk, headCommit, version, taggedCommits)) // TODO Java 9 Optional::stream .flatMap(opt -> opt.isPresent() ? Stream.of(opt.get()) : Stream.empty()) .collect(Collectors.toSet()); Set<Version> claimedVersions = taggedVersions.stream().map(TaggedVersion::getVersion) .collect(Collectors.toSet()); return new VcsInventory(headObjectId.getName(), currentVersion, baseVersion.getVersion(), baseNormal.getVersion(), commitsSinceBase, parallelVersions, claimedVersions); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.eclipse.egit.gitflow.op.GitFlowOperation.java
License:Open Source License
private int getAheadOfDevelopCount(String branchName) throws IOException { String parentBranch = repository.getConfig().getDevelop(); Ref develop = repository.findBranch(parentBranch); Ref branch = repository.findBranch(branchName); RevWalk walk = new RevWalk(repository.getRepository()); RevCommit branchCommit = walk.parseCommit(branch.getObjectId()); RevCommit developCommit = walk.parseCommit(develop.getObjectId()); RevCommit mergeBase = findCommonBase(walk, branchCommit, developCommit); walk.reset();/* ww w. j ava 2 s . c o m*/ walk.setRevFilter(RevFilter.ALL); int aheadCount = RevWalkUtils.count(walk, branchCommit, mergeBase); return aheadCount; }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
private static boolean isNonTrackingBranchAhead(Repository repo, String remote, IProgressMonitor monitor) throws URISyntaxException, InvocationTargetException, IOException { RemoteConfig remoteConfig = new RemoteConfig(repo.getConfig(), remote); FetchResult fetchResult = fetch(remoteConfig, repo, monitor); Ref ref = fetchResult.getAdvertisedRef(Constants.HEAD); if (ref == null) { return false; }//from www. j a v a 2 s .c om Ref currentBranchRef = repo.getRef(repo.getBranch()); RevWalk walk = new RevWalk(repo); RevCommit localCommit = walk.parseCommit(currentBranchRef.getObjectId()); RevCommit trackingCommit = walk.parseCommit(ref.getObjectId()); walk.setRevFilter(RevFilter.MERGE_BASE); walk.markStart(localCommit); walk.markStart(trackingCommit); RevCommit mergeBase = walk.next(); walk.reset(); walk.setRevFilter(RevFilter.ALL); int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase); return aheadCount > 0; }