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


Java TreeWalk.getPathString方法代码示例

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


在下文中一共展示了TreeWalk.getPathString方法的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: simpleFileBrowser

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/** 단순하게 커밋을 트리워크를 이용하여 당시 파일 내역을 출력.
 * @param commit
 * @return
 */
private String simpleFileBrowser(RevCommit commit){
	String out = new String();
	try
	{
		TreeWalk treeWalk = new TreeWalk(this.localRepo);
		treeWalk.addTree(new RevWalk(this.localRepo).parseTree(	commit));

		while (treeWalk.next())
		{
			out+="--- /dev/null\n";
			out+="+++ b/"+treeWalk.getPathString()+"\n";
			out+= "+"+BlobUtils.getContent(this.localRepo, commit,treeWalk.getPathString().replace("\n", "\n+"));
			out+="\n";
		}
	}finally{
		return out;
	}
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:23,代码来源:GitUtil.java

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

示例5: getChange

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private BlobChange getChange(TreeWalk treeWalk, RevCommit oldCommit, RevCommit newCommit) {
	DiffEntry.ChangeType changeType = DiffEntry.ChangeType.MODIFY;
	BlobIdent oldBlobIdent;
	if (!treeWalk.getObjectId(0).equals(ObjectId.zeroId())) {
		oldBlobIdent = new BlobIdent(oldCommit.name(), treeWalk.getPathString(), treeWalk.getRawMode(0));
	} else {
		oldBlobIdent = new BlobIdent(oldCommit.name(), null, FileMode.TREE.getBits());
		changeType = DiffEntry.ChangeType.ADD;
	}
	
	BlobIdent newBlobIdent;
	if (!treeWalk.getObjectId(1).equals(ObjectId.zeroId())) {
		newBlobIdent = new BlobIdent(newCommit.name(), treeWalk.getPathString(), treeWalk.getRawMode(1));
	} else {
		newBlobIdent = new BlobIdent(newCommit.name(), null, FileMode.TREE.getBits());
		changeType = DiffEntry.ChangeType.DELETE;
	}
	
	return new BlobChange(changeType, oldBlobIdent, newBlobIdent, WhitespaceOption.DEFAULT) {

		@Override
		public Blob getBlob(BlobIdent blobIdent) {
			return context.getProject().getBlob(blobIdent);
		}

	};
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:28,代码来源:CommitOptionPanel.java

示例6: collect

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public void collect(IndexSearcher searcher, TreeWalk treeWalk, List<QueryHit> hits) {
	String blobPath = treeWalk.getPathString();
	Range range = PathUtils.matchSegments(blobPath, match, true);
	if (range != null) {
		hits.add(new PathHit(blobPath, range));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:9,代码来源:PathQuery.java

示例7: getAllMetadata

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Replicates ls-tree for the current commit.
 *
 * @return Map containing the full path and the data for all items in the repository.
 * @throws IOException
 */
public Map<String, byte[]> getAllMetadata() throws Exception
{
    Map<String, byte[]> contents = new HashMap<String, byte[]>();
    ObjectReader reader = repository.newObjectReader();
    ObjectId commitId = repository.resolve(curCommit);
    RevWalk revWalk = new RevWalk(reader);
    RevCommit commit = revWalk.parseCommit(commitId);
    RevTree tree = commit.getTree();
    TreeWalk treeWalk = new TreeWalk(reader);
    treeWalk.addTree(tree);
    treeWalk.setRecursive(false);

    while (treeWalk.next())
    {
        if (treeWalk.isSubtree())
        {
            treeWalk.enterSubtree();
        }
        else
        {
            String member = treeWalk.getPathString();
            if (member.contains(SOURCEDIR))
            {
                byte[] data = getBlob(member, curCommit);
                contents.put(member, data);
            }
        }
    }

    reader.release();

    return contents;
}
 
开发者ID:aesanch2,项目名称:salesforce-migration-assistant,代码行数:40,代码来源:SMAGit.java

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

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

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

示例11: toIndexFile

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
private IndexFile toIndexFile(Context context, TreeWalk treeWalk, RevCommit revCommit, ObjectId objectId) throws IOException {
    File file = new File(treeWalk.getPathString());
    String id = String.format("%s|%s|%s|%s", FILE.name().toLowerCase(), context.getName(), revCommit.name(), file.getPath());
    logger.debug("Indexing file with id {}", id);
    return IndexFile.indexFile()
        .id(id)
        .commit(revCommit.name())
        .project(context.getName())
        .path(file.getPath())
        .name(file.getName())
        .extension(Files.getFileExtension(file.getAbsolutePath()))
        .content(safeContent(context, objectId))
        .build();
}
 
开发者ID:obazoud,项目名称:elasticsearch-river-git,代码行数:15,代码来源:RevCommitToIndexFile.java

示例12: getRepoMetadata

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
/**
 * Fetch all commit metadata from the repo
 * @param repoDir repository directory
 * @return list of commit metadata
 * @throws IOException
 * @throws GitAPIException
 */
public static List<CommitMetadata> getRepoMetadata(String repoDir) throws IOException, GitAPIException {

  List<CommitMetadata> metadataList = new ArrayList<>();

  FileRepositoryBuilder builder = new FileRepositoryBuilder();
  Repository repository = builder.setGitDir(new File(repoDir, ".git")).readEnvironment().findGitDir().build();

  // Current branch may not be master. Instead of hard coding determine the current branch
  String currentBranch = repository.getBranch();
  Ref head = repository.getRef("refs/heads/" + currentBranch); // current branch may not be "master"
  if (head == null) {
    return metadataList;
  }

  Git git = new Git(repository);

  RevWalk walk = new RevWalk(repository);
  RevCommit commit = walk.parseCommit(head.getObjectId());

  TreeWalk treeWalk = new TreeWalk(repository);
  treeWalk.addTree(commit.getTree());
  treeWalk.setRecursive(true);
  while (treeWalk.next()) {
    String filePath = treeWalk.getPathString();
    Iterable<RevCommit> commitLog = git.log().add(repository.resolve(Constants.HEAD)).addPath(filePath).call();
    for (RevCommit r : commitLog) {
      CommitMetadata metadata = new CommitMetadata(r.getName());
      metadata.setFilePath(filePath);
      metadata.setFileName(FilenameUtils.getName(filePath));
      metadata.setMessage(r.getShortMessage().trim());
      // Difference between committer and author
      // refer to: http://git-scm.com/book/ch2-3.html
      PersonIdent committer = r.getCommitterIdent();
      PersonIdent author = r.getAuthorIdent();
      metadata.setAuthor(author.getName());
      metadata.setAuthorEmail(author.getEmailAddress());
      metadata.setCommitter(committer.getName());
      metadata.setCommitterEmail(committer.getEmailAddress());
      metadata.setCommitTime(committer.getWhen());
      metadataList.add(metadata);
    }
  }
  git.close();
  return metadataList;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:53,代码来源:GitUtil.java

示例13: testAddMixedLineEndings

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
public void testAddMixedLineEndings () throws Exception {
    File f = new File(workDir, "f");
    String content = "";
    for (int i = 0; i < 10000; ++i) {
        content += i + "\r\n";
    }
    write(f, content);
    File[] files = new File[] { f };
    GitClient client = getClient(workDir);
    client.add(files, NULL_PROGRESS_MONITOR);
    client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR);
    
    Map<File, GitStatus> statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
    
    // lets turn autocrlf on
    StoredConfig cfg = repository.getConfig();
    cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true");
    cfg.save();
    
    // when this starts failing, remove the work around
    ObjectInserter inserter = repository.newObjectInserter();
    TreeWalk treeWalk = new TreeWalk(repository);
    treeWalk.setFilter(PathFilterGroup.createFromStrings("f"));
    treeWalk.setRecursive(true);
    treeWalk.reset();
    treeWalk.addTree(new FileTreeIterator(repository));
    while (treeWalk.next()) {
        String path = treeWalk.getPathString();
        assertEquals("f", path);
        WorkingTreeIterator fit = treeWalk.getTree(0, WorkingTreeIterator.class);
        InputStream in = fit.openEntryStream();
        try {
            inserter.insert(Constants.OBJ_BLOB, fit.getEntryLength(), in);
            fail("this should fail, remove the work around");
        } catch (EOFException ex) {
            assertEquals("Input did not match supplied length. 10000 bytes are missing.", ex.getMessage());
        } finally {
            in.close();
            inserter.release();
        }
        break;
    }
    
    // no err should occur
    write(f, content + "hello");
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false);
    client.add(files, NULL_PROGRESS_MONITOR);
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false);
    client.commit(files, "message", null, null, NULL_PROGRESS_MONITOR);
    statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
    assertEquals(1, statuses.size());
    assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:AddTest.java

示例14: collect

import org.eclipse.jgit.treewalk.TreeWalk; //导入方法依赖的package包/类
@Override
public void collect(IndexSearcher searcher, TreeWalk treeWalk, List<QueryHit> hits) {
	String blobPath = treeWalk.getPathString();
	ObjectId blobId = treeWalk.getObjectId(0);
	
	List<Symbol> symbols = GitPlex.getInstance(SearchManager.class).getSymbols(searcher, blobId, blobPath);
	if (symbols != null) {
		for (Symbol symbol: symbols) {
			if (hits.size() < getCount()) {
				if ((primary==null || primary.booleanValue() == symbol.isPrimary()) 
						&& symbol.getName() != null 
						&& symbol.isSearchable()
						&& (local == null || local.booleanValue() == symbol.isLocalInHierarchy())) {
					String normalizedTerm;
					if (!caseSensitive)
						normalizedTerm = term.toLowerCase();
					else
						normalizedTerm = term;
					
					String normalizedSymbolName;
					if (!caseSensitive)
						normalizedSymbolName = symbol.getName().toLowerCase();
					else
						normalizedSymbolName = symbol.getName();
					
					String normalizedExcludeTerm;
					if (excludeTerm != null) {
						if (!caseSensitive)
							normalizedExcludeTerm = excludeTerm.toLowerCase();
						else
							normalizedExcludeTerm = excludeTerm;
					} else {
						normalizedExcludeTerm = null;
					}
					if (WildcardUtils.matchString(normalizedTerm, normalizedSymbolName)
							&& (normalizedExcludeTerm == null || !normalizedSymbolName.equals(normalizedExcludeTerm))
							&& (excludeBlobPath == null || !excludeBlobPath.equals(blobPath))) {
						Range matchRange = WildcardUtils.rangeOfMatch(normalizedTerm, normalizedSymbolName);
						hits.add(new SymbolHit(blobPath, symbol, matchRange));
					}
				}
			} else {
				break;
			}
		}
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:48,代码来源:SymbolQuery.java

示例15: 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.getPathString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。