Example usage for org.eclipse.jgit.diff ContentSource.Pair ContentSource.Pair

List of usage examples for org.eclipse.jgit.diff ContentSource.Pair ContentSource.Pair

Introduction

In this page you can find the example usage for org.eclipse.jgit.diff ContentSource.Pair ContentSource.Pair.

Prototype

public Pair(ContentSource oldSource, ContentSource newSource) 

Source Link

Document

Construct a pair of sources.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

/**
 * Set the repository the formatter can load object contents from.
 * <p/>/*from   w  w w.  ja  v a 2 s  .c o  m*/
 * Once a repository has been set, the formatter must be released to ensure
 * the internal ObjectReader is able to release its resources.
 *
 * @param repository source repository holding referenced objects.
 */
public void setRepository(Repository repository) {
    if (reader != null)
        reader.release();

    db = repository;
    reader = db.newObjectReader();
    diffCfg = db.getConfig().get(DiffConfig.KEY);

    ContentSource cs = ContentSource.create(reader);
    source = new ContentSource.Pair(cs, cs);

    DiffConfig dc = db.getConfig().get(DiffConfig.KEY);
    if (dc.isNoPrefix()) {
        setOldPrefix(""); //$NON-NLS-1$
        setNewPrefix(""); //$NON-NLS-1$
    }
    setDetectRenames(dc.isRenameDetectionEnabled());

    diffAlgorithm = DiffAlgorithm.getAlgorithm(db.getConfig().getEnum(ConfigConstants.CONFIG_DIFF_SECTION, null,
            ConfigConstants.CONFIG_KEY_ALGORITHM, SupportedAlgorithm.HISTOGRAM));

}

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

/**
* Determine the differences between two trees.
*
* No output is created, instead only the file paths that are different are
* returned. Callers may choose to format these paths themselves, or convert
* them into {@link FileHeader} instances with a complete edit list by
*
* @param a/* w  w w.jav  a2s.c om*/
*            the old (or previous) side.
* @param b
*            the new (or updated) side.
* @return the paths that are different.
* @throws IOException
*             trees cannot be read or file contents cannot be read.
*/
public List<DiffEntry> scan(AbstractTreeIterator a, AbstractTreeIterator b) throws IOException {
    assertHaveRepository();

    TreeWalk walk = new TreeWalk(reader);
    walk.addTree(a);
    walk.addTree(b);
    walk.setRecursive(true);

    TreeFilter filter = getDiffTreeFilterFor(a, b);
    if (pathFilter instanceof FollowFilter) {
        walk.setFilter(AndTreeFilter.create(PathFilter.create(((FollowFilter) pathFilter).getPath()), filter));
    } else {
        walk.setFilter(AndTreeFilter.create(pathFilter, filter));
    }

    source = new ContentSource.Pair(source(a), source(b));

    List<DiffEntry> files = DiffEntry.scan(walk);
    if (pathFilter instanceof FollowFilter && isAdd(files)) {
        // The file we are following was added here, find where it
        // came from so we can properly show the rename or copy,
        // then continue digging backwards.
        //
        a.reset();
        b.reset();
        walk.reset();
        walk.addTree(a);
        walk.addTree(b);
        walk.setFilter(filter);

        if (renameDetector == null)
            setDetectRenames(true);
        files = updateFollowFilter(detectRenames(DiffEntry.scan(walk)));

    } else if (renameDetector != null)
        files = detectRenames(files);

    return files;
}

From source file:jbenchmarker.trace.git.GitExtraction.java

License:Open Source License

public GitExtraction(Repository repo, CouchDbRepositorySupport<Commit> dbc, CouchDbRepositorySupport<Patch> dbp,
        DiffAlgorithm diffAlgorithm, String path, boolean detectMovesAndUpdates, int updateThresold,
        int moveThresold) {
    this.repository = repo;
    this.reader = repo.newObjectReader();
    this.source = ContentSource.create(reader);
    this.pairSource = new ContentSource.Pair(source, source);
    this.diffAlgorithm = diffAlgorithm;
    this.patchCrud = dbp;
    this.commitCrud = dbc;
    this.git = new Git(repo);
    this.path = path;
    this.detectMoveAndUpdate = detectMovesAndUpdates;
    this.updateThresold = updateThresold;
    this.moveThresold = moveThresold;
}