List of usage examples for org.eclipse.jgit.diff RawTextComparator WS_IGNORE_ALL
RawTextComparator WS_IGNORE_ALL
To view the source code for org.eclipse.jgit.diff RawTextComparator WS_IGNORE_ALL.
Click Source Link
From source file:com.google.gerrit.server.patch.PatchListLoader.java
License:Apache License
private static RawTextComparator comparatorFor(Whitespace ws) { switch (ws) { case IGNORE_ALL_SPACE: return RawTextComparator.WS_IGNORE_ALL; case IGNORE_SPACE_AT_EOL: return RawTextComparator.WS_IGNORE_TRAILING; case IGNORE_SPACE_CHANGE: return RawTextComparator.WS_IGNORE_CHANGE; case IGNORE_NONE: default://from w w w.j a v a 2 s . c o m return RawTextComparator.DEFAULT; } }
From source file:org.eclipse.egit.ui.internal.blame.BlameOperation.java
License:Open Source License
public void execute(IProgressMonitor monitor) throws CoreException { final RevisionInformation info = new RevisionInformation(); info.setHoverControlCreator(new BlameInformationControlCreator(false)); info.setInformationPresenterControlCreator(new BlameInformationControlCreator(true)); final BlameCommand command = new BlameCommand(repository).setFollowFileRenames(true).setFilePath(path); if (startCommit != null) command.setStartCommit(startCommit); if (Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.BLAME_IGNORE_WHITESPACE)) command.setTextComparator(RawTextComparator.WS_IGNORE_ALL); BlameResult result;/*from w w w . j a v a 2 s.c o m*/ try { result = command.call(); } catch (Exception e1) { Activator.error(e1.getMessage(), e1); return; } if (result == null) return; Map<RevCommit, BlameRevision> revisions = new HashMap<RevCommit, BlameRevision>(); int lineCount = result.getResultContents().size(); BlameRevision previous = null; for (int i = 0; i < lineCount; i++) { RevCommit commit = result.getSourceCommit(i); if (commit == null) { // Unregister the current revision if (previous != null) { previous.register(); previous = null; } continue; } BlameRevision revision = revisions.get(commit); if (revision == null) { revision = new BlameRevision(); revision.setRepository(repository); revision.setCommit(commit); revisions.put(commit, revision); info.addRevision(revision); } if (previous != null) if (previous == revision) previous.addLine(); else { previous.register(); previous = revision.reset(i); } else previous = revision.reset(i); } if (previous != null) previous.register(); shell.getDisplay().asyncExec(new Runnable() { public void run() { openEditor(info); } }); }
From source file:org.eclipse.orion.server.gerritfs.DiffCommand.java
License:Eclipse Distribution License
/** * Executes the {@code Diff} command with all the options and parameters collected by the setter methods (e.g. {@link #setCached(boolean)} of this class. * Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance. * * @return a DiffEntry for each path which is different *//* w ww .ja va2 s . c o m*/ @Override public List<DiffEntry> call() throws GitAPIException { final DiffFormatter diffFmt; if (out != null && !showNameAndStatusOnly) diffFmt = new DiffFormatter(new BufferedOutputStream(out)); else diffFmt = new DiffFormatter(NullOutputStream.INSTANCE); if (ignoreWS) diffFmt.setDiffComparator(RawTextComparator.WS_IGNORE_ALL); diffFmt.setRepository(repo); diffFmt.setProgressMonitor(monitor); try { if (cached) { if (oldTree == null) { ObjectId head = repo.resolve(HEAD + "^{tree}"); //$NON-NLS-1$ if (head == null) throw new NoHeadException(JGitText.get().cannotReadTree); CanonicalTreeParser p = new CanonicalTreeParser(); ObjectReader reader = repo.newObjectReader(); try { p.reset(reader, head); } finally { reader.release(); } oldTree = p; } newTree = new DirCacheIterator(repo.readDirCache()); } else { if (oldTree == null) oldTree = new DirCacheIterator(repo.readDirCache()); if (newTree == null) newTree = new FileTreeIterator(repo); } diffFmt.setPathFilter(pathFilter); List<DiffEntry> result = diffFmt.scan(oldTree, newTree); if (showNameAndStatusOnly) return result; else { if (contextLines >= 0) diffFmt.setContext(contextLines); if (destinationPrefix != null) diffFmt.setNewPrefix(destinationPrefix); if (sourcePrefix != null) diffFmt.setOldPrefix(sourcePrefix); diffFmt.format(result); diffFmt.flush(); return result; } } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } finally { diffFmt.release(); } }
From source file:org.eclipse.orion.server.git.servlets.GitBlameHandlerV1.java
License:Open Source License
public void doBlame(Blame blame, Repository db) throws GitAPIException, IOException { String filePath = blame.getFilePath(); if (db != null && filePath != null) { BlameCommand blameCommand = new BlameCommand(db); blameCommand.setFilePath(filePath); blameCommand.setFollowFileRenames(true); blameCommand.setTextComparator(RawTextComparator.WS_IGNORE_ALL); if (blame.getStartCommit() != null) { blameCommand.setStartCommit(blame.getStartCommit()); }/*from w ww. j a va2s .c o m*/ BlameResult result; try { result = blameCommand.call(); } catch (Exception e1) { return; } if (result != null) { blame.clearLines(); RevCommit commit; RevCommit prevCommit = null; String path; String prevPath = null; for (int i = 0; i < result.getResultContents().size(); i++) { try { commit = result.getSourceCommit(i); prevCommit = commit; } catch (NullPointerException e) { commit = prevCommit; } if (!blame.commitExists(commit)) { if (commit != null) { blame.addCommit(commit); } } try { path = commit.getId().getName(); prevPath = path; } catch (NullPointerException e) { path = prevPath; } blame.addLine(path); } } } }
From source file:org.kuali.student.git.tools.GitExtractor.java
License:Educational Community License
public void extractDifference(String targetTagName, String copyFromTagName) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevTree target = extractTag(targetTagName); RevTree copyFrom = extractTag(copyFromTagName); DiffFormatter formatter = new DiffFormatter(System.out); formatter.setRepository(repository); formatter.setDetectRenames(true);/*from w w w .j ava 2 s.c o m*/ formatter.setDiffAlgorithm(DiffAlgorithm.getAlgorithm(SupportedAlgorithm.MYERS)); formatter.setDiffComparator(RawTextComparator.WS_IGNORE_ALL); List<DiffEntry> results = formatter.scan(target, copyFrom); for (DiffEntry entry : results) { if (entry.getChangeType().equals(ChangeType.COPY)) { AbbreviatedObjectId copyFromBlobId = entry.getOldId(); // Cscore:md5:target-path:copy-from-path log.info(String.format("C%d:%s:%s:%s", entry.getScore(), "md5", entry.getNewPath(), entry.getOldPath())); } else if (entry.getChangeType().equals(ChangeType.MODIFY)) { // Cscore:md5:target-path:copy-from-path log.info(String.format("M%d:%s:%s:%s", entry.getScore(), "md5", entry.getNewPath(), entry.getOldPath())); } } }
From source file:org.review_board.ereviewboard.ui.wizard.DiffCreator.java
License:Open Source License
public byte[] createDiff(Set<ChangedFile> selectedFiles, File rootLocation, Git gitClient) throws IOException, GitAPIException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); List<DiffEntry> changes = new ArrayList<DiffEntry>(selectedFiles.size()); for (ChangedFile changedFile : selectedFiles) { changes.add(changedFile.getDiffEntry()); }/*from w w w . ja va 2 s . c o m*/ final int INDEX_LENGTH = 40; DiffFormatter diffFormatter = new DiffFormatter(outputStream); diffFormatter.setRepository(gitClient.getRepository()); diffFormatter.setDiffComparator(RawTextComparator.WS_IGNORE_ALL); diffFormatter.setAbbreviationLength(INDEX_LENGTH); diffFormatter.setDetectRenames(true); diffFormatter.format(changes); diffFormatter.flush(); return outputStream.toByteArray(); }
From source file:org.sjanisch.skillview.git.GitAlgorithmContentDiff.java
License:Open Source License
private static Collection<String> diff(String previousContent, String currentContent, DiffAlgorithm algorithm) { RawText previous = new RawText(previousContent.getBytes()); RawText current = new RawText(currentContent.getBytes()); EditList edits = algorithm.diff(RawTextComparator.WS_IGNORE_ALL, previous, current); Collection<String> result = new LinkedList<>(); for (int i = 0; i < edits.size(); ++i) { Edit edit = edits.get(i);//from ww w . jav a2s .c o m switch (edit.getType()) { case INSERT: case REPLACE: String touched = current.getString(edit.getBeginB(), edit.getEndB(), false).trim(); result.add(touched); break; default: continue; } } return result; }
From source file:org.sonar.plugins.scm.git.JGitBlameCommand.java
License:Open Source License
private void blame(BlameOutput output, Git git, File gitBaseDir, InputFile inputFile) throws GitAPIException { String filename = pathResolver.relativePath(gitBaseDir, inputFile.file()); org.eclipse.jgit.blame.BlameResult blameResult = git.blame() // Equivalent to -w command line option .setTextComparator(RawTextComparator.WS_IGNORE_ALL).setFilePath(filename).call(); List<BlameLine> lines = new ArrayList<BlameLine>(); for (int i = 0; i < blameResult.getResultContents().size(); i++) { if (blameResult.getSourceAuthor(i) == null || blameResult.getSourceCommit(i) == null) { LOG.info("Author: " + blameResult.getSourceAuthor(i)); LOG.info("Source commit: " + blameResult.getSourceCommit(i)); throw new IllegalStateException("Unable to blame file " + inputFile.relativePath() + ". No blame info at line " + (i + 1) + ". Is file commited?"); }//from w w w . j av a 2s.c o m lines.add(new org.sonar.api.batch.scm.BlameLine().date(blameResult.getSourceAuthor(i).getWhen()) .revision(blameResult.getSourceCommit(i).getName()) .author(blameResult.getSourceAuthor(i).getEmailAddress())); } if (lines.size() == inputFile.lines() - 1) { // SONARPLUGINS-3097 Git do not report blame on last empty line lines.add(lines.get(lines.size() - 1)); } output.blameResult(inputFile, lines); }
From source file:org.sonarsource.scm.git.JGitBlameCommand.java
License:Open Source License
private void blame(BlameOutput output, Git git, File gitBaseDir, InputFile inputFile) throws GitAPIException { String filename = pathResolver.relativePath(gitBaseDir, inputFile.file()); LOG.debug("Blame file {}", filename); org.eclipse.jgit.blame.BlameResult blameResult; try {//from w w w .j a v a 2 s . c om blameResult = git.blame() // Equivalent to -w command line option .setTextComparator(RawTextComparator.WS_IGNORE_ALL).setFilePath(filename).call(); } catch (Exception e) { throw new IllegalStateException("Unable to blame file " + inputFile.relativePath(), e); } List<BlameLine> lines = new ArrayList<>(); if (blameResult == null) { LOG.debug("Unable to blame file {}. It is probably a symlink.", inputFile.relativePath()); return; } for (int i = 0; i < blameResult.getResultContents().size(); i++) { if (blameResult.getSourceAuthor(i) == null || blameResult.getSourceCommit(i) == null) { LOG.debug( "Unable to blame file {}. No blame info at line {}. Is file committed? [Author: {} Source commit: {}]", inputFile.relativePath(), i + 1, blameResult.getSourceAuthor(i), blameResult.getSourceCommit(i)); return; } lines.add(new org.sonar.api.batch.scm.BlameLine().date(blameResult.getSourceCommitter(i).getWhen()) .revision(blameResult.getSourceCommit(i).getName()) .author(blameResult.getSourceAuthor(i).getEmailAddress())); } if (lines.size() == inputFile.lines() - 1) { // SONARPLUGINS-3097 Git do not report blame on last empty line lines.add(lines.get(lines.size() - 1)); } output.blameResult(inputFile, lines); }