当前位置: 首页>>代码示例>>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;未经允许,请勿转载。