Java Code Examples for org.eclipse.jgit.diff.DiffEntry.ChangeType#COPY
The following examples show how to use
org.eclipse.jgit.diff.DiffEntry.ChangeType#COPY .
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: TreeRevFilter.java From onedev with MIT License | 4 votes |
private static boolean isRename(DiffEntry ent) { return ent.getChangeType() == ChangeType.RENAME || ent.getChangeType() == ChangeType.COPY; }
Example 3
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(); }
Example 4
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 4 votes |
private boolean hasNewPath(DiffEntry d) { return d.getChangeType()==ChangeType.COPY || d.getChangeType()==ChangeType.RENAME; }