本文整理汇总了Java中org.eclipse.jgit.treewalk.TreeWalk.getFileMode方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalk.getFileMode方法的具体用法?Java TreeWalk.getFileMode怎么用?Java TreeWalk.getFileMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.treewalk.TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.getFileMode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPathModel
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Returns a path model of the current file in the treewalk.
*
* @param tw
* @param basePath
* @param commit
* @return a path model of the current file in the treewalk
*/
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
String name;
long size = 0;
if (StringUtils.isEmpty(basePath)) {
name = tw.getPathString();
} else {
name = tw.getPathString().substring(basePath.length() + 1);
}
ObjectId objectId = tw.getObjectId(0);
try {
if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
}
} catch (Throwable t) {
error(t, null, "failed to retrieve blob size for " + tw.getPathString());
}
return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(), objectId.getName(), commit.getName());
}
示例2: getPathModel
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Returns a path model of the current file in the treewalk.
*
* @param tw
* @param basePath
* @param commit
* @return a path model of the current file in the treewalk
*/
private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) {
String name;
long size = 0;
if (StringUtils.isEmpty(basePath)) {
name = tw.getPathString();
} else {
name = tw.getPathString().substring(basePath.length() + 1);
}
ObjectId objectId = tw.getObjectId(0);
try {
if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) {
size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB);
}
} catch (Throwable t) {
error(t, null, "failed to retrieve blob size for " + tw.getPathString());
}
return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(),
objectId.getName(), commit.getName());
}
示例3: 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;
}
示例4: getContent
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public BinaryResult getContent(
Repository repo, ProjectState project, ObjectId revstr, String path)
throws IOException, ResourceNotFoundException {
try (RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(revstr);
ObjectReader reader = rw.getObjectReader();
TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree());
if (tw == null) {
throw new ResourceNotFoundException();
}
org.eclipse.jgit.lib.FileMode mode = tw.getFileMode(0);
ObjectId id = tw.getObjectId(0);
if (mode == org.eclipse.jgit.lib.FileMode.GITLINK) {
return BinaryResult.create(id.name()).setContentType(X_GIT_GITLINK).base64();
}
ObjectLoader obj = repo.open(id, OBJ_BLOB);
byte[] raw;
try {
raw = obj.getCachedBytes(MAX_SIZE);
} catch (LargeObjectException e) {
raw = null;
}
String type;
if (mode == org.eclipse.jgit.lib.FileMode.SYMLINK) {
type = X_GIT_SYMLINK;
} else {
type = registry.getMimeType(path, raw).toString();
type = resolveContentType(project, path, FileMode.FILE, type);
}
return asBinaryResult(raw, obj).setContentType(type).base64();
}
}
示例5: streamFromRepo
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
protected boolean streamFromRepo(HttpServletRequest request, HttpServletResponse response, Repository repository, RevCommit commit,
String requestedPath) throws IOException {
boolean served = false;
RevWalk rw = new RevWalk(repository);
TreeWalk tw = new TreeWalk(repository);
try {
tw.reset();
tw.addTree(commit.getTree());
PathFilter f = PathFilter.create(requestedPath);
tw.setFilter(f);
tw.setRecursive(true);
MutableObjectId id = new MutableObjectId();
ObjectReader reader = tw.getObjectReader();
while (tw.next()) {
FileMode mode = tw.getFileMode(0);
if (mode == FileMode.GITLINK || mode == FileMode.TREE) {
continue;
}
tw.getObjectId(id, 0);
String filename = StringUtils.getLastPathElement(requestedPath);
try {
String userAgent = request.getHeader("User-Agent");
if (userAgent != null && userAgent.indexOf("MSIE 5.5") > -1) {
response.setHeader("Content-Disposition", "filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else if (userAgent != null && userAgent.indexOf("MSIE") > -1) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(filename, Constants.ENCODING) + "\"");
} else {
response.setHeader("Content-Disposition", "attachment; filename=\""
+ new String(filename.getBytes(Constants.ENCODING), "latin1") + "\"");
}
} catch (UnsupportedEncodingException e) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
}
long len = reader.getObjectSize(id, org.eclipse.jgit.lib.Constants.OBJ_BLOB);
setContentType(response, "application/octet-stream");
response.setIntHeader("Content-Length", (int) len);
ObjectLoader ldr = repository.open(id);
ldr.copyTo(response.getOutputStream());
served = true;
}
} finally {
tw.close();
rw.dispose();
}
response.flushBuffer();
return served;
}
示例6: 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.close();
rw.close();
rw.dispose();
}
return success;
}
示例7: getFilesInVersion
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
* Returns a list containing the paths to all files in the specified
* version.
*
* @param c version identifier (commit)
* @return a list containing the paths to all files in the specified version
* @throws IllegalStateException if this file is currently not open
*/
private Collection<String> getFilesInVersion(RevCommit c) {
Collection<String> result = new ArrayList<String>();
// file has to be opened
if (!isOpened()) {
throw new IllegalStateException(
"File\"" + getFile().getPath() + "\" not opened!");
}
Git git = null;
try {
git = Git.open(tmpFolder);
// create a tree walk to search for files
TreeWalk walk = new TreeWalk(git.getRepository());
if (walk != null) {
// recursively search fo files
walk.setRecursive(true);
// add the tree the specified commit belongs to
walk.addTree(c.getTree());
// walk through the tree
while (walk.next()) {
// TODO: is it a problem if mode is treemode?
final FileMode mode = walk.getFileMode(0);
if (mode == FileMode.TREE) {
System.out.print(
"VersionedFile."
+ "getFilesInVersion(): FileMode unexpected!");
}
// retrieve the path name of the current element
String fileName = walk.getPathString();
// we do not want to commit/checkout this file
if (!fileName.equals(FILE_INFO_NAME)) {
result.add(walk.getPathString());
}
}
}
} catch (IOException ex) {
closeGit(git);
Logger.getLogger(VersionedFile.class.getName()).
log(Level.SEVERE, null, ex);
}
closeGit(git);
return result;
}
示例8: 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;
}
示例9: 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;
}
示例10: getFileMode
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Nullable
public static FileMode getFileMode(TreeWalk tw) {
return tw.getFileMode(0);
}
示例11: PathInfo
import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
protected PathInfo(TreeWalk tw) {
fileMode = tw.getFileMode(0);
path = tw.getPathString();
objectId = tw.getObjectId(0);
}