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


Java TreeWalk.getFileMode方法代碼示例

本文整理匯總了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());
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:27,代碼來源:JGitUtils.java

示例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());
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:28,代碼來源:JGitUtils.java

示例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;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:26,代碼來源:JGitUtils.java

示例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();
  }
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:37,代碼來源:FileContentUtil.java

示例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;
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:52,代碼來源:RawServlet.java

示例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;
}
 
開發者ID:tomaswolf,項目名稱:gerrit-gitblit-plugin,代碼行數:62,代碼來源:CompressionUtils.java

示例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;

}
 
開發者ID:miho,項目名稱:VGitArchive,代碼行數:64,代碼來源:VersionedFile.java

示例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;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:54,代碼來源:JGitUtils.java

示例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;
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:64,代碼來源:CompressionUtils.java

示例10: getFileMode

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
@Nullable
public static FileMode getFileMode(TreeWalk tw) {
  return tw.getFileMode(0);
}
 
開發者ID:beijunyi,項目名稱:ParallelGit,代碼行數:5,代碼來源:TreeUtils.java

示例11: PathInfo

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
protected PathInfo(TreeWalk tw) {
  fileMode = tw.getFileMode(0);
  path = tw.getPathString();
  objectId = tw.getObjectId(0);
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:6,代碼來源:VersionedMetaData.java


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