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


Java DiffFormatter.flush方法代碼示例

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


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

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

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

示例3: convert

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
 * Construct a generic file object from the attributes of a git DiffEntry.
 *
 * @param  diff    DiffEntry data object
 * @return CMnFile data object
 */
private CMnFile convert(DiffEntry diff) {
    String filename = diff.getNewPath();
    CMnFile.Operation op = null;
    DiffEntry.ChangeType changeType = diff.getChangeType();
    if (changeType == DiffEntry.ChangeType.ADD){
        op = CMnFile.Operation.ADD;
    } else if (changeType == DiffEntry.ChangeType.DELETE){
        op = CMnFile.Operation.DELETE;
    } else if (changeType == DiffEntry.ChangeType.RENAME){
        op = CMnFile.Operation.RENAME;
    } else {
        op = CMnFile.Operation.EDIT;
    }
    CMnFile file = new CMnFile(filename, op);

    // Convert the file diff to a string
    try {
        OutputStream out = new ByteArrayOutputStream();
        DiffFormatter df = new DiffFormatter(out);
        df.setRepository(repository.getRepository());
        df.setDiffComparator(diffComparator);
        df.setDetectRenames(true);
        df.format(diff);
        df.flush();
        file.setDiff(out.toString());
    } catch (IOException ioex) {
    }

    return file;
}
 
開發者ID:ModelN,項目名稱:build-management,代碼行數:37,代碼來源:CMnGitServer.java

示例4: run

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
@Override
  protected void run() throws GitException {
      Repository repository = getRepository();
      DiffFormatter formatter = new DiffFormatter(out);
      formatter.setRepository(repository);
      ObjectReader or = null;
      String workTreePath = repository.getWorkTree().getAbsolutePath();
      try {
          Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
          if (!pathFilters.isEmpty()) {
              formatter.setPathFilter(PathFilterGroup.create(pathFilters));
          }
          if (repository.getConfig().get(WorkingTreeOptions.KEY).getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
              // work-around for autocrlf
              formatter.setDiffComparator(new AutoCRLFComparator());
          }
          or = repository.newObjectReader();
          AbstractTreeIterator firstTree = getIterator(firstCommit, or);
          AbstractTreeIterator secondTree = getIterator(secondCommit, or);
          List<DiffEntry> diffEntries;
          if (secondTree instanceof WorkingTreeIterator) {
              // remote when fixed in JGit, see ExportDiffTest.testDiffRenameDetectionProblem
              formatter.setDetectRenames(false);
              diffEntries = formatter.scan(firstTree, secondTree);
              formatter.setDetectRenames(true);
              RenameDetector detector = formatter.getRenameDetector();
              detector.reset();
              detector.addAll(diffEntries);
diffEntries = detector.compute(new ContentSource.Pair(ContentSource.create(or), ContentSource.create((WorkingTreeIterator) secondTree)), NullProgressMonitor.INSTANCE);
          } else {
              formatter.setDetectRenames(true);
              diffEntries = formatter.scan(firstTree, secondTree);
          }
          for (DiffEntry ent : diffEntries) {
              if (monitor.isCanceled()) {
                  break;
              }
              listener.notifyFile(new File(workTreePath + File.separator + ent.getNewPath()), ent.getNewPath());
              formatter.format(ent);
          }
          formatter.flush();
      } catch (IOException ex) {
          throw new GitException(ex);
      } finally {
          if (or != null) {
              or.release();
          }
          formatter.release();
      }
  }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:51,代碼來源:ExportDiffCommand.java

示例5: doDiff

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
protected String doDiff(Git git, String objectId, String baseObjectId, String pathOrBlobPath) throws IOException {
    Repository r = git.getRepository();
    String blobPath = trimLeadingSlash(pathOrBlobPath);

    RevCommit commit;
    if (Strings.isNotBlank(objectId)) {
        commit = CommitUtils.getCommit(r, objectId);
    } else {
        commit = CommitUtils.getHead(r);
    }
    RevCommit baseCommit = null;
    if (Strings.isNotBlank(baseObjectId) && !Objects.equals(baseObjectId, objectId)) {
        baseCommit = CommitUtils.getCommit(r, baseObjectId);
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    DiffFormatter formatter = createDiffFormatter(r, buffer);

    RevTree commitTree = commit.getTree();
    RevTree baseTree;
    if (baseCommit == null) {
        if (commit.getParentCount() > 0) {
            final RevWalk rw = new RevWalk(r);
            RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
            rw.dispose();
            baseTree = parent.getTree();
        } else {
            // FIXME initial commit. no parent?!
            baseTree = commitTree;
        }
    } else {
        baseTree = baseCommit.getTree();
    }

    List<DiffEntry> diffEntries = formatter.scan(baseTree, commitTree);
    if (blobPath != null && blobPath.length() > 0) {
        for (DiffEntry diffEntry : diffEntries) {
            if (diffEntry.getNewPath().equalsIgnoreCase(blobPath)) {
                formatter.format(diffEntry);
                break;
            }
        }
    } else {
        formatter.format(diffEntries);
    }
    formatter.flush();
    return buffer.toString();
}
 
開發者ID:fabric8io,項目名稱:fabric8-forge,代碼行數:49,代碼來源:RepositoryResource.java

示例6: writeRawDiff

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void writeRawDiff(List<DiffEntry> diff, DiffFormatter formatter) throws IOException {
  formatter.format(diff);
  formatter.flush();
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:5,代碼來源:JGitDiffPage.java

示例7: CommitDTO

import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public CommitDTO(Git git, NamespaceName projectNamespaceName, RevCommit commit, String repoUrl, String branch) {
        this.namespace = projectNamespaceName.getNamespace();
        this.app = projectNamespaceName.getName();
        this.repoUrl = repoUrl;
        this.branch = branch;
        this.sha = commit.getId().getName();

        this.author = PersonIdentDTO.newInstance(commit.getAuthorIdent());
        this.committer = PersonIdentDTO.newInstance(commit.getCommitterIdent());
        this.fullMessage = commit.getFullMessage();
        this.name = commit.getName();
        this.commitTime = GitHelpers.getCommitDate(commit);
        this.shortMessage = commit.getShortMessage();

        // TODO how to figure out the number of lines added/removed from DiffEntry + HunkHeader?
        // lets try find out the lines added / updated / deleted for this commit
        try {
            Repository r = git.getRepository();
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            DiffFormatter formatter = createDiffFormatter(r, buffer);

            RevCommit baseCommit = null;
            RevTree commitTree = commit.getTree();
            RevTree baseTree;
            if (baseCommit == null) {
                if (commit.getParentCount() > 0) {
                    final RevWalk rw = new RevWalk(r);
                    RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
                    rw.dispose();
                    baseTree = parent.getTree();
                } else {
                    // FIXME initial commit. no parent?!
                    baseTree = commitTree;
                }
            } else {
                baseTree = baseCommit.getTree();
            }

            List<DiffEntry> diffEntries = formatter.scan(baseTree, commitTree);
            for (DiffEntry diffEntry : diffEntries) {
                formatter.format(diffEntry);

/*
                FileHeader fileHeader = formatter.toFileHeader(diffEntry);
                List<? extends HunkHeader> hunks = fileHeader.getHunks();
                for (HunkHeader hunk : hunks) {
                    // linesAdded += hunk.getOldImage().getLinesAdded();
                    // linesRemoved += hunk.getOldImage().getLinesDeleted();
                }
*/
            }
            // TODO should we store the diff? thats maybe too big?
            formatter.flush();
            String diff = buffer.toString();
            if (diff != null) {
                String[] lines = diff.split("\n");
                for (String line : lines) {
                    if (line.length() == 0 || line.startsWith("diff ") || line.startsWith("index ") || line.startsWith("--- ") || line.startsWith("+++ ")) {
                        continue;
                    }
                    if (line.startsWith("+")) {
                        linesAdded++;
                    } else if (line.startsWith("-")) {
                        linesRemoved++;
                    }
                }
            }

        } catch (IOException e) {
            LOG.warn("Failed to extract lines changed for " + projectNamespaceName + " branch: " + branch + " commit: " + sha + ". " + e, e);
        }
    }
 
開發者ID:fabric8io,項目名稱:fabric8-devops,代碼行數:73,代碼來源:CommitDTO.java


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