当前位置: 首页>>代码示例>>Java>>正文


Java RawTextComparator类代码示例

本文整理汇总了Java中org.eclipse.jgit.diff.RawTextComparator的典型用法代码示例。如果您正苦于以下问题:Java RawTextComparator类的具体用法?Java RawTextComparator怎么用?Java RawTextComparator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RawTextComparator类属于org.eclipse.jgit.diff包,在下文中一共展示了RawTextComparator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPaths

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private List<DiffEntry> getPaths(Repository repository, RevCommit rev)
		throws MissingObjectException, IncorrectObjectTypeException,
		IOException {
	RevCommit parent = null;
	List<DiffEntry> diffs = null;
	RevWalk rw = new RevWalk(repository);
	DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);

	df.setRepository(repository);
	df.setDiffComparator(RawTextComparator.DEFAULT);
	df.setDetectRenames(true);

	if (rev.getParentCount() > 0 && rev.getParent(0) != null) {
		parent = rw.parseCommit(rev.getParent(0).getId());
		diffs = df.scan(parent.getTree(), rev.getTree());
	} else {
		diffs = df.scan(new EmptyTreeIterator(), new CanonicalTreeParser(
				null, rw.getObjectReader(), rev.getTree()));
	}

	return diffs;
}
 
开发者ID:aserg-ufmg,项目名称:ModularityCheck,代码行数:23,代码来源:GITLogHandler.java

示例2: diffWhitespaceLineEndings

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
/**
 * Returns a git-style diff between the two unix strings.
 *
 * Output has no trailing newlines.
 *
 * Boolean args determine whether whitespace or line endings will be visible.
 */
private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
	dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings);
	clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings);

	RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8));
	RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8));
	EditList edits = new EditList();
	edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b));

	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try (DiffFormatter formatter = new DiffFormatter(out)) {
		formatter.format(edits, a, b);
	}
	String formatted = out.toString(StandardCharsets.UTF_8.name());

	// we don't need the diff to show this, since we display newlines ourselves
	formatted = formatted.replace("\\ No newline at end of file\n", "");
	return NEWLINE_MATCHER.trimTrailingFrom(formatted);
}
 
开发者ID:diffplug,项目名称:spotless,代码行数:27,代码来源:DiffMessageFormatter.java

示例3: comparatorFor

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private static RawTextComparator comparatorFor(Whitespace ws) {
  switch (ws) {
    case IGNORE_ALL:
      return RawTextComparator.WS_IGNORE_ALL;

    case IGNORE_TRAILING:
      return RawTextComparator.WS_IGNORE_TRAILING;

    case IGNORE_LEADING_AND_TRAILING:
      return RawTextComparator.WS_IGNORE_CHANGE;

    case IGNORE_NONE:
    default:
      return RawTextComparator.DEFAULT;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:PatchListLoader.java

示例4: listFilesChangedInCommit

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private HashSet<String> listFilesChangedInCommit(Repository repository, AnyObjectId beforeID, AnyObjectId afterID) throws MissingObjectException, IncorrectObjectTypeException, IOException
{
	log.info("calculating files changed in commit");
	HashSet<String> result = new HashSet<>();
	RevWalk rw = new RevWalk(repository);
	RevCommit commitBefore = rw.parseCommit(beforeID);
	RevCommit commitAfter = rw.parseCommit(afterID);
	DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
	df.setRepository(repository);
	df.setDiffComparator(RawTextComparator.DEFAULT);
	df.setDetectRenames(true);
	List<DiffEntry> diffs = df.scan(commitBefore.getTree(), commitAfter.getTree());
	for (DiffEntry diff : diffs)
	{
		result.add(diff.getNewPath());
	}
	log.debug("Files changed between commits commit: {} and {} - {}", beforeID.getName(), afterID, result);
	return result;
}
 
开发者ID:Apelon-VA,项目名称:ISAAC,代码行数:20,代码来源:SyncServiceGIT.java

示例5: getFilesInRange

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
/**
 * Returns the list of files changed in a specified commit. If the repository does not exist or is empty, an empty list is returned.
 * 
 * @param repository
 * @param startCommit
 *            earliest commit
 * @param endCommit
 *            most recent commit. if null, HEAD is assumed.
 * @return list of files changed in a commit range
 */
public static List<PathChangeModel> getFilesInRange(Repository repository, RevCommit startCommit, RevCommit endCommit) {
	List<PathChangeModel> list = new ArrayList<PathChangeModel>();
	if (!hasCommits(repository)) {
		return list;
	}
	try (DiffFormatter df = new DiffFormatter(null)) {
		df.setRepository(repository);
		df.setDiffComparator(RawTextComparator.DEFAULT);
		df.setDetectRenames(true);

		List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
		for (DiffEntry diff : diffEntries) {
			PathChangeModel pcm = PathChangeModel.from(diff, endCommit.getName());
			list.add(pcm);
		}
		Collections.sort(list);
	} catch (Throwable t) {
		error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit);
	}
	return list;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:32,代码来源:JGitUtils.java

示例6: getBlameForLines

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
public void getBlameForLines(final String file, final int lineFrom,
		final int lineTo, final int changedTs) throws IOException {
	final BlameGenerator bg = new BlameGenerator(
			repository.getRepository(), file);
	bg.setDiffAlgorithm(MyersDiff.INSTANCE);
	bg.setTextComparator(RawTextComparator.WS_IGNORE_ALL);

	bg.push(null, repository.getRepository().resolve(Constants.HEAD));
	final BlameResult br = bg.computeBlameResult();
	br.computeRange(lineFrom, lineTo);

	for (int i = lineFrom; i < lineTo; i++) {
		final int timeDiff = changedTs
				- br.getSourceCommit(i).getCommitTime();
		System.out.println(timeDiff);
	}

	// Now store the stuff in before/after and num lines(?).
	// Maybe we need to normalize over a) all the lines b) all the lines
	// that ever changed? c) something else
	// God help us
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:23,代码来源:LineLifecycle.java

示例7: getAllHistories

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
@Override
public Map<String, List<Revision>> getAllHistories() throws StoreException {
    final TestMatrixDefinition testMatrixDefinition = getCurrentTestMatrix().getTestMatrixDefinition();
    if (testMatrixDefinition == null) {
        return Collections.emptyMap();
    }
    final Set<String> activeTests = testMatrixDefinition.getTests().keySet();

    final Repository repository = git.getRepository();
    try {
        final ObjectId head = repository.resolve(Constants.HEAD);
        final RevWalk revWalk = new RevWalk(repository);
        final DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
        df.setRepository(git.getRepository());
        df.setDiffComparator(RawTextComparator.DEFAULT);

        final HistoryParser historyParser = new HistoryParser(revWalk, df, getTestDefinitionsDirectory(), activeTests);
        return historyParser.parseFromHead(head);

    } catch (final IOException e) {
        throw new StoreException("Could not get history " + getGitCore().getRefName(), e);
    }
}
 
开发者ID:indeedeng,项目名称:proctor,代码行数:24,代码来源:GitProctor.java

示例8: generatePatches

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
public void generatePatches() throws Exception {
    git.add().addFilepattern(".").call();
    git.commit().setMessage("generate patches").call();
    DiffFormatter formatter = new DiffFormatter(null);
    formatter.setRepository(git.getRepository());
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), getHead());
    getChangedFiles().forEach((path) -> {
        for (DiffEntry entry : entries) {
            Path diffPath = Paths.get(entry.getPath(DiffEntry.Side.NEW));
            if (diffPath.equals(path)) {
                File patchFile = new File(this.patchDirectory, diffPath.getFileName() + ".patch");
                try {
                    DiffFormatter diffFormatter = new DiffFormatter(new FileOutputStream
                            (patchFile));
                    diffFormatter.setRepository(git.getRepository());
                    diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
                    diffFormatter.setContext(3);
                    diffFormatter.format(entry);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}
 
开发者ID:PizzaCrust,项目名称:IodineToolkit,代码行数:28,代码来源:PatchService.java

示例9: getChangedFiles

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
public List<Path> getChangedFiles() throws IOException {
    List<Path> changedFiles = new ArrayList<>();
    RevWalk revWalk = new RevWalk(git.getRepository());
    AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
    RevCommit head = revWalk.parseCommit(headId);
    DiffFormatter formatter = new DiffFormatter(null);
    formatter.setRepository(git.getRepository());
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), head);
    entries.forEach((diffEntry -> changedFiles.add(Paths.get(diffEntry.getPath(DiffEntry.Side.NEW)))));
    return changedFiles;
}
 
开发者ID:PizzaCrust,项目名称:IodineToolkit,代码行数:14,代码来源:PatchService.java

示例10: diff

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
public static List<DiffEntry> diff(Repository repository, AnyObjectId oldRevId, AnyObjectId newRevId) {
	List<DiffEntry> diffs = new ArrayList<>();
	try (	DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE);
			RevWalk revWalk = new RevWalk(repository);
			ObjectReader reader = repository.newObjectReader();) {
    	diffFormatter.setRepository(repository);
    	diffFormatter.setDetectRenames(true);
    	diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
    	
    	CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
    	if (!oldRevId.equals(ObjectId.zeroId()))
    		oldTreeParser.reset(reader, revWalk.parseCommit(oldRevId).getTree());
    	
    	CanonicalTreeParser newTreeParser = new CanonicalTreeParser();
    	if (!newRevId.equals(ObjectId.zeroId()))
    		newTreeParser.reset(reader, revWalk.parseCommit(newRevId).getTree());
    	
    	for (DiffEntry entry: diffFormatter.scan(oldTreeParser, newTreeParser)) {
    		if (!Objects.equal(entry.getOldPath(), entry.getNewPath())
    				|| !Objects.equal(entry.getOldMode(), entry.getNewMode())
    				|| entry.getOldId()==null || !entry.getOldId().isComplete()
    				|| entry.getNewId()== null || !entry.getNewId().isComplete()
    				|| !entry.getOldId().equals(entry.getNewId())) {
    			diffs.add(entry);
    		}
    	}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}			
	return diffs;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:32,代码来源:GitUtils.java

示例11: checkLogEntry

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private static boolean checkLogEntry(RevCommit gitLog, SVNLogEntry entry, String svnPath, String gitPath, Pattern pFilter) throws Exception {
	if (gitLog.getFullMessage().contains(entry.getMessage())) {
		log.trace("same message for " + entry.getRevision());
		if (gitLog.getAuthorIdent().getName().equals(authors.get(entry.getAuthor()).getKey())) {
			log.trace("same author for " + entry.getRevision());
			Set<String> gitSet = new HashSet<>();
			try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
				df.setRepository(git.getRepository());
				df.setDiffComparator(RawTextComparator.DEFAULT);
				df.setDetectRenames(true);

				df.scan(gitLog.getParent(0).getTree(), gitLog.getTree()).forEach(d -> {
					String path = d.getNewPath();
					String prePath = path.startsWith(gitPath) ? gitPath : path.startsWith(svnPath) ? svnPath : null;
					if (prePath != null && pFilter.matcher(path).find()) {
						gitSet.add(path.substring(prePath.length()));
					}
				});
			}
			Set<String> svnSet = new HashSet<>();
			entry.getChangedPaths().keySet().forEach(path -> {
				int i = path.indexOf(svnPath);
				if (i != -1 && pFilter.matcher(path).find()) {
					svnSet.add(path.substring(i + svnPath.length()));
				}
			});
			
			boolean same = gitSet.equals(svnSet);
			log.debug("same content for " + entry.getRevision() + " ? " + same);
			return same;
		}
	}
	return false;
}
 
开发者ID:nicolas-albert,项目名称:sync-svn-git,代码行数:35,代码来源:SyncSvnGit.java

示例12: createDiffFormatter

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
protected static DiffFormatter createDiffFormatter(Repository r, OutputStream buffer) {
    DiffFormatter formatter = new DiffFormatter(buffer);
    formatter.setRepository(r);
    formatter.setDiffComparator(RawTextComparator.DEFAULT);
    formatter.setDetectRenames(true);
    return formatter;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:8,代码来源:RepositoryResource.java

示例13: getDiffFormatter

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
/**
 * Get diff formatter.
 *
 * @param filePath optional filter for diff
 * @return diff formater
 */
private DiffFormatter getDiffFormatter(String filePath) {
    final DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
    df.setRepository(repository);
    df.setDiffComparator(RawTextComparator.DEFAULT);
    df.setDetectRenames(true);
    if (filePath != null) {
        df.setPathFilter(PathFilter.create(filePath));
    }
    return df;
}
 
开发者ID:iazarny,项目名称:gitember,代码行数:17,代码来源:GitRepositoryService.java

示例14: blame

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private void blame(BlameOutput output, Git git, File gitBaseDir, InputFile inputFile) {
  String filename = pathResolver.relativePath(gitBaseDir, inputFile.file());
  LOG.debug("Blame file {}", filename);
  BlameResult blameResult;
  try {
    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 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);
}
 
开发者ID:SonarSource,项目名称:sonar-scm-git,代码行数:35,代码来源:JGitBlameCommand.java

示例15: walkFilesInCommit

import org.eclipse.jgit.diff.RawTextComparator; //导入依赖的package包/类
private void walkFilesInCommit(
    Git gitClient,
    RevCommit commit,
    List<SourceCodeFileAnalyzerPlugin> analyzers,
    MetricsProcessor metricsProcessor)
    throws IOException {
  commit = CommitUtils.getCommit(gitClient.getRepository(), commit.getId());
  logger.info("starting analysis of commit {}", commit.getName());
  DiffFormatter diffFormatter = new DiffFormatter(DisabledOutputStream.INSTANCE);
  diffFormatter.setRepository(gitClient.getRepository());
  diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
  diffFormatter.setDetectRenames(true);

  ObjectId parentId = null;
  if (commit.getParentCount() > 0) {
    // TODO: support multiple parents
    parentId = commit.getParent(0).getId();
  }

  List<DiffEntry> diffs = diffFormatter.scan(parentId, commit);
  for (DiffEntry diff : diffs) {
    String filePath = diff.getPath(DiffEntry.Side.NEW);
    byte[] fileContent =
        BlobUtils.getRawContent(gitClient.getRepository(), commit.getId(), filePath);
    FileMetrics metrics = fileAnalyzer.analyzeFile(analyzers, filePath, fileContent);
    FileMetricsWithChangeType metricsWithChangeType =
        new FileMetricsWithChangeType(
            metrics, changeTypeMapper.jgitToCoderadar(diff.getChangeType()));
    metricsProcessor.processMetrics(metricsWithChangeType, gitClient, commit.getId(), filePath);
  }
  metricsProcessor.onCommitFinished(gitClient, commit.getId());
}
 
开发者ID:reflectoring,项目名称:coderadar,代码行数:33,代码来源:AnalyzingCommitProcessor.java


注:本文中的org.eclipse.jgit.diff.RawTextComparator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。