当前位置: 首页>>代码示例>>Java>>正文


Java TreeWalk.release方法代码示例

本文整理汇总了Java中org.eclipse.jgit.treewalk.TreeWalk.release方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalk.release方法的具体用法?Java TreeWalk.release怎么用?Java TreeWalk.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.treewalk.TreeWalk的用法示例。


在下文中一共展示了TreeWalk.release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSubmoduleCommitId

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) {
	String commitId = null;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
	try {
		tw.reset(commit.getTree());
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			if (FileMode.GITLINK == tw.getFileMode(0)) {
				commitId = tw.getObjectId(0).getName();
				break;
			}
		}
	} catch (Throwable t) {
		error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name());
	} finally {
		rw.dispose();
		tw.release();
	}
	return commitId;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:26,代码来源:JGitUtils.java

示例2: listFiles

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private void listFiles() throws GitException {
    RevWalk revWalk = new RevWalk(repository);
    TreeWalk walk = new TreeWalk(repository);
    try {
        List<GitFileInfo> result;
        walk.reset();
        walk.setRecursive(true);
        RevCommit parentCommit = null;
        if (revCommit.getParentCount() > 0) {
            for (RevCommit commit : revCommit.getParents()) {
                revWalk.markStart(revWalk.lookupCommit(commit));
            }
            revWalk.setRevFilter(RevFilter.MERGE_BASE);
            Iterator<RevCommit> it = revWalk.iterator();
            if (it.hasNext()) {
                parentCommit = it.next();
            }
            if (parentCommit != null) {
                walk.addTree(parentCommit.getTree().getId());
            }
        }
        walk.addTree(revCommit.getTree().getId());
        walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
        if (parentCommit != null) {
            result = Utils.getDiffEntries(repository, walk, GitClassFactoryImpl.getInstance());
        } else {
            result = new ArrayList<GitFileInfo>();
            while (walk.next()) {
                result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
            }
        }
        this.modifiedFiles = result.toArray(new GitFileInfo[result.size()]);
    } catch (IOException ex) {
        throw new GitException(ex);
    } finally {
        revWalk.release();
        walk.release();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:GitRevisionInfo.java

示例3: checkout

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public void checkout () throws IOException, GitException {
    TreeWalk treeWalk = new TreeWalk(repository);
    Collection<String> relativePaths = Utils.getRelativePaths(repository.getWorkTree(), roots);
    if (!relativePaths.isEmpty()) {
        treeWalk.setFilter(PathFilterGroup.createFromStrings(relativePaths));
    }
    treeWalk.setRecursive(true);
    treeWalk.reset();
    treeWalk.addTree(new DirCacheIterator(cache));
    treeWalk.addTree(new FileTreeIterator(repository));
    String lastAddedPath = null;
    ObjectReader od = repository.newObjectReader();
    try {
    while (treeWalk.next() && !monitor.isCanceled()) {
        File path = new File(repository.getWorkTree(), treeWalk.getPathString());
        if (treeWalk.getPathString().equals(lastAddedPath)) {
            // skip conflicts
            continue;
        } else {
            lastAddedPath = treeWalk.getPathString();
        }
        DirCacheIterator dit = treeWalk.getTree(0, DirCacheIterator.class);
        FileTreeIterator fit = treeWalk.getTree(1, FileTreeIterator.class);
        if (dit != null && (recursively || directChild(roots, repository.getWorkTree(), path)) && (fit == null || fit.isModified(dit.getDirCacheEntry(), checkContent, od))) {
            // update entry
            listener.notifyFile(path, treeWalk.getPathString());
            checkoutEntry(repository, path, dit.getDirCacheEntry(), od);
        }
    }
    } finally {
        od.release();
        treeWalk.release();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:CheckoutIndex.java

示例4: getByteContent

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Retrieves the raw byte content of a file in the specified tree.
 * 
 * @param repository
 * @param tree
 *            if null, the RevTree from HEAD is assumed.
 * @param path
 * @return content as a byte []
 */
public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) {
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path)));
	byte[] content = null;
	try {
		if (tree == null) {
			ObjectId object = getDefaultBranch(repository);
			RevCommit commit = rw.parseCommit(object);
			tree = commit.getTree();
		}
		tw.reset(tree);
		while (tw.next()) {
			if (tw.isSubtree() && !path.equals(tw.getPathString())) {
				tw.enterSubtree();
				continue;
			}
			ObjectId entid = tw.getObjectId(0);
			FileMode entmode = tw.getFileMode(0);
			if (entmode != FileMode.GITLINK) {
				RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
				rw.parseBody(ro);
				ByteArrayOutputStream os = new ByteArrayOutputStream();
				ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB);
				byte[] tmp = new byte[4096];
				InputStream in = ldr.openStream();
				int n;
				while ((n = in.read(tmp)) > 0) {
					os.write(tmp, 0, n);
				}
				in.close();
				content = os.toByteArray();
			}
		}
	} catch (Throwable t) {
		if (throwError) {
			error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
		}
	} finally {
		rw.dispose();
		tw.release();
	}
	return content;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:54,代码来源:JGitUtils.java

示例5: zip

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Zips the contents of the tree at the (optionally) specified revision and
 * the (optionally) specified basepath to the supplied outputstream.
 * 
 * @param repository
 * @param basePath
 *            if unspecified, entire repository is assumed.
 * @param objectId
 *            if unspecified, HEAD is assumed.
 * @param os
 * @return true if repository was successfully zipped to supplied output
 *         stream
 */
public static boolean zip(Repository repository, String basePath, String objectId,
		OutputStream os) {
	RevCommit commit = JGitUtils.getCommit(repository, objectId);
	if (commit == null) {
		return false;
	}
	boolean success = false;
	RevWalk rw = new RevWalk(repository);
	TreeWalk tw = new TreeWalk(repository);
	try {
		tw.reset();
		tw.addTree(commit.getTree());
		ZipArchiveOutputStream zos = new ZipArchiveOutputStream(os);
		zos.setComment("Generated by Gitblit");
		if (!StringUtils.isEmpty(basePath)) {
			PathFilter f = PathFilter.create(basePath);
			tw.setFilter(f);
		}
		tw.setRecursive(true);
		MutableObjectId id = new MutableObjectId();
		ObjectReader reader = tw.getObjectReader();
		long modified = commit.getAuthorIdent().getWhen().getTime();
		while (tw.next()) {
			FileMode mode = tw.getFileMode(0);
			if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
				continue;
			}
			tw.getObjectId(id, 0);

			ZipArchiveEntry entry = new ZipArchiveEntry(tw.getPathString());
			entry.setSize(reader.getObjectSize(id, Constants.OBJ_BLOB));
			entry.setComment(commit.getName());
			entry.setUnixMode(mode.getBits());
			entry.setTime(modified);
			zos.putArchiveEntry(entry);

			ObjectLoader ldr = repository.open(id);
			ldr.copyTo(zos);
			zos.closeArchiveEntry();
		}
		zos.finish();
		success = true;
	} catch (IOException e) {
		error(e, repository, "{0} failed to zip files from commit {1}", commit.getName());
	} finally {
		tw.release();
		rw.dispose();
	}
	return success;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:64,代码来源:CompressionUtils.java

示例6: findMatchingIdentity

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Find the tree that contains the required identity.
 *
 * @return The ObjectId of the tree (directory) that contains the matching
 * identity within the supplied hierarchy.
 */
private ObjectId findMatchingIdentity(
        IdentityValidator identityValidator,
        ObjectId tree) throws IOException {
    TreeWalk treeWalk = new TreeWalk(repo.getRepository());
    try {
        treeWalk.setRecursive(false);
        treeWalk.addTree(tree);

        while (treeWalk.next()) {
            if (treeWalk.isSubtree()) {
                ObjectId candidateId = findMatchingIdentity(
                        identityValidator, treeWalk.getObjectId(0));
                if (ObjectId.zeroId().equals(candidateId)) {
                    // Keep searching
                } else {
                    return candidateId;
                }
            } else if (identityValidator.getIdentityFilename().equals(treeWalk.getNameString())) {
                // Read the identity file
                ObjectLoader loader = repo.getRepository().open(
                        treeWalk.getObjectId(0));
                ObjectStream stream = loader.openStream();
                InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
                if (identityValidator.isIdentityMatched(new BufferedReader(reader))) {
                    // We found it
                    return tree;
                }
            }
        }
        return ObjectId.zeroId();
    } finally {
        treeWalk.release();
    }
}
 
开发者ID:fuzzyBSc,项目名称:systemdesign,代码行数:41,代码来源:GitVersionControl.java

示例7: listFiles

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public Stream<String> listFiles(
        IdentityValidator identityValidator, Optional<String> label) throws IOException {
    if (label.isPresent()) {
        Pair<String, ObjectId> diff = findDiff(identityValidator, label.get());

        if (ObjectId.zeroId().equals(diff.getValue())) {
            // No such tree
            return Stream.empty();
        } else {
            // Find the file in this tree
            TreeWalk treeWalk = new TreeWalk(repo.getRepository());
            try {
                treeWalk.setRecursive(false);
                treeWalk.addTree(diff.getValue());

                List<String> filenames = new ArrayList<>();
                while (treeWalk.next()) {
                    filenames.add(treeWalk.getNameString());
                }
                return filenames.stream();
            } finally {
                treeWalk.release();
            }
        }
    } else {
        return delegate.listFiles(identityValidator, label);
    }
}
 
开发者ID:fuzzyBSc,项目名称:systemdesign,代码行数:30,代码来源:GitVersionControl.java

示例8: exists

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public boolean exists(
        IdentityValidator identityValidator, String filename, Optional<String> label) throws IOException {
    if (label.isPresent()) {
        Pair<String, ObjectId> diff = findDiff(identityValidator, label.get());

        if (ObjectId.zeroId().equals(diff.getValue())) {
            // No such tree
            return false;
        } else {
            // Find the file in this tree
            TreeWalk treeWalk = new TreeWalk(repo.getRepository());
            try {
                treeWalk.setRecursive(false);
                treeWalk.addTree(diff.getValue());

                while (treeWalk.next()) {
                    if (filename.equals(treeWalk.getNameString())) {
                        return true;
                    }
                }
                // No such file
                return false;
            } finally {
                treeWalk.release();
            }
        }
    } else {
        return delegate.exists(identityValidator, filename, label);
    }
}
 
开发者ID:fuzzyBSc,项目名称:systemdesign,代码行数:32,代码来源:GitVersionControl.java

示例9: getBufferedReader

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public BufferedReader getBufferedReader(
        IdentityValidator identityValidator, String filename, Optional<String> label) throws IOException {
    if (label.isPresent()) {
        Pair<String, ObjectId> diff = findDiff(identityValidator, label.get());

        if (ObjectId.zeroId().equals(diff.getValue())) {
            // No such tree
            throw new FileNotFoundException(identityValidator.getPath() + " does not exist for label " + label.get());
        } else {
            // Find the file in this tree
            TreeWalk treeWalk = new TreeWalk(repo.getRepository());
            try {
                treeWalk.setRecursive(false);
                treeWalk.addTree(diff.getValue());

                while (treeWalk.next()) {
                    if (filename.equals(treeWalk.getNameString())) {
                        // Read the file
                        ObjectLoader loader = repo.getRepository().open(
                                treeWalk.getObjectId(0));
                        ObjectStream stream = loader.openStream();
                        InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
                        return new BufferedReader(reader);
                    }
                }
                // No such file
                throw new FileNotFoundException(filename + " does not exist for label " + label.get()
                );
            } finally {
                treeWalk.release();
            }
        }
    } else {
        return delegate.getBufferedReader(identityValidator, filename, label);
    }
}
 
开发者ID:fuzzyBSc,项目名称:systemdesign,代码行数:38,代码来源:GitVersionControl.java

示例10: mergeConflicts

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException {
    DirCacheBuilder builder = cache.builder();
    DirCacheBuildIterator dci = new DirCacheBuildIterator(builder);
    TreeWalk walk = new TreeWalk(getRepository());
    ObjectDatabase od = null;
    DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum(
                    ConfigConstants.CONFIG_DIFF_SECTION, null,
                    ConfigConstants.CONFIG_KEY_ALGORITHM,
                    DiffAlgorithm.SupportedAlgorithm.HISTOGRAM);
    MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg));
    try {
        od = getRepository().getObjectDatabase();
        walk.addTree(dci);
        walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts)));
        String lastPath = null;
        DirCacheEntry[] entries = new DirCacheEntry[3];
        walk.setRecursive(true);
        while (walk.next()) {
            DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry();
            String path = e.getPathString();
            if (lastPath != null && !lastPath.equals(path)) {
                resolveEntries(merger, lastPath, entries, od, builder);
            }
            if (e.getStage() == 0) {
                DirCacheIterator c = walk.getTree(0, DirCacheIterator.class);
                builder.add(c.getDirCacheEntry());
            } else {
                entries[e.getStage() - 1] = e;
                lastPath = path;
            }
        }
        resolveEntries(merger, lastPath, entries, od, builder);
        builder.commit();
    } catch (IOException ex) {
        throw new GitException(ex);
    } finally {
        walk.release();
        if (od != null) {
            od.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:CheckoutRevisionCommand.java

示例11: ExtractCommitInfo

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private static CommitNode ExtractCommitInfo(RevCommit _revCommit, Repository _repo, Date later) {
	
	CommitNode c = new CommitNode(null);

	
	RevWalk rw = new RevWalk(_repo);
	try {
		/*if (commit == null) {
			ObjectId object = getDefaultBranch(repository);
			commit = rw.parseCommit(object);
		}*/

		if (_revCommit.getParentCount() == 0) {
			TreeWalk tw = new TreeWalk(_repo);
			tw.reset();
			tw.setRecursive(true);
			tw.addTree(_revCommit.getTree());
			c.date = _revCommit.getAuthorIdent().getWhen();
			
			if ( (later != null) && c.date.before(later)){
				return null;
			}
			
			while (tw.next()) {
				
				if (isJavaFile(tw.getPathString())){
					c.files.add(new FileNode(tw.getPathString(), tw.getPathString(),
							tw.getObjectId(0), null, ChangeType.ADD));
				}
			}
			tw.release();
		} else {
			RevCommit parent = rw.parseCommit(_revCommit.getParent(0).getId());
			DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
			df.setRepository(_repo);	
			df.setDiffComparator(RawTextComparator.DEFAULT);
			df.setDetectRenames(true);
			List<DiffEntry> diffs = df.scan(parent.getTree(), _revCommit.getTree());
			c.date = _revCommit.getAuthorIdent().getWhen();
			
			if ((later != null) && c.date.before(later)){
				return null;
			}
			
			for (DiffEntry diff : diffs) {
				
				if (diff.getChangeType().equals(ChangeType.ADD)) {
					if (isJavaFile(diff.getNewPath())){
						c.files.add(new FileNode(diff.getNewPath(), null,
							diff.getNewId().toObjectId(), null, diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.DELETE)) {
					if (isJavaFile(diff.getOldPath())){
						c.files.add(new FileNode(null, diff.getOldPath(),
							null, diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.RENAME)) {
					if (isJavaFile(diff.getNewPath())){
						c.files.add(new FileNode(diff.getNewPath(), diff.getOldPath(),
							diff.getNewId().toObjectId(), diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.MODIFY)){
					if (isJavaFile(diff.getNewPath())){
						c.files.add(new FileNode(diff.getNewPath(), null,
							diff.getNewId().toObjectId(), diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		rw.dispose();
	}
	
	return c;
}
 
开发者ID:gems-uff,项目名称:dominoes,代码行数:78,代码来源:CommitNode.java

示例12: parse

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public void parse(RepositoryNode _repo) {
	
	RevWalk rw = new RevWalk(_repo.getRepository());
	try {
		/*if (commit == null) {
			ObjectId object = getDefaultBranch(repository);
			commit = rw.parseCommit(object);
		}*/

		if (revCommit.getParentCount() == 0) {
			TreeWalk tw = new TreeWalk(_repo.getRepository());
			tw.reset();
			tw.setRecursive(true);
			tw.addTree(revCommit.getTree());

			
			while (tw.next()) {
				
				if (isJavaFile(tw.getPathString())){
					files.add(new FileNode(tw.getPathString(), tw.getPathString(),
						tw.getObjectId(0), null, ChangeType.ADD));
				}
			}
			tw.release();
		} else {
			RevCommit parent = rw.parseCommit(revCommit.getParent(0).getId());
			DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
			df.setRepository(_repo.getRepository());	
			df.setDiffComparator(RawTextComparator.DEFAULT);
			df.setDetectRenames(true);
			List<DiffEntry> diffs = df.scan(parent.getTree(), revCommit.getTree());
			
			for (DiffEntry diff : diffs) {
				
				if (diff.getChangeType().equals(ChangeType.ADD)) {
					if (isJavaFile(diff.getNewPath())){
						files.add(new FileNode(diff.getNewPath(), null,
							diff.getNewId().toObjectId(), null, diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.DELETE)) {
					if (isJavaFile(diff.getOldPath())){
						files.add(new FileNode(null, diff.getOldPath(),
							null, diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.RENAME)) {
					if (isJavaFile(diff.getNewPath())){
						files.add(new FileNode(diff.getNewPath(), diff.getOldPath(),
							diff.getNewId().toObjectId(), diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				} else if (diff.getChangeType().equals(ChangeType.MODIFY)){
					if (isJavaFile(diff.getNewPath())){
						files.add(new FileNode(diff.getNewPath(), null,
							diff.getNewId().toObjectId(), diff.getOldId().toObjectId(), diff.getChangeType()));
					}
				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		rw.dispose();
	}
	
	
	for (FileNode f : files){
		f.Parse(_repo.getRepository());
	}
}
 
开发者ID:gems-uff,项目名称:dominoes,代码行数:69,代码来源:CommitNode.java

示例13: getFilesInCommit

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Returns the list of files changed in a specified commit. If the
 * repository does not exist or is empty, an empty list is returned.
 * 
 * @param repository
 * @param commit
 *            if null, HEAD is assumed.
 * @return list of files changed in a commit
 */
public List<PathChangeModel> getFilesInCommit(RevCommit commit) {
	List<PathChangeModel> list = new ArrayList<PathChangeModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	RevWalk rw = new RevWalk(repository);
	try {
		if (commit == null) {
			ObjectId object = getDefaultBranch(repository);
			commit = rw.parseCommit(object);
		}

		if (commit.getParentCount() == 0) {
			TreeWalk tw = new TreeWalk(repository);
			tw.reset();
			tw.setRecursive(true);
			tw.addTree(commit.getTree());
			while (tw.next()) {
				list.add(new PathChangeModel(tw.getPathString(), tw.getPathString(), 0, tw
						.getRawMode(0), commit.getId().getName(), ChangeType.ADD));
			}
			tw.release();
		} else {
			RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
			DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
			df.setRepository(repository);
			df.setDiffComparator(RawTextComparator.DEFAULT);
			df.setDetectRenames(true);
			List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
			for (DiffEntry diff : diffs) {
				if (diff.getChangeType().equals(ChangeType.DELETE)) {
					list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
							.getNewMode().getBits(), commit.getId().getName(), diff
							.getChangeType()));
				} else if (diff.getChangeType().equals(ChangeType.RENAME)) {
					list.add(new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
							.getNewMode().getBits(), commit.getId().getName(), diff
							.getChangeType()));
				} else {
					list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
							.getNewMode().getBits(), commit.getId().getName(), diff
							.getChangeType()));
				}
			}
		}
	} catch (Throwable t) {
		System.err.println("Repository failed to determine files in commit!");
	} finally {
		rw.dispose();
	}
	return list;
}
 
开发者ID:gems-uff,项目名称:oceano,代码行数:62,代码来源:GitCommands.java

示例14: getFilesInPath

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Returns the list of files in the specified folder at the specified
 * commit. If the repository does not exist or is empty, an empty list is
 * returned.
 * 
 * @param repository
 * @param path
 *            if unspecified, root folder is assumed.
 * @param commit
 *            if null, HEAD is assumed.
 * @return list of files in specified path
 */
public static List<PathModel> getFilesInPath(Repository repository, String path,
		RevCommit commit) {
	List<PathModel> list = new ArrayList<PathModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	if (commit == null) {
		commit = getCommit(repository, null);
	}
	final TreeWalk tw = new TreeWalk(repository);
	try {
		tw.addTree(commit.getTree());
		if (!StringUtils.isEmpty(path)) {
			PathFilter f = PathFilter.create(path);
			tw.setFilter(f);
			tw.setRecursive(false);
			boolean foundFolder = false;
			while (tw.next()) {
				if (!foundFolder && tw.isSubtree()) {
					tw.enterSubtree();
				}
				if (tw.getPathString().equals(path)) {
					foundFolder = true;
					continue;
				}
				if (foundFolder) {
					list.add(getPathModel(tw, path, commit));
				}
			}
		} else {
			tw.setRecursive(false);
			while (tw.next()) {
				list.add(getPathModel(tw, null, commit));
			}
		}
	} catch (IOException e) {
		error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
	} finally {
		tw.release();
	}
	Collections.sort(list);
	return list;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:56,代码来源:JGitUtils.java

示例15: getFilesInCommit

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Returns the list of files changed in a specified commit. If the
 * repository does not exist or is empty, an empty list is returned.
 * 
 * @param repository
 * @param commit
 *            if null, HEAD is assumed.
 * @return list of files changed in a commit
 */
public static List<PathChangeModel> getFilesInCommit(Repository repository, RevCommit commit) {
	List<PathChangeModel> list = new ArrayList<PathChangeModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	RevWalk rw = new RevWalk(repository);
	try {
		if (commit == null) {
			ObjectId object = getDefaultBranch(repository);
			commit = rw.parseCommit(object);
		}

		if (commit.getParentCount() == 0) {
			TreeWalk tw = new TreeWalk(repository);
			tw.reset();
			tw.setRecursive(true);
			tw.addTree(commit.getTree());
			while (tw.next()) {
				list.add(new PathChangeModel(tw.getPathString(), tw.getPathString(), 0, tw
						.getRawMode(0), tw.getObjectId(0).getName(), commit.getId().getName(),
						ChangeType.ADD));
			}
			tw.release();
		} else {
			RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
			DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
			df.setRepository(repository);
			df.setDiffComparator(RawTextComparator.DEFAULT);
			df.setDetectRenames(true);
			List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
			for (DiffEntry diff : diffs) {
				String objectId = diff.getNewId().name();
				if (diff.getChangeType().equals(ChangeType.DELETE)) {
					list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
							.getNewMode().getBits(), objectId, commit.getId().getName(), diff
							.getChangeType()));
				} else if (diff.getChangeType().equals(ChangeType.RENAME)) {
					list.add(new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
							.getNewMode().getBits(), objectId, commit.getId().getName(), diff
							.getChangeType()));
				} else {
					list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
							.getNewMode().getBits(), objectId, commit.getId().getName(), diff
							.getChangeType()));
				}
			}
		}
	} catch (Throwable t) {
		error(t, repository, "{0} failed to determine files in commit!");
	} finally {
		rw.dispose();
	}
	return list;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:64,代码来源:JGitUtils.java


注:本文中的org.eclipse.jgit.treewalk.TreeWalk.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。