當前位置: 首頁>>代碼示例>>Java>>正文


Java RevTree類代碼示例

本文整理匯總了Java中org.eclipse.jgit.revwalk.RevTree的典型用法代碼示例。如果您正苦於以下問題:Java RevTree類的具體用法?Java RevTree怎麽用?Java RevTree使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RevTree類屬於org.eclipse.jgit.revwalk包,在下文中一共展示了RevTree類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fillLastModifiedCommits

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private void fillLastModifiedCommits(ObjectId start, String basePath) throws IOException, GitAPIException {
    Map<String, ObjectId> objects = lastModifiedCommits.get(start);
    if (objects == null) {
        objects = new TreeMap<>();
    }
    DiffFormatter diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
    diffFmt.setRepository(getGitRepository());
    LogCommand log = new Git(getGitRepository()).log();
    if (!basePath.isEmpty()) {
        log.addPath(basePath);
    }
    for(RevCommit c: log.call()) {
        final RevTree a = c.getParentCount() > 0 ? c.getParent(0).getTree() : null;
        final RevTree b = c.getTree();

        for(DiffEntry diff: diffFmt.scan(a, b)) {
            objects.put(diff.getNewPath(), c.getId());
        }
    }
    lastModifiedCommits.put(start, objects);
}
 
開發者ID:naver,項目名稱:svngit,代碼行數:22,代碼來源:GitFS.java

示例2: getHeadFiles

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private List<IdentifiableResource> getHeadFiles (Repository aRepository, String... aSearchPaths) {
  List<String> searchPaths = Arrays.asList(aSearchPaths);
  List<IdentifiableResource> resources = new ArrayList<>();
  try (ObjectReader reader = aRepository.newObjectReader(); RevWalk walk = new RevWalk(reader); TreeWalk treeWalk = new TreeWalk(aRepository,reader);) {
    final ObjectId id = aRepository.resolve(Constants.HEAD);
    RevCommit commit = walk.parseCommit(id);
    RevTree tree = commit.getTree();
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    while (treeWalk.next()) {
      String path = treeWalk.getPathString();        
      if(searchPaths.stream().anyMatch((sp)->path.startsWith(sp))) {
        ObjectId objectId = treeWalk.getObjectId(0);
        logger.debug("Loading {} [{}]",path,objectId.name());
        resources.add(readBlob(aRepository, path.substring(0, path.indexOf('.')), objectId.name()));
      }
    }
    return resources;
  }
  catch (Exception e) {
    throw Throwables.propagate(e);
  } 
}
 
開發者ID:creactiviti,項目名稱:piper,代碼行數:24,代碼來源:JGitTemplate.java

示例3: QuickSearchPanel

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
public QuickSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) {
	super(id);
	
	this.projectModel = projectModel;
	this.revisionModel = revisionModel;
	
	Project project = projectModel.getObject();
	for (String blobPath: getRecentOpened()) {
		try {
			RevTree revTree = project.getRevCommit(revisionModel.getObject()).getTree();
			TreeWalk treeWalk = TreeWalk.forPath(project.getRepository(), blobPath, revTree);
			if (treeWalk != null && treeWalk.getRawMode(0) != FileMode.TREE.getBits()) {
				symbolHits.add(new FileHit(blobPath, null));
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:20,代碼來源:QuickSearchPanel.java

示例4: testRemoveFile

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的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));
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:26,代碼來源:BlobEditsTest.java

示例5: shouldFailIfOldPathIsTreeWhenRename

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的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));
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:26,代碼來源:BlobEditsTest.java

示例6: getLoaderFrom

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
/**
 * Gets the loader for a file from a specified commit and its path
 * 
 * @param commit
 *          - the commit from which to get the loader
 * @param path
 *          - the path to the file
 * @return the loader
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 * @throws CorruptObjectException
 * @throws IOException
 */
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
		throws IOException {
	Repository repository = git.getRepository();
	RevWalk revWalk = new RevWalk(repository);
	RevCommit revCommit = revWalk.parseCommit(commit);
	// and using commit's tree find the path
	RevTree tree = revCommit.getTree();
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setFilter(PathFilter.create(path));

	ObjectLoader loader = null;
	if (treeWalk.next()) {
		ObjectId objectId = treeWalk.getObjectId(0);
		loader = repository.open(objectId);
	}

	treeWalk.close();
	revWalk.close();
	return loader;
}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:36,代碼來源:GitAccess.java

示例7: printFile

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private static void printFile(Repository repository, RevTree tree) throws IOException {
    // now try to find a specific file
    try (TreeWalk treeWalk = new TreeWalk(repository)) {
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        treeWalk.setFilter(PathFilter.create("README.md"));
        if (!treeWalk.next()) {
            throw new IllegalStateException("Did not find expected file 'README.md'");
        }

        // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit
// set
        FileMode fileMode = treeWalk.getFileMode(0);
        ObjectLoader loader = repository.open(treeWalk.getObjectId(0));
        System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode +
                " size: " + loader.getSize());
    }
}
 
開發者ID:alexmy21,項目名稱:gmds,代碼行數:19,代碼來源:GetFileAttributes.java

示例8: getTreeIterator

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private AbstractTreeIterator getTreeIterator( String commitId ) throws Exception {
  if ( commitId == null ) {
    return new EmptyTreeIterator();
  }
  if ( commitId.equals( WORKINGTREE ) ) {
    return new FileTreeIterator( git.getRepository() );
  } else if ( commitId.equals( INDEX ) ) {
    return new DirCacheIterator( git.getRepository().readDirCache() );
  } else {
    ObjectId id = git.getRepository().resolve( commitId );
    if ( id == null ) { // commitId does not exist
      return new EmptyTreeIterator();
    } else {
      CanonicalTreeParser treeIterator = new CanonicalTreeParser();
      try ( RevWalk rw = new RevWalk( git.getRepository() ) ) {
        RevTree tree = rw.parseTree( id );
        try ( ObjectReader reader = git.getRepository().newObjectReader() ) {
          treeIterator.reset( reader, tree.getId() );
        }
      }
      return treeIterator;
    }
  }
}
 
開發者ID:HiromuHota,項目名稱:pdi-git-plugin,代碼行數:25,代碼來源:UIGit.java

示例9: prepareTreeParser

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private AbstractTreeIterator prepareTreeParser(Repository repository, String objectId) throws IOException {
    // from the commit we can build the tree which allows us to construct the TreeParser
    //noinspection Duplicates
    try (RevWalk walk = new RevWalk(repository)) {
        RevCommit commit = walk.parseCommit(ObjectId.fromString(objectId));
        RevTree tree = walk.parseTree(commit.getTree().getId());

        CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
        try (ObjectReader oldReader = repository.newObjectReader()) {
            oldTreeParser.reset(oldReader, tree.getId());
        }

        walk.dispose();

        return oldTreeParser;
    }
}
 
開發者ID:iazarny,項目名稱:gitember,代碼行數:18,代碼來源:GitRepositoryService.java

示例10: isInPath

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
private boolean isInPath(Repository repository, RevWalk walk, RevCommit commit) throws IOException {
    if (commit.getParentCount() == 0) {
        RevTree tree = commit.getTree();
        try (TreeWalk treeWalk = new TreeWalk(repository)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(true);
            treeWalk.setFilter(pathFilter);
            return treeWalk.next();
        }
    } else {
        DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
        df.setRepository(repository);
        df.setPathFilter(pathFilter);
        RevCommit parent = walk.parseCommit(commit.getParent(0).getId());
        List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
        return !diffs.isEmpty();
    }
}
 
開發者ID:jakubplichta,項目名稱:git-changelog-maven-plugin,代碼行數:19,代碼來源:RepositoryProcessor.java

示例11: readFromCommit

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
public byte[] readFromCommit(String commitId, String path) throws Exception {
    try (RevWalk revWalk = new RevWalk(localRepo)) {
        RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
        // use commit's tree find the path
        RevTree tree = commit.getTree();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(true);
            treeWalk.setFilter(PathFilter.create(path));
            if (!treeWalk.next()) {
                return null;
            }

            ObjectId objectId = treeWalk.getObjectId(0);
            ObjectLoader loader = localRepo.open(objectId);

            loader.copyTo(baos);
        }
        revWalk.dispose();
        return baos.toByteArray();
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:24,代碼來源:VersionControlGit.java

示例12: iterator

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
@Override
public Iterator<TreeWalkerEntry> iterator() {
	Repository repository = commit.getGitRepository().getRepository();
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.setRecursive(true);
	RevTree tree = getCommit().getRevCommit().getTree();
	try {
		treeWalk.addTree(tree);
		TreeWalkerIterator treeWalkerIterator = new TreeWalkerIterator(
				treeWalk, this);
		iterators.add(treeWalkerIterator);
		return treeWalkerIterator;
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:link-intersystems,項目名稱:GitDirStat,代碼行數:17,代碼來源:TreeWalker.java

示例13: getFileFromCommit

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
    final TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    treeWalk.setFilter(PathFilter.create(file));
    if (!treeWalk.next()) {
        logger.info("Did not find expected file '" + file + "'");
        return false;
    }

    final ObjectId objectId = treeWalk.getObjectId(0);
    final ObjectLoader loader = repo.open(objectId);

    // and then one can the loader to read the file
    loader.copyTo(os);
    return true;
}
 
開發者ID:cobr123,項目名稱:VirtaMarketAnalyzer,代碼行數:18,代碼來源:GitHubPublisher.java

示例14: getFileSHA1Checksum

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
@Override
public String getFileSHA1Checksum() throws SVNException {
    String path = getCreatedPath();
    long revision = getTextRepresentation().getRevision();
    Repository gitRepository = myGitFS.getGitRepository();
    try {
        RevTree tree = new RevWalk(gitRepository).parseTree(gitRepository.resolve("refs/svn/" + revision));
        TreeWalk treeWalk = TreeWalk.forPath(gitRepository, path, tree);
        if (treeWalk.isSubtree()) {
            SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.FS_NOT_FILE, "Attempted to get checksum of a *non*-file node");
            SVNErrorManager.error(err, SVNLogType.FSFS);
        }
        return treeWalk.getObjectId(0).getName();
    } catch (IOException e) {
        SVNDebugLog.getDefaultLog().logError(SVNLogType.DEFAULT, e.getMessage());
        return "";
    }
}
 
開發者ID:naver,項目名稱:svngit,代碼行數:19,代碼來源:GitFSRevisionNode.java

示例15: emptyToCommit

import org.eclipse.jgit.revwalk.RevTree; //導入依賴的package包/類
/**
 * Show changes between specified revision and empty tree.
 *
 * @param commitId id of commit
 * @param formatter diff formatter
 * @return list of diff entries
 * @throws IOException if any i/o errors occurs
 */
private List<DiffEntry> emptyToCommit(String commitId, DiffFormatter formatter)
    throws IOException {
  ObjectId commit = repository.resolve(commitId);
  checkArgument(commit != null, "Invalid commit id " + commitId);
  RevTree tree;
  try (RevWalk revWalkA = new RevWalk(repository)) {
    tree = revWalkA.parseTree(commit);
  }

  List<DiffEntry> diff;
  try (ObjectReader reader = repository.newObjectReader()) {
    CanonicalTreeParser iterator = new CanonicalTreeParser();
    iterator.reset(reader, tree);
    diff = formatter.scan(new EmptyTreeIterator(), iterator);
  }
  return diff;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:JGitDiffPage.java


注:本文中的org.eclipse.jgit.revwalk.RevTree類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。