本文整理匯總了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;
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
示例6: writeRawDiff
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void writeRawDiff(List<DiffEntry> diff, DiffFormatter formatter) throws IOException {
formatter.format(diff);
formatter.flush();
}
示例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);
}
}