org.eclipse.jgit.revwalk.RevTree Java Examples

The following examples show how to use org.eclipse.jgit.revwalk.RevTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JGitAPIImpl.java    From git-client-plugin with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public List<IndexEntry> getSubmodules(String treeIsh) throws GitException {
    try (Repository repo = getRepository();
         ObjectReader or = repo.newObjectReader();
         RevWalk w = new RevWalk(or)) {
        List<IndexEntry> r = new ArrayList<>();

        RevTree t = w.parseTree(repo.resolve(treeIsh));
        SubmoduleWalk walk = new SubmoduleWalk(repo);
        walk.setTree(t);
        walk.setRootTree(t);
        while (walk.next()) {
            r.add(new IndexEntry(walk));
        }

        return r;
    } catch (IOException e) {
        throw new GitException(e);
    }
}
 
Example #2
Source File: CommitUtil.java    From SZZUnleashed with MIT License 6 votes vote down vote up
/**
 * Method to read a file from a specific revision.
 *
 * @param tree the revision tree that contains the file.
 * @param path the path that leads to the file in the tree.
 * @return a list containing all lines in the file.
 */
public List<String> getFileLines(RevTree tree, String path) throws IOException, GitAPIException {

  try (TreeWalk walk = new TreeWalk(this.repo)) {
    walk.addTree(tree);
    walk.setRecursive(true);
    walk.setFilter(PathFilter.create(path));

    walk.next();
    ObjectId oId = walk.getObjectId(0);

    if (oId == ObjectId.zeroId()) {
      return new LinkedList<>();
    }

    ObjectLoader loader = this.repo.open(oId);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    loader.copyTo(stream);

    return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8");
  } catch (Exception e) {
    return new LinkedList<>();
  }
}
 
Example #3
Source File: GitCommit.java    From Getaviz with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, VersionedFile> getFiles(Iterable<String> filters) throws FilesNotAvailableException {
	Map<String, VersionedFile> returnable = new HashMap<String, VersionedFile>();
	IterablePatternMatcher matcher = new IterablePatternMatcher();
	Iterable<Pattern> patterns = matcher.transformToPattern(filters);
	try {
		RevTree tree = commit.getTree();
		TreeWalk treeWalk = new TreeWalk(repository);
		treeWalk.addTree(tree);
		treeWalk.setRecursive(true);
		while (treeWalk.next()) {
			String currentFilePath = treeWalk.getPathString();
			if (matcher.isIncluded(patterns, currentFilePath)) {
				returnable.put(currentFilePath, readToByteArray(treeWalk));
			}
		}
	} catch (IOException e) {
		throw new FilesNotAvailableException(e);
	}
	return returnable;
}
 
Example #4
Source File: UIGit.java    From hop with Apache License 2.0 6 votes vote down vote up
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;
    }
  }
}
 
Example #5
Source File: BlobEditsTest.java    From onedev with MIT License 6 votes vote down vote up
@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));
	}
}
 
Example #6
Source File: BlobEditsTest.java    From onedev with MIT License 6 votes vote down vote up
@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));
	}
}
 
Example #7
Source File: GitUtils.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@SuppressFBWarnings(value={"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}, justification="JDK11 produces different bytecode - https://github.com/spotbugs/spotbugs/issues/756")
static byte[] readFile(Repository repository, String ref, String filePath) {
    try (ObjectReader reader = repository.newObjectReader()) {
        ObjectId branchRef = repository.resolve(ref); // repository.exactRef(ref);
        if (branchRef != null) { // for empty repositories, branchRef may be null
            RevWalk revWalk = new RevWalk(repository);
            RevCommit commit = revWalk.parseCommit(branchRef);
            // and using commit's tree find the path
            RevTree tree = commit.getTree();
            TreeWalk treewalk = TreeWalk.forPath(reader, filePath, tree);
            if (treewalk != null) {
                // use the blob id to read the file's data
                return reader.open(treewalk.getObjectId(0)).getBytes();
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    return null;
}
 
Example #8
Source File: JGitTemplate.java    From piper with Apache License 2.0 6 votes vote down vote up
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);
    if(id == null) {
      return List.of();
    }
    RevCommit commit = walk.parseCommit(id);
    RevTree tree = commit.getTree();
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    while (treeWalk.next()) {
      String path = treeWalk.getPathString();        
      if(!path.startsWith(".") && (searchPaths == null || searchPaths.size() == 0 || 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);
  } 
}
 
Example #9
Source File: VersionControlGit.java    From mdw with Apache License 2.0 6 votes vote down vote up
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 to 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();
    }
}
 
Example #10
Source File: VersionControlGit.java    From mdw with Apache License 2.0 6 votes vote down vote up
/**
 * Find package assets that are present at the specified commit.
 */
public List<String> getAssetsAtCommit(String commitId, String packagePath) throws Exception {
    try (RevWalk revWalk = new RevWalk(localRepo)) {
        RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
        // use commit's tree to find the path
        RevTree tree = commit.getTree();
        try (TreeWalk treeWalk = new TreeWalk(localRepo)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(true);
            treeWalk.setFilter(PathFilter.create(packagePath));
            List<String> assets = new ArrayList<>();
            while (treeWalk.next()) {
                if (treeWalk.getPathString().equals(packagePath + "/" + treeWalk.getNameString())) {
                    // direct member of package
                    assets.add(treeWalk.getNameString());
                }
            }
            return assets;
        }
        finally {
            revWalk.dispose();
        }
    }
}
 
Example #11
Source File: RepositoryPGit.java    From coming with MIT License 6 votes vote down vote up
protected void detectRenames(RevTree revTree)
		throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException {
	TreeWalk tw = new TreeWalk(repository);
	tw.setRecursive(true);
	tw.addTree(revTree);
	tw.addTree(new FileTreeIterator(repository));
	RenameDetector rd = new RenameDetector(repository);
	rd.addAll(DiffEntry.scan(tw));

	List<DiffEntry> lde = rd.compute(/* tw.getObjectReader(), null */);
	for (DiffEntry de : lde) {
		if (de.getScore() >= rd.getRenameScore()) {
			System.out.println("file: " + de.getOldPath() + " copied/moved to: " + de.getNewPath() + " ");
		}
	}
}
 
Example #12
Source File: PGA.java    From coming with MIT License 6 votes vote down vote up
private void obtainDiff(Repository repository, RevCommit commit, List<String> paths) throws IOException, GitAPIException {
        // and using commit's tree find the path
        RevTree tree = commit.getTree();
        System.out.println("Having tree: " + tree);

        // now try to find a specific file
        TreeWalk treeWalk = new TreeWalk(repository);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(true);
        for (String path : paths) {
            String filePath = SIVA_COMMITS_DIR + commit.getName() + "/" + path;
            File file = new File(filePath);
            if (!file.exists()) {
                treeWalk.setFilter(PathFilter.create(path));
                if (!treeWalk.next()) {
                    throw new IllegalStateException("Did not find expected file '" + path + "'");
                }

                ObjectId objectId = treeWalk.getObjectId(0);
                ObjectLoader loader = repository.open(objectId);
                // and then one can the loader to read the file
//                loader.copyTo(System.out);
                loader.copyTo(FileUtils.openOutputStream(file));
            }
        }
    }
 
Example #13
Source File: GitContentRepository.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long getContentSize(final String site, final String path) {
    Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);
    try {
        RevTree tree = helper.getTreeForLastCommit(repo);
        try (TreeWalk tw = TreeWalk.forPath(repo, helper.getGitPath(path), tree)) {
            if (tw != null && tw.getObjectId(0) != null) {
                ObjectId id = tw.getObjectId(0);
                ObjectLoader objectLoader = repo.open(id);
                return objectLoader.getSize();
            }
        }
    } catch (IOException e) {
        logger.error("Error while getting content for file at site: " + site + " path: " + path, e);
    }
    return -1L;
}
 
Example #14
Source File: ConfigRepository.java    From gocd with Apache License 2.0 5 votes vote down vote up
private byte[] contentFromTree(RevTree tree) {
    try (final ObjectReader reader = gitRepo.newObjectReader()) {
        CanonicalTreeParser parser = new CanonicalTreeParser();
        parser.reset(reader, tree);

        String lastPath = null;
        while (true) {
            final String path = parser.getEntryPathString();
            parser = parser.next();
            if (path.equals(lastPath)) {
                break;
            }

            lastPath = path;

            if (path.equals(CRUISE_CONFIG_XML)) {
                final ObjectId id = parser.getEntryObjectId();
                final ObjectLoader loader = reader.open(id);
                return loader.getBytes();
            }
        }
        return null;
    } catch (IOException e) {
        LOGGER.error("Could not fetch content from the config repository found at path '{}'", workingDir.getAbsolutePath(), e);
        throw new RuntimeException("Error while fetching content from the config repository.", e);
    }
}
 
Example #15
Source File: GitContentRepository.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void unLockItem(String site, String path) {
    Repository repo = helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX);

    synchronized (helper.getRepository(site, StringUtils.isEmpty(site) ? GLOBAL : SANDBOX)) {
        try (TreeWalk tw = new TreeWalk(repo)) {
            RevTree tree = helper.getTreeForLastCommit(repo);
            tw.addTree(tree); // tree ‘0’
            tw.setRecursive(false);
            tw.setFilter(PathFilter.create(path));

            if (!tw.next()) {
                return;
            }

            File repoRoot = repo.getWorkTree();
            Paths.get(repoRoot.getPath(), tw.getPathString());
            File file = new File(tw.getPathString());
            LockFile lock = new LockFile(file);
            lock.unlock();

            tw.close();

        } catch (IOException e) {
            logger.error("Error while unlocking file for site: " + site + " path: " + path, e);
        }
    }
}
 
Example #16
Source File: GitContentRepositoryHelper.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
public RevTree getTreeForLastCommit(Repository repository) throws IOException {
    ObjectId lastCommitId = repository.resolve(Constants.HEAD);
    if (lastCommitId == null) {
        return null;
    }
    // a RevWalk allows to walk over commits based on some filtering
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(lastCommitId);

        // and using commit's tree find the path
        RevTree tree = commit.getTree();
        return tree;
    }
}
 
Example #17
Source File: GitContentRepository.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void unLockItemForPublishing(String site, String path) {
    Repository repo = helper.getRepository(site, PUBLISHED);

    synchronized (repo) {
        try (TreeWalk tw = new TreeWalk(repo)) {
            RevTree tree = helper.getTreeForLastCommit(repo);
            tw.addTree(tree); // tree ‘0’
            tw.setRecursive(false);
            tw.setFilter(PathFilter.create(path));

            if (!tw.next()) {
                return;
            }

            File repoRoot = repo.getWorkTree();
            Paths.get(repoRoot.getPath(), tw.getPathString());
            File file = new File(tw.getPathString());
            LockFile lock = new LockFile(file);
            lock.unlock();

            tw.close();

        } catch (IOException e) {
            logger.error("Error while unlocking file for site: " + site + " path: " + path, e);
        }
    }
}
 
Example #18
Source File: GitContentRepositoryHelper.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
public RevTree getTreeForCommit(Repository repository, String commitId) throws IOException {
    ObjectId commitObjectId = repository.resolve(commitId);
    if (commitObjectId == null) {
        return null;
    }

    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(commitObjectId);

        // and using commit's tree find the path
        RevTree tree = commit.getTree();
        return tree;
    }
}
 
Example #19
Source File: GitWriter.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private int filterMigration(@NotNull RevTree tree) throws IOException, SVNException {
  final GitFile root = GitFileTreeEntry.create(branch, tree, 0);
  final GitFilterMigration validator = new GitFilterMigration(root);
  for (VcsConsumer<CommitAction> validateAction : commitActions) {
    validateAction.accept(validator);
  }
  return validator.done();
}
 
Example #20
Source File: SMAGit.java    From salesforce-migration-assistant with MIT License 5 votes vote down vote up
/**
 * Replicates ls-tree for the current commit.
 *
 * @return Map containing the full path and the data for all items in the repository.
 * @throws IOException
 */
public Map<String, byte[]> getAllMetadata() throws Exception
{
    Map<String, byte[]> contents = new HashMap<String, byte[]>();
    ObjectReader reader = repository.newObjectReader();
    ObjectId commitId = repository.resolve(curCommit);
    RevWalk revWalk = new RevWalk(reader);
    RevCommit commit = revWalk.parseCommit(commitId);
    RevTree tree = commit.getTree();
    TreeWalk treeWalk = new TreeWalk(reader);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);

    while (treeWalk.next())
    {
        if (treeWalk.isSubtree())
        {
            treeWalk.enterSubtree();
        }
        else
        {
            String member = treeWalk.getPathString();
            if (member.contains(SOURCEDIR))
            {
                byte[] data = getBlob(member, curCommit);
                contents.put(member, data);
            }
        }
    }

    reader.release();

    return contents;
}
 
Example #21
Source File: SMAGit.java    From salesforce-migration-assistant with MIT License 5 votes vote down vote up
/**
 * Returns the blob information for the file at the specified path and commit
 *
 * @param repoItem
 * @param commit
 * @return
 * @throws Exception
 */
public byte[] getBlob(String repoItem, String commit) throws Exception
{
    byte[] data;

    String parentPath = repository.getDirectory().getParent();

    ObjectId commitId = repository.resolve(commit);

    ObjectReader reader = repository.newObjectReader();
    RevWalk revWalk = new RevWalk(reader);
    RevCommit revCommit = revWalk.parseCommit(commitId);
    RevTree tree = revCommit.getTree();
    TreeWalk treeWalk = TreeWalk.forPath(reader, repoItem, tree);

    if (treeWalk != null)
    {
        data = reader.open(treeWalk.getObjectId(0)).getBytes();
    }
    else
    {
        throw new IllegalStateException("Did not find expected file '" + repoItem + "'");
    }

    reader.release();

    return data;
}
 
Example #22
Source File: TreeUtilsNewTreeWalkTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Test
public void createTreeWalkForTreeAndNonExistentPath_shouldReturnNull() throws IOException {
  writeMultipleToCache("/a.txt", "/b.txt", "/c/d.txt", "/c/e.txt", "/f/g.txt");
  RevTree tree = commitToMaster().getTree();
  TreeWalk treeWalk = TreeUtils.forPath("/non_existent_file.txt", tree, repo);

  assertNull(treeWalk);
}
 
Example #23
Source File: TreeUtilsNewTreeWalkTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Test
public void createTreeWalkForTreeAndPath_shouldReturnTreeWalkPointingToTheSpecifiedNode() throws IOException {
  writeMultipleToCache("/a.txt", "/b.txt", "/c/d.txt", "/c/e.txt", "/f/g.txt");
  RevTree tree = commitToMaster().getTree();
  TreeWalk treeWalk = TreeUtils.forPath("/c/d.txt", tree, repo);

  assertNotNull(treeWalk);
  assertEquals("d.txt", treeWalk.getNameString());
}
 
Example #24
Source File: TreeUtilsNewTreeWalkTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Test
public void createTreeWalkForTree_shouldReturnNonRecursiveTreeWalk() throws IOException {
  writeMultipleToCache("/a.txt", "/b.txt", "/c/d.txt", "/c/e.txt", "/f/g.txt");
  RevTree tree = commitToMaster().getTree();
  TreeWalk treeWalk = TreeUtils.newTreeWalk(tree, repo);

  assertNextEntry(treeWalk, "a.txt");
  assertNextEntry(treeWalk, "b.txt");
  assertNextEntry(treeWalk, "c");
  assertNextEntry(treeWalk, "f");
  assertFalse(treeWalk.next());
}
 
Example #25
Source File: TreeUtilsTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Test
public void isDirectoryTest() throws IOException {
  writeToCache("a/b.txt");
  RevTree tree = commitToMaster().getTree();
  assertTrue(TreeUtils.isDirectory("a", tree, repo));
  assertFalse(TreeUtils.isDirectory("a/b.txt", tree, repo));
  assertFalse(TreeUtils.isDirectory("a/b", tree, repo));
}
 
Example #26
Source File: TreeUtilsTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@Test
public void existsTest() throws IOException {
  writeToCache("a/b.txt");
  RevTree tree = commitToMaster().getTree();
  assertTrue(TreeUtils.exists("a", tree, repo));
  assertTrue(TreeUtils.exists("a/b.txt", tree, repo));
  assertFalse(TreeUtils.exists("a/b", tree, repo));
}
 
Example #27
Source File: WalkCommitTreeAdapter.java    From coderadar with MIT License 5 votes vote down vote up
@Override
public void walkCommitTree(
    String projectRoot, String name, WalkTreeCommandInterface commandInterface)
    throws UnableToWalkCommitTreeException {
  try {
    Git git = Git.open(new File(projectRoot));
    ObjectId commitId = git.getRepository().resolve(name);

    RevWalk walk = new RevWalk(git.getRepository());
    RevCommit commit = walk.parseCommit(commitId);
    RevTree tree = commit.getTree();
    TreeWalk treeWalk = new TreeWalk(git.getRepository());
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);

    while (treeWalk.next()) {
      if (!treeWalk.getPathString().endsWith(".java")
          || treeWalk.getPathString().contains("build")
          || treeWalk.getPathString().contains("out")
          || treeWalk.getPathString().contains("classes")
          || treeWalk.getPathString().contains("node_modules")
          || treeWalk.getPathString().contains("test")) {
        continue;
      }
      commandInterface.walkMethod(treeWalk.getPathString());
    }
    git.close();
  } catch (IOException e) {
    throw new UnableToWalkCommitTreeException(e.getMessage());
  }
}
 
Example #28
Source File: GITStatusCrawler.java    From celerio with Apache License 2.0 5 votes vote down vote up
private static RevTree getTree(Repository repository) throws IOException {
    ObjectId lastCommitId = repository.resolve(Constants.HEAD);

    // a RevWalk allows to walk over commits based on some filtering
    RevWalk revWalk = new RevWalk(repository);
    RevCommit commit = revWalk.parseCommit(lastCommitId);

    // and using commit's tree find the path
    RevTree tree = commit.getTree();
    return tree;
}
 
Example #29
Source File: AppraiseGitReviewClient.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private AbstractTreeIterator prepareTreeParserHelper(RevWalk walk, RevCommit commit)
    throws IOException, MissingObjectException, IncorrectObjectTypeException {
  RevTree tree = walk.parseTree(commit.getTree().getId());
  CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
  try (ObjectReader oldReader = repo.newObjectReader()) {
    oldTreeParser.reset(oldReader, tree.getId());
  }
  return oldTreeParser;
}
 
Example #30
Source File: GitWriter.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
private void validateProperties(@NotNull RevTree tree) throws IOException, SVNException {
  final GitFile root = GitFileTreeEntry.create(branch, tree, 0);
  final GitPropertyValidator validator = new GitPropertyValidator(root);
  for (VcsConsumer<CommitAction> validateAction : commitActions) {
    validateAction.accept(validator);
  }
  validator.done();
}