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


Java DiffFormatter.setRepository方法代碼示例

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


在下文中一共展示了DiffFormatter.setRepository方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fillLastModifiedCommits

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void fillLastModifiedCommits(ObjectId start, String basePath) throws IOException, GitAPIException {
    Map<String, ObjectId> objects = lastModifiedCommits.get(start);
    if (objects == null) {
        objects = new TreeMap<>();
    }
    DiffFormatter diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
    diffFmt.setRepository(getGitRepository());
    LogCommand log = new Git(getGitRepository()).log();
    if (!basePath.isEmpty()) {
        log.addPath(basePath);
    }
    for(RevCommit c: log.call()) {
        final RevTree a = c.getParentCount() > 0 ? c.getParent(0).getTree() : null;
        final RevTree b = c.getTree();

        for(DiffEntry diff: diffFmt.scan(a, b)) {
            objects.put(diff.getNewPath(), c.getId());
        }
    }
    lastModifiedCommits.put(start, objects);
}
 
開發者ID:naver,項目名稱:svngit,代碼行數:22,代碼來源:GitFS.java

示例2: getPaths

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private List<DiffEntry> getPaths(Repository repository, RevCommit rev)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	RevCommit parent = null;
	List<DiffEntry> diffs = null;
	RevWalk rw = new RevWalk(repository);
	DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);

	df.setRepository(repository);
	df.setDiffComparator(RawTextComparator.DEFAULT);
	df.setDetectRenames(true);

	if (rev.getParentCount() > 0 && rev.getParent(0) != null) {
		parent = rw.parseCommit(rev.getParent(0).getId());
		diffs = df.scan(parent.getTree(), rev.getTree());
	} else {
		diffs = df.scan(new EmptyTreeIterator(), new CanonicalTreeParser(
				null, rw.getObjectReader(), rev.getTree()));
	}

	return diffs;
}
 
開發者ID:aserg-ufmg,項目名稱:ModularityCheck,代碼行數:23,代碼來源:GITLogHandler.java

示例3: isInPath

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private boolean isInPath(Repository repository, RevWalk walk, RevCommit commit) throws IOException {
    if (commit.getParentCount() == 0) {
        RevTree tree = commit.getTree();
        try (TreeWalk treeWalk = new TreeWalk(repository)) {
            treeWalk.addTree(tree);
            treeWalk.setRecursive(true);
            treeWalk.setFilter(pathFilter);
            return treeWalk.next();
        }
    } else {
        DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
        df.setRepository(repository);
        df.setPathFilter(pathFilter);
        RevCommit parent = walk.parseCommit(commit.getParent(0).getId());
        List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
        return !diffs.isEmpty();
    }
}
 
開發者ID:jakubplichta,項目名稱:git-changelog-maven-plugin,代碼行數:19,代碼來源:RepositoryProcessor.java

示例4: getDiffBetweenCommits

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public String getDiffBetweenCommits(int commitIndex) throws IOException,GitAPIException{
    if(commitIndex+1==commitCount)
        return "Nothing to Diff. This is first commit";
    AbstractTreeIterator current = prepareTreeParser(repository,commitSHA.get(commitIndex));
    AbstractTreeIterator parent = prepareTreeParser(repository,commitSHA.get(++commitIndex));
    ObjectReader reader = repository.newObjectReader();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    // finally get the list of changed files
    Git git = new Git(repository) ;
    List<DiffEntry> diff = git.diff().
            setOldTree(parent).
            setNewTree(current).
            //TODO Set the path filter to filter out the selected file
            //setPathFilter(PathFilter.create("README.md")).
            call();
    for (DiffEntry entry : diff) {
        System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
        DiffFormatter formatter = new DiffFormatter(byteStream) ;
            formatter.setRepository(repository);
            formatter.format(entry);
        }
   // System.out.println(byteStream.toString());
    String diffContent = byteStream.toString();
    return byteStream.toString();
}
 
開發者ID:jughyd,項目名稱:GitFx,代碼行數:26,代碼來源:GitRepoMetaData.java

示例5: getDiffString

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private String getDiffString() throws GitAPIException, IOException {
    ObjectId head = this.repo.resolve("HEAD");
    if(head == null) return "";

    // The following code is largely written by Tk421 on StackOverflow
    //      (http://stackoverflow.com/q/23486483)
    // Thanks! NOTE: comments are mine.
    ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
    DiffFormatter formatter = new DiffFormatter(diffOutputStream);
    formatter.setRepository(this.repo);
    formatter.setPathFilter(PathFilter.create(this.pathFilter.replaceAll("\\\\","/")));

    AbstractTreeIterator commitTreeIterator = prepareTreeParser(this.repo, head.getName());
    FileTreeIterator workTreeIterator = new FileTreeIterator(this.repo);

    // Scan gets difference between the two iterators.
    formatter.format(commitTreeIterator, workTreeIterator);

    return diffOutputStream.toString();
}
 
開發者ID:dmusican,項目名稱:Elegit,代碼行數:21,代碼來源:DiffHelper.java

示例6: listFilesChangedInCommit

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private HashSet<String> listFilesChangedInCommit(Repository repository, AnyObjectId beforeID, AnyObjectId afterID) throws MissingObjectException, IncorrectObjectTypeException, IOException
{
	log.info("calculating files changed in commit");
	HashSet<String> result = new HashSet<>();
	RevWalk rw = new RevWalk(repository);
	RevCommit commitBefore = rw.parseCommit(beforeID);
	RevCommit commitAfter = rw.parseCommit(afterID);
	DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
	df.setRepository(repository);
	df.setDiffComparator(RawTextComparator.DEFAULT);
	df.setDetectRenames(true);
	List<DiffEntry> diffs = df.scan(commitBefore.getTree(), commitAfter.getTree());
	for (DiffEntry diff : diffs)
	{
		result.add(diff.getNewPath());
	}
	log.debug("Files changed between commits commit: {} and {} - {}", beforeID.getName(), afterID, result);
	return result;
}
 
開發者ID:Apelon-VA,項目名稱:ISAAC,代碼行數:20,代碼來源:SyncServiceGIT.java

示例7: getAllHistories

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
@Override
public Map<String, List<Revision>> getAllHistories() throws StoreException {
    final TestMatrixDefinition testMatrixDefinition = getCurrentTestMatrix().getTestMatrixDefinition();
    if (testMatrixDefinition == null) {
        return Collections.emptyMap();
    }
    final Set<String> activeTests = testMatrixDefinition.getTests().keySet();

    final Repository repository = git.getRepository();
    try {
        final ObjectId head = repository.resolve(Constants.HEAD);
        final RevWalk revWalk = new RevWalk(repository);
        final DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
        df.setRepository(git.getRepository());
        df.setDiffComparator(RawTextComparator.DEFAULT);

        final HistoryParser historyParser = new HistoryParser(revWalk, df, getTestDefinitionsDirectory(), activeTests);
        return historyParser.parseFromHead(head);

    } catch (final IOException e) {
        throw new StoreException("Could not get history " + getGitCore().getRefName(), e);
    }
}
 
開發者ID:indeedeng,項目名稱:proctor,代碼行數:24,代碼來源:GitProctor.java

示例8: formatHtmlDiff

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void formatHtmlDiff(OutputStream out,
    Repository repo, RevWalk walk,
    AbstractTreeIterator oldTree, AbstractTreeIterator newTree,
    String path)
    throws IOException {
  DiffFormatter diff = new HtmlDiffFormatter(renderer, out);
  try {
    if (!path.equals("")) {
      diff.setPathFilter(PathFilter.create(path));
    }
    diff.setRepository(repo);
    diff.setDetectRenames(true);
    diff.format(oldTree, newTree);
  } finally {
    diff.release();
  }
}
 
開發者ID:afrojer,項目名稱:gitiles,代碼行數:18,代碼來源:DiffServlet.java

示例9: getCommitStatistics

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/** 각 유저가 날짜별로 커밋을 한 정보를 취합함.
 * @return
 */
public GitParentStatistics getCommitStatistics(){
	GitParentStatistics gitParentStatistics = new GitParentStatistics();
	try{
		for(RevCommit rc:git.log().all().call()){
			String diffs = new String();
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			if(rc.getParentCount()>0){
				DiffFormatter df = new DiffFormatter(out);
				df.setRepository(this.localRepo);
				df.format(rc.getParent(0), rc);
				df.flush();
				diffs = out.toString();
			} else {
				diffs = simpleFileBrowser(rc);
			}
			int addFile = StringUtils.countOccurrencesOf(diffs, "--- /dev/null");// 추가한 파일 수
			int deleteFile = StringUtils.countOccurrencesOf(diffs, "+++ /dev/null");// 삭제한 파일 수
			diffs = StringUtils.delete(diffs, "\n--- ");
			diffs = StringUtils.delete(diffs, "\n+++ ");
			gitParentStatistics.addGitChildStatistics(
					new GitChildStatistics(
							rc.getAuthorIdent().getEmailAddress(), // 유저 이메일
							StringUtils.countOccurrencesOf(diffs, "\n+"), //추가한 라인 수
							StringUtils.countOccurrencesOf(diffs, "\n-"), //삭제한 라인 수
							addFile,
							deleteFile,
							rc.getAuthorIdent().getWhen())); // 날짜
		}

	}catch(Exception e){
		System.err.println(e.getMessage());
	}
	return gitParentStatistics;
}
 
開發者ID:forweaver,項目名稱:forweaver2.0,代碼行數:38,代碼來源:GitUtil.java

示例10: testDiffRenameDetectionProblem

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public void testDiffRenameDetectionProblem () throws Exception {
    File file = new File(workDir, "file");
    File renamed = new File(workDir, "renamed");
    File patchFile = new File(workDir.getParentFile(), "diff.patch");
    write(file, "hey, i will be renamed\n");
    add(file);
    commit(file);
    
    file.renameTo(renamed);
    write(renamed, "hey, i will be renamed\nand now i am\n");
    OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile));
    DiffFormatter formatter = new DiffFormatter(out);
    formatter.setRepository(repository);
    ObjectReader or = null;
    try {
        formatter.setDetectRenames(true);
        AbstractTreeIterator firstTree = new DirCacheIterator(repository.readDirCache());;
        AbstractTreeIterator secondTree = new FileTreeIterator(repository);
        formatter.format(firstTree, secondTree);
        formatter.flush();
        fail("Fixed in JGit, modify and simplify the sources in ExportDiff command");
    } catch (IOException ex) {
        assertEquals("Missing blob 7b34a309b8dbae2686c9e597efef28a612e48aff", ex.getMessage());
    } finally {
        if (or != null) {
            or.release();
        }
        formatter.release();
    }
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:ExportDiffTest.java

示例11: generatePatches

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public void generatePatches() throws Exception {
    git.add().addFilepattern(".").call();
    git.commit().setMessage("generate patches").call();
    DiffFormatter formatter = new DiffFormatter(null);
    formatter.setRepository(git.getRepository());
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), getHead());
    getChangedFiles().forEach((path) -> {
        for (DiffEntry entry : entries) {
            Path diffPath = Paths.get(entry.getPath(DiffEntry.Side.NEW));
            if (diffPath.equals(path)) {
                File patchFile = new File(this.patchDirectory, diffPath.getFileName() + ".patch");
                try {
                    DiffFormatter diffFormatter = new DiffFormatter(new FileOutputStream
                            (patchFile));
                    diffFormatter.setRepository(git.getRepository());
                    diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
                    diffFormatter.setContext(3);
                    diffFormatter.format(entry);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
 
開發者ID:PizzaCrust,項目名稱:IodineToolkit,代碼行數:28,代碼來源:PatchService.java

示例12: getChangedFiles

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public List<Path> getChangedFiles() throws IOException {
    List<Path> changedFiles = new ArrayList<>();
    RevWalk revWalk = new RevWalk(git.getRepository());
    AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
    RevCommit head = revWalk.parseCommit(headId);
    DiffFormatter formatter = new DiffFormatter(null);
    formatter.setRepository(git.getRepository());
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), head);
    entries.forEach((diffEntry -> changedFiles.add(Paths.get(diffEntry.getPath(DiffEntry.Side.NEW)))));
    return changedFiles;
}
 
開發者ID:PizzaCrust,項目名稱:IodineToolkit,代碼行數:14,代碼來源:PatchService.java

示例13: createDiffFormatter

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
protected static DiffFormatter createDiffFormatter(Repository r, OutputStream buffer) {
    DiffFormatter formatter = new DiffFormatter(buffer);
    formatter.setRepository(r);
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    return formatter;
}
 
開發者ID:fabric8io,項目名稱:fabric8-forge,代碼行數:8,代碼來源:RepositoryResource.java

示例14: getDiffFormatter

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
 * Get diff formatter.
 *
 * @param filePath optional filter for diff
 * @return diff formater
 */
private DiffFormatter getDiffFormatter(String filePath) {
    final DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
    df.setRepository(repository);
    df.setDiffComparator(RawTextComparator.DEFAULT);
    df.setDetectRenames(true);
    if (filePath != null) {
        df.setPathFilter(PathFilter.create(filePath));
    }
    return df;
}
 
開發者ID:iazarny,項目名稱:gitember,代碼行數:17,代碼來源:GitRepositoryService.java

示例15: walkFilesInCommit

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void walkFilesInCommit(
    Git gitClient,
    RevCommit commit,
    List<SourceCodeFileAnalyzerPlugin> analyzers,
    MetricsProcessor metricsProcessor)
    throws IOException {
  commit = CommitUtils.getCommit(gitClient.getRepository(), commit.getId());
  logger.info("starting analysis of commit {}", commit.getName());
  DiffFormatter diffFormatter = new DiffFormatter(DisabledOutputStream.INSTANCE);
  diffFormatter.setRepository(gitClient.getRepository());
  diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
  diffFormatter.setDetectRenames(true);

  ObjectId parentId = null;
  if (commit.getParentCount() > 0) {
    // TODO: support multiple parents
    parentId = commit.getParent(0).getId();
  }

  List<DiffEntry> diffs = diffFormatter.scan(parentId, commit);
  for (DiffEntry diff : diffs) {
    String filePath = diff.getPath(DiffEntry.Side.NEW);
    byte[] fileContent =
        BlobUtils.getRawContent(gitClient.getRepository(), commit.getId(), filePath);
    FileMetrics metrics = fileAnalyzer.analyzeFile(analyzers, filePath, fileContent);
    FileMetricsWithChangeType metricsWithChangeType =
        new FileMetricsWithChangeType(
            metrics, changeTypeMapper.jgitToCoderadar(diff.getChangeType()));
    metricsProcessor.processMetrics(metricsWithChangeType, gitClient, commit.getId(), filePath);
  }
  metricsProcessor.onCommitFinished(gitClient, commit.getId());
}
 
開發者ID:reflectoring,項目名稱:coderadar,代碼行數:33,代碼來源:AnalyzingCommitProcessor.java


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