Java Code Examples for org.eclipse.jgit.diff.DiffEntry.ChangeType#ADD
The following examples show how to use
org.eclipse.jgit.diff.DiffEntry.ChangeType#ADD .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlobDiffPanel.java From onedev with MIT License | 5 votes |
@Override protected void onInitialize() { super.onInitialize(); if (change.getType() == ChangeType.ADD || change.getType() == ChangeType.COPY) { showBlob(change.getNewBlob()); } else if (change.getType() == ChangeType.DELETE) { showBlob(change.getOldBlob()); } else { if (change.getOldText() != null && change.getNewText() != null) { if (change.getOldText().getLines().size() + change.getNewText().getLines().size() > DiffUtils.MAX_DIFF_SIZE) { add(newFragment("Unable to diff as the file is too large.", true)); } else if (change.getAdditions() + change.getDeletions() > WebConstants.MAX_SINGLE_DIFF_LINES) { add(newFragment("Diff is too large to be displayed.", true)); } else if (change.getAdditions() + change.getDeletions() == 0 && (commentSupport == null || commentSupport.getComments().isEmpty())) { add(newFragment("Content is identical", false)); } else { add(new TextDiffPanel(CONTENT_ID, projectModel, requestModel, change, diffMode, blameModel, commentSupport)); } } else if (change.getOldBlob().isPartial() || change.getNewBlob().isPartial()) { add(newFragment("File is too large to be loaded.", true)); } else if (change.getOldBlob().getMediaType().equals(change.getNewBlob().getMediaType())) { Panel diffPanel = null; for (DiffRenderer renderer: OneDev.getExtensions(DiffRenderer.class)) { diffPanel = renderer.render(CONTENT_ID, change.getNewBlob().getMediaType(), change, diffMode); if (diffPanel != null) break; } if (diffPanel != null) add(diffPanel); else add(newFragment("Binary file.", false)); } else { add(newFragment("Binary file.", false)); } } }
Example 2
Source File: GitUtils.java From onedev with MIT License | 5 votes |
public static BlobIdent getOldBlobIdent(DiffEntry diffEntry, String oldRev) { BlobIdent blobIdent; if (diffEntry.getChangeType() != ChangeType.ADD) { blobIdent = new BlobIdent(oldRev, diffEntry.getOldPath(), diffEntry.getOldMode().getBits()); } else { blobIdent = new BlobIdent(oldRev, null, null); } return blobIdent; }
Example 3
Source File: GitServiceImpl.java From RefactoringMiner with MIT License | 5 votes |
public void fileTreeDiff(Repository repository, RevCommit currentCommit, List<String> javaFilesBefore, List<String> javaFilesCurrent, Map<String, String> renamedFilesHint) throws Exception { if (currentCommit.getParentCount() > 0) { ObjectId oldTree = currentCommit.getParent(0).getTree(); ObjectId newTree = currentCommit.getTree(); final TreeWalk tw = new TreeWalk(repository); tw.setRecursive(true); tw.addTree(oldTree); tw.addTree(newTree); final RenameDetector rd = new RenameDetector(repository); rd.setRenameScore(80); rd.addAll(DiffEntry.scan(tw)); for (DiffEntry diff : rd.compute(tw.getObjectReader(), null)) { ChangeType changeType = diff.getChangeType(); String oldPath = diff.getOldPath(); String newPath = diff.getNewPath(); if (changeType != ChangeType.ADD) { if (isJavafile(oldPath)) { javaFilesBefore.add(oldPath); } } if (changeType != ChangeType.DELETE) { if (isJavafile(newPath)) { javaFilesCurrent.add(newPath); } } if (changeType == ChangeType.RENAME && diff.getScore() >= rd.getRenameScore()) { if (isJavafile(oldPath) && isJavafile(newPath)) { renamedFilesHint.put(oldPath, newPath); } } } } }
Example 4
Source File: GitCommit.java From compiler with Apache License 2.0 | 4 votes |
private void updateChangedFiles(final RevCommit parent, final int parentIndex, final RevCommit child) { final DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE); df.setRepository(repository); df.setDiffComparator(RawTextComparator.DEFAULT); df.setDetectRenames(true); try { final AbstractTreeIterator parentIter = new CanonicalTreeParser(null, repository.newObjectReader(), parent.getTree()); final AbstractTreeIterator childIter = new CanonicalTreeParser(null, repository.newObjectReader(), child.getTree()); List<DiffEntry> diffs = df.scan(parentIter, childIter); for (final DiffEntry diff : diffs) { if (diff.getChangeType() == ChangeType.MODIFY) { if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) { updateChangedFiles(parent, child, diff, ChangeKind.MODIFIED); } // RENAMED file may have the same/different object id(s) for old and new } else if (diff.getChangeType() == ChangeType.RENAME) { if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) { updateChangedFiles(parent, child, diff, ChangeKind.RENAMED); } } else if (diff.getChangeType() == ChangeType.COPY) { if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) { updateChangedFiles(parent, child, diff, ChangeKind.COPIED); } // ADDED file should not have old path and its old object id is 0's } else if (diff.getChangeType() == ChangeType.ADD) { if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) { updateChangedFiles(parent, child, diff, ChangeKind.ADDED); } // DELETED file's new object id is 0's and doesn't have new path } else if (diff.getChangeType() == ChangeType.DELETE) { if (diff.getOldMode().getObjectType() == Constants.OBJ_BLOB) { String oldPath = diff.getOldPath(); String oldObjectId = diff.getOldId().toObjectId().getName(); ChangedFile.Builder cfb = getChangedFile(oldPath, ChangeKind.DELETED); filePathGitObjectIds.put(oldPath, diff.getNewId().toObjectId()); } } } } catch (final IOException e) { if (debug) System.err.println("Git Error getting commit diffs: " + e.getMessage()); } df.close(); }