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


Java TreeWalk.getObjectId方法代碼示例

本文整理匯總了Java中org.eclipse.jgit.treewalk.TreeWalk.getObjectId方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeWalk.getObjectId方法的具體用法?Java TreeWalk.getObjectId怎麽用?Java TreeWalk.getObjectId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jgit.treewalk.TreeWalk的用法示例。


在下文中一共展示了TreeWalk.getObjectId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getLoaderFrom

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
 * Gets the loader for a file from a specified commit and its path
 * 
 * @param commit
 *          - the commit from which to get the loader
 * @param path
 *          - the path to the file
 * @return the loader
 * @throws MissingObjectException
 * @throws IncorrectObjectTypeException
 * @throws CorruptObjectException
 * @throws IOException
 */
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
		throws IOException {
	Repository repository = git.getRepository();
	RevWalk revWalk = new RevWalk(repository);
	RevCommit revCommit = revWalk.parseCommit(commit);
	// and using commit's tree find the path
	RevTree tree = revCommit.getTree();
	TreeWalk treeWalk = new TreeWalk(repository);
	treeWalk.addTree(tree);
	treeWalk.setRecursive(true);
	treeWalk.setFilter(PathFilter.create(path));

	ObjectLoader loader = null;
	if (treeWalk.next()) {
		ObjectId objectId = treeWalk.getObjectId(0);
		loader = repository.open(objectId);
	}

	treeWalk.close();
	revWalk.close();
	return loader;
}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:36,代碼來源:GitAccess.java

示例4: getFileFromCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static boolean getFileFromCommit(final OutputStream os, final String file, final Repository repo, final RevTree tree) throws IOException, GitAPIException {
    final TreeWalk treeWalk = new TreeWalk(repo);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(true);
    treeWalk.setFilter(PathFilter.create(file));
    if (!treeWalk.next()) {
        logger.info("Did not find expected file '" + file + "'");
        return false;
    }

    final ObjectId objectId = treeWalk.getObjectId(0);
    final ObjectLoader loader = repo.open(objectId);

    // and then one can the loader to read the file
    loader.copyTo(os);
    return true;
}
 
開發者ID:cobr123,項目名稱:VirtaMarketAnalyzer,代碼行數:18,代碼來源:GitHubPublisher.java

示例5: getBlob

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
private Optional<String[]> getBlob(Git git, String fileName, CodeRevision revision)
		throws IOException {
	TreeWalk treeWalk = new TreeWalk(git.getRepository());
	treeWalk.addTree(getTreeIterator(git, revision));
	treeWalk.setFilter(PathFilter.create(fileName));
	treeWalk.setRecursive(true);
	if (!treeWalk.next()) {
		return Optional.empty();
	}
	ObjectId blobId = treeWalk.getObjectId(0);
	String content = new String(git.getRepository().getObjectDatabase().open(blobId).getBytes(),
			Charset.forName("UTF-8"));

	String[] lines = content.split("\n");
	return Optional.of(lines);
}
 
開發者ID:bugminer,項目名稱:bugminer,代碼行數:17,代碼來源:GitStrategy.java

示例6: getFileAsDiffFormat

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public List<DiffInfo> getFileAsDiffFormat(RepositoryPK repositoryPK, String ref) {
  try (RepositoryReader reader = new RepositoryReader(repositoryPK)) {
    Git git = reader.getGit();
    Repository repository = reader.getRepository();

    ObjectId objectId = repository.resolve(ref);
    List<RevCommit> commits = getFirstCommits(git, objectId, null, 2);

    TreeWalk treeWalk = new TreeWalk(repository);
    List<DiffInfo> diffInfos = new ArrayList<>();
    treeWalk.addTree(commits.get(0).getTree());
    treeWalk.setRecursive(true);
    while (treeWalk.next()) {
      ObjectId fileId = treeWalk.getObjectId(0);
      if (!treeWalk.isSubtree()) {
        FileContent fileContent = getFileContent(git, treeWalk.getPathString(), fileId);
        diffInfos.add(DiffInfo.ofNewCommit(fileContent));
      }
    }
    return diffInfos;
  } catch (IOException | GitAPIException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:kamegu,項目名稱:git-webapp,代碼行數:25,代碼來源:GitOperation.java

示例7: setObject

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public void setObject(RevTree tree, View view, Repository repo) {
    TreeWalk treeWalk = new TreeWalk(repo);
    StringBuilder sb = new StringBuilder();
    try {
        int treeIndex = treeWalk.addTree(tree);
        while (treeWalk.next()) {
            ObjectId newObjectId = treeWalk.getObjectId(treeIndex);
            String rawPath = new String(treeWalk.getRawPath());
            sb.append(rawPath).append(" - ");
            //System.out.println(newObjectId+" rawPath="+rawPath+" subTree="+ tw.isSubtree());
        }
        ((TextView) view.findViewById(R.id.osv_tree_description)).setText(sb);
    } catch (Exception e) {
        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }
}
 
開發者ID:m4rzEE1,項目名稱:ninja_chic-,代碼行數:17,代碼來源:TreeSummaryView.java

示例8: getBlob

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
/**
 * Read blob content and cache result in repository in case the same blob 
 * content is requested again. 
 * 
 * We made this method thread-safe as we are using ForkJoinPool to calculate 
 * diffs of multiple blob changes concurrently, and this method will be 
 * accessed concurrently in that special case.
 * 
 * @param blobIdent
 * 			ident of the blob
 * @return
 * 			blob of specified blob ident
 * @throws
 * 			ObjectNotFoundException if blob of specified ident can not be found in repository 
 * 			
 */
public Blob getBlob(BlobIdent blobIdent) {
	Preconditions.checkArgument(blobIdent.revision!=null && blobIdent.path!=null && blobIdent.mode!=null, 
			"Revision, path and mode of ident param should be specified");
	
	Blob blob = getBlobCache().get(blobIdent);
	if (blob == null) {
		try (RevWalk revWalk = new RevWalk(getRepository())) {
			ObjectId revId = getObjectId(blobIdent.revision);		
			RevTree revTree = revWalk.parseCommit(revId).getTree();
			TreeWalk treeWalk = TreeWalk.forPath(getRepository(), blobIdent.path, revTree);
			if (treeWalk != null) {
				ObjectId blobId = treeWalk.getObjectId(0);
				if (blobIdent.isGitLink()) {
					String url = getSubmodules(blobIdent.revision).get(blobIdent.path);
					if (url == null)
						throw new ObjectNotFoundException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules");
					String hash = blobId.name();
					blob = new Blob(blobIdent, blobId, new Submodule(url, hash).toString().getBytes());
				} else if (blobIdent.isTree()) {
					throw new NotFileException("Path '" + blobIdent.path + "' is a tree");
				} else {
					blob = new Blob(blobIdent, blobId, treeWalk.getObjectReader());
				}
				getBlobCache().put(blobIdent, blob);
			} else {
				throw new ObjectNotFoundException("Unable to find blob path '" + blobIdent.path + "' in revision '" + blobIdent.revision + "'");
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	return blob;
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:50,代碼來源:Project.java

示例9: getLastRevision

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static void getLastRevision(Git git, String base, String name, 
     String rev, OutputStream out, String ext) 
                         throws WsSrvException, IOException {

  checkFile(base, name, ext);
   String fp = getLocalPath(name);
   
   // find the HEAD
   ObjectId lastCommitId = git.getRepository().resolve(Constants.HEAD);

   // a RevWalk allows to walk over commits based on 
   // 									some filtering that is defined
   RevWalk revWalk = new RevWalk(git.getRepository());
   RevCommit commit = revWalk.parseCommit(lastCommitId);
   // 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(git.getRepository());
   treeWalk.addTree(tree);
   treeWalk.setRecursive(true);
   treeWalk.setFilter(PathFilter.create(fp));
   
   if (!treeWalk.next()) {
       throw new IllegalStateException(
       		"Did not find expected file 'README.md'");
   }

   ObjectId objectId = treeWalk.getObjectId(0);
   System.out.println("ObjectId: " + objectId.toString());
   ObjectLoader loader = git.getRepository().open(objectId);

   // and then one can the loader to read the file
   loader.copyTo(System.out);

   revWalk.dispose();
  
}
 
開發者ID:osbitools,項目名稱:OsBiToolsWs,代碼行數:40,代碼來源:GitUtils.java

示例10: getObjectId

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
protected ObjectId getObjectId(String fileName) throws IOException {
  if (revision == null) {
    return null;
  }

  TreeWalk tw = TreeWalk.forPath(reader, fileName, revision.getTree());
  if (tw != null) {
    return tw.getObjectId(0);
  }

  return null;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:13,代碼來源:VersionedMetaData.java

示例11: 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

示例12: getFileContent

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public FileContent getFileContent(RepositoryPK repositoryPK, RefPath refPath) {
  try (RepositoryReader reader = new RepositoryReader(repositoryPK)) {
    Git git = reader.getGit();
    Repository repository = reader.getRepository();

    RevTree revTree = JGitUtils.getRevTree(repository, refPath.getRefName());

    TreeWalk treeWalk = TreeWalk.forPath(repository, refPath.getPath(), revTree);

    ObjectId fileId = treeWalk.getObjectId(0);
    return getFileContent(git, refPath.getPath(), fileId);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:kamegu,項目名稱:git-webapp,代碼行數:16,代碼來源:GitOperation.java

示例13: getFileContentOfLastCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static File getFileContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);

	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// 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);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath));
	if (!treeWalk.next()) {
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}

	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);

	return Utils.inputStreamToFile(loader.openStream());
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:30,代碼來源:Utils.java

示例14: getStringContentOfLastCommit

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static String getStringContentOfLastCommit(String filePath,Repository repository) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(Constants.HEAD);
	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// 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);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath));
	if (!treeWalk.next()) {
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}

	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);
	
	return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:28,代碼來源:Utils.java

示例15: getStringContentOfCommitID

import org.eclipse.jgit.treewalk.TreeWalk; //導入方法依賴的package包/類
public static String getStringContentOfCommitID(String filePath,Repository repository, String commitID) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException {
	// find the HEAD
	ObjectId lastCommitId = repository.resolve(commitID);

	// a RevWalk allows to walk over commits based on some filtering that is
	// defined
	RevWalk revWalk = new RevWalk(repository);
	RevCommit commit = revWalk.parseCommit(lastCommitId);
	// 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);
	treeWalk.setPostOrderTraversal(true);
	treeWalk.setFilter(PathFilter.create(filePath.substring(filePath.indexOf("/") + 1)));
	if (!treeWalk.next()) {
		
		//TODO the file is added to project
		throw new IllegalStateException(
				"CHANGECOMMIT -- Did not find expected file '" + filePath + "'");
	}
	ObjectId objectId = treeWalk.getObjectId(0);
	ObjectLoader loader = repository.open(objectId);
	return IOUtils.stringFromFile(Utils.inputStreamToFile(loader.openStream()).getAbsolutePath(), "utf-8");
}
 
開發者ID:SEMERU-WM,項目名稱:ChangeScribe,代碼行數:29,代碼來源:Utils.java


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