WorkingTreeSource(WorkingTreeIterator iterator) { this.tw = new TreeWalk((ObjectReader) null); this.tw.setRecursive(true); this.iterator = iterator; }
/** * Create submodule generator * * @param repository * the {@link org.eclipse.jgit.lib.Repository}. * @throws java.io.IOException */ public SubmoduleWalk(Repository repository) throws IOException { this.repository = repository; repoConfig = repository.getConfig(); walk = new TreeWalk(repository); walk.setRecursive(true); }
WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w) { Transport wt = (Transport)t; local = wt.local; objCheck = wt.getObjectChecker(); inserter = local.newObjectInserter(); reader = inserter.newReader(); remotes = new ArrayList<>(); remotes.add(w); unfetchedPacks = new LinkedList<>(); packsConsidered = new HashSet<>(); noPacksYet = new LinkedList<>(); noPacksYet.add(w); noAlternatesYet = new LinkedList<>(); noAlternatesYet.add(w); fetchErrors = new HashMap<>(); packLocks = new ArrayList<>(4); revWalk = new RevWalk(reader); revWalk.setRetainBody(false); treeWalk = new TreeWalk(reader); COMPLETE = revWalk.newFlag("COMPLETE"); //$NON-NLS-1$ IN_WORK_QUEUE = revWalk.newFlag("IN_WORK_QUEUE"); //$NON-NLS-1$ LOCALLY_SEEN = revWalk.newFlag("LOCALLY_SEEN"); //$NON-NLS-1$ localCommitQueue = new DateRevQueue(); workQueue = new LinkedList<>(); }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { ObjectId revId = repository.resolve(Constants.HEAD); try (TreeWalk treeWalk = new TreeWalk(repository)) { try (RevWalk revWalk = new RevWalk(repository)) { treeWalk.addTree(revWalk.parseTree(revId)); while (treeWalk.next()) { System.out.println("---------------------------"); System.out.append("name: ").println(treeWalk.getNameString()); System.out.append("path: ").println(treeWalk.getPathString()); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.append("directory: ").println(loader.getType() == Constants.OBJ_TREE); System.out.append("size: ").println(loader.getSize()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { ObjectId revId = repository.resolve(Constants.HEAD); try (TreeWalk treeWalk = new TreeWalk(repository)) { try (RevWalk revWalk = new RevWalk(repository)) { treeWalk.addTree(revWalk.parseTree(revId)); while (treeWalk.next()) { System.out.println("---------------------------"); System.out.append("name: ").println(treeWalk.getNameString()); System.out.append("path: ").println(treeWalk.getPathString()); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.append("directory: ").println(loader.getType() == Constants.OBJ_TREE); System.out.append("size: ").println(loader.getSize()); } } } } } }
/** * Create a filter for the first phase of a parent-rewriting limited revision * walk. * <p> * This filter is ANDed to evaluate before all other filters and ties the * configured {@link TreeFilter} into the revision walking process. * <p> * If no interesting tree entries are found the commit is colored with * {@code rewriteFlag}, allowing a later pass implemented by * {@link RewriteGenerator} to remove those colored commits from the DAG. * * @see RewriteGenerator * * @param walker * walker used for reading trees. * @param t * filter to compare against any changed paths in each commit. If a * {@link FollowFilter}, will be replaced with a new filter * following new paths after a rename. * @param rewriteFlag * flag to color commits to be removed from the simplified DAT. */ TreeRevFilter(final RevWalk walker, final TreeFilter t, final int rewriteFlag) { pathFilter = new TreeWalk(walker.reader); pathFilter.setFilter(t); pathFilter.setRecursive(t.shouldBeRecursive()); this.rewriteFlag = rewriteFlag; }
private static void printDirectory(Repository repository, RevTree tree) throws IOException { // look at directory, this has FileMode.TREE try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("src")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected folder 'src'"); } // FileMode now indicates that this is a directory, i.e. FileMode.TREE.equals(fileMode) holds true FileMode fileMode = treeWalk.getFileMode(0); System.out.println("src: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode); } }
private static void printDirectory(Repository repository, RevTree tree) throws IOException { // look at directory, this has FileMode.TREE try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("src")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected folder 'src'"); } // FileMode now indicates that this is a directory, i.e. FileMode.TREE.equals(fileMode) holds true FileMode fileMode = treeWalk.getFileMode(0); System.out.println("src: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode); } }
private static int countLinesOfFileInCommit(Repository repository, ObjectId commitID, String name) throws IOException { try (RevWalk revWalk = new RevWalk(repository)) { RevCommit commit = revWalk.parseCommit(commitID); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(name)); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = repository.open(objectId); // load the content of the file into a stream ByteArrayOutputStream stream = new ByteArrayOutputStream(); loader.copyTo(stream); revWalk.dispose(); return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8").size(); } } } }
private static int countLinesOfFileInCommit(Repository repository, ObjectId commitID, String name) throws IOException { try (RevWalk revWalk = new RevWalk(repository)) { RevCommit commit = revWalk.parseCommit(commitID); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(name)); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = repository.open(objectId); // load the content of the file into a stream ByteArrayOutputStream stream = new ByteArrayOutputStream(); loader.copyTo(stream); revWalk.dispose(); return IOUtils.readLines(new ByteArrayInputStream(stream.toByteArray()), "UTF-8").size(); } } } }
private void initRevPool(boolean reverse) { if (queue != null) throw new IllegalStateException(); if (revPool != null) revPool.close(); if (reverse) revPool = new ReverseWalk(getRepository()); else revPool = new RevWalk(getRepository()); SEEN = revPool.newFlag("SEEN"); //$NON-NLS-1$ reader = revPool.getObjectReader(); treeWalk = new TreeWalk(reader); treeWalk.setRecursive(true); }
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()); } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); // not walk the tree recursively so we only get the elements in the top-level directory treeWalk.setRecursive(false); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); // not walk the tree recursively so we only get the elements in the top-level directory treeWalk.setRecursive(false); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree recursively // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
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()); } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Ref head = repository.findRef("HEAD"); // a RevWalk allows to walk over commits based on some filtering that is defined try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); System.out.println("Having tree: " + tree); // now use a TreeWalk to iterate over all files in the Tree recursively // you can set Filters to narrow down the results if needed try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true); while (treeWalk.next()) { System.out.println("found: " + treeWalk.getPathString()); } } } } } }
try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true);
try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree); treeWalk.setRecursive(true);
private void resetIndex(ObjectId commitTree) throws IOException { DirCache dc = repo.lockDirCache(); try (TreeWalk walk = new TreeWalk(repo)) { DirCacheBuilder builder = dc.builder();