本文整理汇总了Java中org.eclipse.jgit.revwalk.RevWalkUtils类的典型用法代码示例。如果您正苦于以下问题:Java RevWalkUtils类的具体用法?Java RevWalkUtils怎么用?Java RevWalkUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RevWalkUtils类属于org.eclipse.jgit.revwalk包,在下文中一共展示了RevWalkUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isRefBehind
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
boolean isRefBehind( Ref behind, Ref tracking ) throws IOException {
RevWalk walk = new RevWalk( _git.getRepository() );
try {
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();
}
}
开发者ID:Verigreen,项目名称:verigreen,代码行数:26,代码来源:JGitOperator.java
示例2: determineAheadBehindCounts
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
protected void determineAheadBehindCounts(Ref input, BranchModel branch, RevWalk walk, RevCommit localCommit) throws IOException {
Ref master = repo.getRef(REF_MASTER);
int ahead = 0, behind = 0;
if(!input.equals(master)){
RevCommit trackingCommit = walk.parseCommit(master.getObjectId());
walk.setRevFilter(RevFilter.MERGE_BASE);
walk.markStart(localCommit);
walk.markStart(trackingCommit);
RevCommit mergeBase = walk.next();
walk.reset();
walk.setRevFilter(RevFilter.ALL);
ahead = RevWalkUtils.count(walk, localCommit, mergeBase);
behind = RevWalkUtils.count(walk, trackingCommit, mergeBase);
}
branch.setAhead(ahead);
branch.setBehind(behind);
}
开发者ID:devhub-tud,项目名称:git-server,代码行数:22,代码来源:JGitRepositoryFacade.java
示例3: rebase
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
@Nullable
public static ObjectId rebase(Repository repository, ObjectId source, ObjectId target, PersonIdent committer) {
try ( RevWalk revWalk = new RevWalk(repository);
ObjectInserter inserter = repository.newObjectInserter();) {
RevCommit sourceCommit = revWalk.parseCommit(source);
RevCommit targetCommit = revWalk.parseCommit(target);
revWalk.setRevFilter(RevFilter.NO_MERGES);
List<RevCommit> commits = RevWalkUtils.find(revWalk, sourceCommit, targetCommit);
Collections.reverse(commits);
RevCommit headCommit = targetCommit;
for (RevCommit commit: commits) {
ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE.newMerger(repository, true);
merger.setBase(commit.getParent(0));
if (merger.merge(headCommit, commit)) {
if (!headCommit.getTree().getId().equals(merger.getResultTreeId())) {
CommitBuilder newCommit = new CommitBuilder();
newCommit.setAuthor(commit.getAuthorIdent());
newCommit.setCommitter(committer);
newCommit.setParentId(headCommit);
newCommit.setMessage(commit.getFullMessage());
newCommit.setTreeId(merger.getResultTreeId());
headCommit = revWalk.parseCommit(inserter.insert(newCommit));
}
} else {
return null;
}
}
inserter.flush();
return headCommit.copy();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:34,代码来源:GitUtils.java
示例4: countCommits
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
public int countCommits(Repository repository, String branch) throws Exception {
RevWalk walk = new RevWalk(repository);
try {
Ref ref = repository.findRef(REMOTE_REFS_PREFIX + branch);
ObjectId objectId = ref.getObjectId();
RevCommit start = walk.parseCommit(objectId);
walk.setRevFilter(RevFilter.NO_MERGES);
return RevWalkUtils.count(walk, start, null);
} finally {
walk.dispose();
}
}
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:13,代码来源:GitHelper.java
示例5: countCommits
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
@Override
public int countCommits(Repository repository, String branch) throws Exception {
RevWalk walk = new RevWalk(repository);
try {
Ref ref = repository.findRef(REMOTE_REFS_PREFIX + branch);
ObjectId objectId = ref.getObjectId();
RevCommit start = walk.parseCommit(objectId);
walk.setRevFilter(RevFilter.NO_MERGES);
return RevWalkUtils.count(walk, start, null);
} finally {
walk.dispose();
}
}
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:14,代码来源:GitServiceImpl.java
示例6: findParallel
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
private Optional<Version> findParallel(
RevWalk walk, RevCommit head, TaggedVersion candidate, Set<RevCommit> tagged) {
try {
walk.reset();
walk.setRevFilter(RevFilter.MERGE_BASE);
walk.markStart(head);
walk.markStart(candidate.getCommit());
RevCommit mergeBase = walk.next();
walk.reset();
walk.setRevFilter(RevFilter.ALL);
boolean taggedSinceMergeBase =
RevWalkUtils.find(walk, head, mergeBase)
.stream()
.filter(tagged::contains)
.findAny()
.isPresent();
if (mergeBase != null
&& !taggedSinceMergeBase
&& !mergeBase.equals(head)
&& !mergeBase.equals(candidate.getCommit())) {
return Optional.of(Versions.getNormal(candidate.getVersion()));
} else {
return Optional.empty();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
开发者ID:ajoberstar,项目名称:reckon,代码行数:32,代码来源:GitInventorySupplier.java
示例7: merge
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
/**
* Merge the list of check-ins into the destination branch. The list of
* check-ins supplied to the method constitutes the complete list of
* check-ins that should exist on the destination branch. If the
* destination branch contains any additional check-ins, or order of
* existing check-ins does not exactly match the order of the supplied
* list, an alternate branch will be created by branching from the point
* at which the list diverges from the existing branch.
*
* @param branch Destination branch
* @param alt Alternate branch created if the list diverges from destination branch
* @param list Complete list of changes to be merged
* @param existingList List of existing check-ins on the branch
* @return TRUE if an alternate branch was created
*/
public boolean merge(String branch, String alt, List<CMnCheckIn> list, List<CMnCheckIn> existingList) throws Exception {
Date startDate = new Date();
boolean diverged = false;
// Locate the last check-in where the existing branch is valid
RevCommit lastMerge = null;
int idx = 0;
Iterator listIter = list.iterator();
Iterator existingIter = existingList.iterator();
while (listIter.hasNext() && existingIter.hasNext()) {
// Get the two current check-ins
CMnCheckIn desired = (CMnCheckIn) listIter.next();
CMnCheckIn existing = (CMnCheckIn) existingIter.next();
RevCommit desiredCommit = getCommit(desired.getId());
RevCommit existingCommit = getCommit(existing.getId());
int depth = RevWalkUtils.count(revWalk, desiredCommit, existingCommit);
logger.info("Merge depth of " + desired.getId() + ": " + depth);
}
// Display the elapsed time for this operation
CMnCmdLineTool.logElapsedTime(logger, startDate, new Date(), "Merge completed: ");
return diverged;
}
开发者ID:ModelN,项目名称:build-management,代码行数:42,代码来源:CMnGitServer.java
示例8: getInventory
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
@Override
public VcsInventory getInventory() {
try (RevWalk walk = new RevWalk(repo)) {
walk.setRetainBody(false);
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);
}
}
开发者ID:ajoberstar,项目名称:reckon,代码行数:59,代码来源:GitInventorySupplier.java
示例9: listUnmergedCommits
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
@Nonnull
public static List<RevCommit> listUnmergedCommits(AnyObjectId sourceHead, AnyObjectId masterHead, ObjectReader reader) throws IOException {
try(RevWalk rw = new RevWalk(reader)) {
return unmodifiableList(RevWalkUtils.find(rw, rw.lookupCommit(sourceHead), rw.lookupCommit(masterHead)));
}
}
开发者ID:beijunyi,项目名称:ParallelGit,代码行数:7,代码来源:CommitUtils.java
示例10: getProjectVersion
import org.eclipse.jgit.revwalk.RevWalkUtils; //导入依赖的package包/类
public String getProjectVersion(File repoDir) throws IOException, GitAPIException {
Git git = Git.open(repoDir);
Repository repo = git.getRepository();
// Find base commit between current branch and "master":
String branch = repo.getBranch();
RevCommit base = CommitUtils.getBase(repo, "master", branch);
CommitCountFilter count = new CommitCountFilter();
CommitFinder finder = new CommitFinder(repo).setFilter(count);
finder.findBetween(branch, base);
long commitsSinceBase = count.getCount();
// Find tags in "master" before base commit:
RevWalk rw = new RevWalk(repo);
rw.markStart(base);
rw.setRetainBody(false);
Ref master = repo.getRef("master");
List<Ref> masterAsList = Arrays.asList(master);
List<Ref> tags = git.tagList().call();
Map<RevCommit, Ref> masterTags = new HashMap<RevCommit, Ref>();
for (Ref tag : tags) {
tag = repo.peel(tag);
ObjectId commitID = tag.getPeeledObjectId();
if (commitID == null) continue;
RevCommit commit = rw.parseCommit(commitID);
// Only remember tags reachable from "master":
if (!RevWalkUtils.findBranchesReachableFrom(commit, rw, masterAsList).isEmpty()) {
masterTags.put(commit, tag);
}
}
// Find the shortest distance in commits between base tag in "master":
long commitsBetweenBaseAndTag = Long.MAX_VALUE;
String tagName = "";
for (RevCommit tagCommit : masterTags.keySet()) {
count.reset();
finder.findBetween(base, tagCommit);
if (count.getCount() < commitsBetweenBaseAndTag) {
commitsBetweenBaseAndTag = count.getCount();
tagName = masterTags.get(tagCommit).getName();
}
}
if (commitsBetweenBaseAndTag == Long.MAX_VALUE) {
// If no tag, get total number of commits:
commitsBetweenBaseAndTag = repo.getRefDatabase().getRefs("").size();
}
long commitsSinceLastMasterTag = commitsSinceBase + commitsBetweenBaseAndTag;
// Construct version string:
String version = branch.equals("master") ? "" : (branch + "-");
if (tagName.startsWith("refs/tags/")) {
tagName = tagName.substring("refs/tags/".length());
}
// v1.1 -> 1.1
if (tagName.matches("v\\d+.*")) {
tagName = tagName.substring(1);
}
if (tagName.isEmpty()) {
version = "0";
}
version += tagName + ((!tagonly) ? "." + commitsSinceLastMasterTag : "");
return version;
}
开发者ID:Hunternif,项目名称:JGitVersion,代码行数:65,代码来源:JGitVersionTask.java
注:本文中的org.eclipse.jgit.revwalk.RevWalkUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论