本文整理匯總了Java中org.eclipse.jgit.revwalk.RevWalk類的典型用法代碼示例。如果您正苦於以下問題:Java RevWalk類的具體用法?Java RevWalk怎麽用?Java RevWalk使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RevWalk類屬於org.eclipse.jgit.revwalk包,在下文中一共展示了RevWalk類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isDirectory
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
/** 파일주소와 커밋아이디를 바탕으로 디렉토리인지 검사함.
* @param commitID
* @param filePath
* @return
*/
public boolean isDirectory(String commitID, String filePath){
if(filePath.length() == 0)
return true;
try{
ObjectId revId = this.localRepo.resolve(commitID);
TreeWalk treeWalk = new TreeWalk(this.localRepo);
treeWalk.addTree(new RevWalk(this.localRepo).parseTree(revId));
treeWalk.setRecursive(true);
while (treeWalk.next()) {
if(treeWalk.getPathString().equals(filePath)){
return false;
}
}
treeWalk.reset(new RevWalk(this.localRepo).parseTree(revId));
while (treeWalk.next()) {
if(treeWalk.getPathString().startsWith(filePath)){
return true;
}
}
}catch(Exception e){
return false;
}
return false;
}
示例2: simpleFileBrowser
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
/** 단순하게 커밋을 트리워크를 이용하여 당시 파일 내역을 출력.
* @param commit
* @return
*/
private String simpleFileBrowser(RevCommit commit){
String out = new String();
try
{
TreeWalk treeWalk = new TreeWalk(this.localRepo);
treeWalk.addTree(new RevWalk(this.localRepo).parseTree( commit));
while (treeWalk.next())
{
out+="--- /dev/null\n";
out+="+++ b/"+treeWalk.getPathString()+"\n";
out+= "+"+BlobUtils.getContent(this.localRepo, commit,treeWalk.getPathString().replace("\n", "\n+"));
out+="\n";
}
}finally{
return out;
}
}
示例3: getSingleBaseCommit
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
private GitRevisionInfo getSingleBaseCommit (RevWalk walk, List<RevCommit> commits) throws IOException {
while (commits.size() > 1) {
walk.reset();
for (RevCommit c : commits) {
walk.markStart(walk.parseCommit(c));
}
walk.setRevFilter(RevFilter.MERGE_BASE);
commits.clear();
for (RevCommit commit = walk.next(); commit != null; commit = walk.next()) {
commits.add(commit);
}
}
if (commits.isEmpty()) {
return null;
} else {
return getClassFactory().createRevisionInfo(commits.get(0), getRepository());
}
}
示例4: testJGitCheckout
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
public void testJGitCheckout () throws Exception {
File file1 = new File(workDir, "file1");
write(file1, "blablablabla");
Git git = new Git(repository);
org.eclipse.jgit.api.AddCommand cmd = git.add();
cmd.addFilepattern("file1");
cmd.call();
org.eclipse.jgit.api.CommitCommand commitCmd = git.commit();
commitCmd.setAuthor("author", "[email protected]");
commitCmd.setMessage("commit message");
commitCmd.call();
String commitId = git.log().call().iterator().next().getId().getName();
DirCache cache = repository.lockDirCache();
try {
DirCacheCheckout checkout = new DirCacheCheckout(repository, null, cache, new RevWalk(repository).parseCommit(repository.resolve(commitId)).getTree());
checkout.checkout();
} finally {
cache.unlock();
}
}
示例5: blockingPreviewDiff
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例6: doRefUpdate
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
@VisibleForTesting
static void doRefUpdate(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk revWalk,
String ref, ObjectId commitId) throws IOException {
if (ref.startsWith(Constants.R_TAGS)) {
final Ref oldRef = jGitRepository.exactRef(ref);
if (oldRef != null) {
throw new StorageException("tag ref exists already: " + ref);
}
}
final RefUpdate refUpdate = jGitRepository.updateRef(ref);
refUpdate.setNewObjectId(commitId);
final Result res = refUpdate.update(revWalk);
switch (res) {
case NEW:
case FAST_FORWARD:
// Expected
break;
default:
throw new StorageException("unexpected refUpdate state: " + res);
}
}
示例7: hasMatchingChanges
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
private boolean hasMatchingChanges(Revision from, Revision to, PathPatternFilter filter) {
try (RevWalk revWalk = new RevWalk(jGitRepository)) {
final List<DiffEntry> diff =
compareTrees(toTreeId(revWalk, from), toTreeId(revWalk, to), TreeFilter.ALL);
for (DiffEntry e : diff) {
final String path;
switch (e.getChangeType()) {
case ADD:
path = e.getNewPath();
break;
case MODIFY:
case DELETE:
path = e.getOldPath();
break;
default:
throw new Error();
}
if (filter.matches(path)) {
return true;
}
}
}
return false;
}
示例8: testDoUpdateRef
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
private static void testDoUpdateRef(String ref, ObjectId commitId, boolean tagExists) throws Exception {
final org.eclipse.jgit.lib.Repository jGitRepo = mock(org.eclipse.jgit.lib.Repository.class);
final RevWalk revWalk = mock(RevWalk.class);
final RefUpdate refUpdate = mock(RefUpdate.class);
when(jGitRepo.exactRef(ref)).thenReturn(tagExists ? mock(Ref.class) : null);
when(jGitRepo.updateRef(ref)).thenReturn(refUpdate);
when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.NEW);
GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);
when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.FAST_FORWARD);
GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId);
when(refUpdate.update(revWalk)).thenReturn(RefUpdate.Result.LOCK_FAILURE);
assertThatThrownBy(() -> GitRepository.doRefUpdate(jGitRepo, revWalk, ref, commitId))
.isInstanceOf(StorageException.class);
}
示例9: putColumnMetaAsTree
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
/**
*
* @param columns
* @param objectInserter
* @param tblTree
* @param walkTbl
* @return
* @throws SQLException
* @throws IOException
*/
public static ObjectId putColumnMetaAsTree(ResultSet columns,
ObjectInserter objectInserter, TreeFormatter tblTree, RevWalk walkTbl) throws SQLException, IOException {
// Add tree for the column Metadata
TreeFormatter clmnMetaTree = new TreeFormatter();
// Build tree for column attributs
buildMetaTree(columns, Consts.COLUMN_META_ATTRIBUTES, objectInserter, clmnMetaTree);
ObjectId clmnMetaTreeId = objectInserter.insert(clmnMetaTree);
objectInserter.flush();
tblTree.append(Consts.COLUMN_META, walkTbl.parseTree(clmnMetaTreeId));
// Add empty tree for the column content
TreeFormatter clmnDataTree = new TreeFormatter();
ObjectId clmnDataTreeId = objectInserter.insert(clmnDataTree);
objectInserter.flush();
tblTree.append(Consts.COLUMN_DATA, walkTbl.parseTree(clmnDataTreeId));
return clmnMetaTreeId;
}
示例10: getRevCommit
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
@Nullable
public RevCommit getRevCommit(ObjectId revId, boolean mustExist) {
if (commitCache == null)
commitCache = new HashMap<>();
RevCommit commit;
Optional<RevCommit> optional = commitCache.get(revId);
if (optional == null) {
try (RevWalk revWalk = new RevWalk(getRepository())) {
optional = Optional.fromNullable(GitUtils.parseCommit(revWalk, revId));
}
commitCache.put(revId, optional);
}
commit = optional.orNull();
if (mustExist && commit == null)
throw new ObjectNotFoundException("Unable to find commit associated with object id: " + revId);
else
return commit;
}
示例11: getCommits
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
/**
* Get commits belonging to this update, reversely ordered by commit traversing. The list of commit will remain
* unchanged even if tip of target branch changes. This assumption is key to our caching of code comment to
* to pull request relations. Check {@link DefaultCodeCommentRelationManager#findCodeComments(PullRequest)} for
* details
*
* @return
* commits belonging to this update ordered by commit id
*/
public List<RevCommit> getCommits() {
if (commits == null) {
commits = new ArrayList<>();
try (RevWalk revWalk = new RevWalk(getRequest().getWorkProject().getRepository())) {
revWalk.markStart(revWalk.parseCommit(ObjectId.fromString(getHeadCommitHash())));
revWalk.markUninteresting(revWalk.parseCommit(ObjectId.fromString(getBaseCommitHash())));
/*
* Instead of excluding commits reachable from target branch, we exclude commits reachable
* from the merge commit to achieve two purposes:
* 1. commits merged back into target branch after this update can still be included in this
* update
* 2. commits of this update will remain unchanged even if tip of the target branch changes
*/
revWalk.markUninteresting(revWalk.parseCommit(ObjectId.fromString(getMergeBaseCommitHash())));
revWalk.forEach(c->commits.add(c));
} catch (IOException e) {
throw new RuntimeException(e);
}
Collections.reverse(commits);
}
return commits;
}
示例12: testRemoveFile
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
@Test
public void testRemoveFile() throws IOException {
createDir("client");
addFileAndCommit("client/a.java", "a", "add a");
addFileAndCommit("client/b.java", "b", "add b");
createDir("server/src/com/example/a");
createDir("server/src/com/example/b");
addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
BlobEdits edits = new BlobEdits(Sets.newHashSet("/server/src/com/example/a//a.java"), Maps.newHashMap());
ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test delete");
try (RevWalk revWalk = new RevWalk(git.getRepository())) {
RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree));
assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/b/b.java", revTree));
assertNotNull(TreeWalk.forPath(git.getRepository(), "client/a.java", revTree));
assertNotNull(TreeWalk.forPath(git.getRepository(), "client/b.java", revTree));
}
}
示例13: shouldFailIfOldPathIsTreeWhenRename
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
@Test
public void shouldFailIfOldPathIsTreeWhenRename() throws IOException {
createDir("client");
addFileAndCommit("client/a.java", "a", "add a");
addFileAndCommit("client/b.java", "b", "add b");
createDir("server/src/com/example/a");
createDir("server/src/com/example/b");
addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a"), newBlobs);
ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user,
"test rename");
try (RevWalk revWalk = new RevWalk(git.getRepository())) {
RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
assertNotNull(TreeWalk.forPath(git.getRepository(), "client/c.java", revTree));
assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree));
}
}
示例14: testMergeWithoutConflicts
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
@Test
public void testMergeWithoutConflicts() throws Exception {
addFileAndCommit("initial", "", "initial");
git.checkout().setCreateBranch(true).setName("dev").call();
addFileAndCommit("dev1", "", "dev1");
addFileAndCommit("dev2", "", "dev2");
git.checkout().setName("master").call();
addFileAndCommit("master1", "", "master1");
addFileAndCommit("master2", "", "master2");
ObjectId masterId = git.getRepository().resolve("master");
ObjectId devId = git.getRepository().resolve("dev");
ObjectId mergeCommitId = GitUtils.merge(git.getRepository(), devId, masterId, false, user, "merge commit");
try ( RevWalk revWalk = new RevWalk(git.getRepository());
TreeWalk treeWalk = new TreeWalk(git.getRepository())) {
RevCommit mergeCommit = revWalk.parseCommit(mergeCommitId);
treeWalk.addTree(mergeCommit.getTree());
Set<String> files = new HashSet<>();
while (treeWalk.next()) {
files.add(treeWalk.getPathString());
}
assertEquals(Sets.newHashSet("initial", "dev1", "dev2", "master1", "master2"), files);
assertEquals(2, mergeCommit.getParentCount());
assertEquals(masterId, mergeCommit.getParent(0));
assertEquals(devId, mergeCommit.getParent(1));
}
}
示例15: getCommonAncestor
import org.eclipse.jgit.revwalk.RevWalk; //導入依賴的package包/類
/**
* Finds the common base for the given commit "a" and the given commit "b"
*
* @param walk
* - used to browse through commits
* @param a
* - commit "a"
* @param b
* - commit "b"
* @return the bese commit
* @throws IncorrectObjectTypeException
* @throws IOException
*/
private RevCommit getCommonAncestor(RevWalk walk, RevCommit a, RevCommit b)
throws IOException {
walk.reset();
walk.setRevFilter(RevFilter.MERGE_BASE);
walk.markStart(a);
walk.markStart(b);
final RevCommit base = walk.next();
if (base == null)
return null;
final RevCommit base2 = walk.next();
if (base2 != null) {
throw new NoMergeBaseException(MergeBaseFailureReason.MULTIPLE_MERGE_BASES_NOT_SUPPORTED,
MessageFormat.format(JGitText.get().multipleMergeBasesFor, a.name(), b.name(), base.name(), base2.name()));
}
return base;
}