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

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

Introduction

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

Prototype

public static ContentSource create(WorkingTreeIterator iterator) 

Source Link

Document

Construct a content source for a working directory.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

/**
 * Set the repository the formatter can load object contents from.
 * <p/>/*  w  ww  .j a 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

private ContentSource source(AbstractTreeIterator iterator) {
    if (iterator instanceof WorkingTreeIterator)
        return ContentSource.create((WorkingTreeIterator) iterator);
    return ContentSource.create(reader);
}

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;
}

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

License:Open Source License

public GitWalker(String... args) throws IOException {

    try {//from  www.j ava  2 s  . co m
        this.parser = new CmdLineParser(this);

        parser.parseArgument(args);

        if (help) {
            help(0);
        }
    } catch (CmdLineException ex) {
        System.err.println("Error in argument " + ex);
        help(-1);
    }

    Logger.getLogger("").setLevel(levels[logLevel.ordinal()]);

    builder = new FileRepositoryBuilder();
    repository = builder.setGitDir(new File(gitDir + "/.git")).readEnvironment().findGitDir().build();
    this.reader = repository.newObjectReader();
    this.git = new Git(repository);
    this.source = ContentSource.create(reader);
    this.diffAlgorithm = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.MYERS);
    this.fromCommit = repository.resolve(fromCommitStr);

}

From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java

License:Open Source License

/**
 * Show changes between index and working tree.
 *
 * @param formatter/*  w ww .  ja  va 2 s  .  c  om*/
 *            diff formatter
 * @return list of diff entries
 * @throws IOException
 *             if any i/o errors occurs
 */
private List<DiffEntry> indexToWorkingTree(DiffFormatter formatter) throws IOException {
    DirCache dirCache = null;
    ObjectReader reader = repository.newObjectReader();
    List<DiffEntry> diff;
    try {
        dirCache = repository.lockDirCache();
        DirCacheIterator iterA = new DirCacheIterator(dirCache);
        FileTreeIterator iterB = new FileTreeIterator(repository);
        // Seems bug in DiffFormatter when work with working. Disable detect
        // renames by formatter and do it later.
        formatter.setDetectRenames(false);
        diff = formatter.scan(iterA, iterB);
        if (!request.isNoRenames()) {
            // Detect renames.
            RenameDetector renameDetector = createRenameDetector();
            ContentSource.Pair sourcePairReader = new ContentSource.Pair(ContentSource.create(reader),
                    ContentSource.create(iterB));
            renameDetector.addAll(diff);
            diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
        }
    } finally {
        reader.close();
        if (dirCache != null) {
            dirCache.unlock();
        }
    }
    return diff;
}

From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java

License:Open Source License

/**
 * Show changes between specified revision and working tree.
 *
 * @param commitId//from  w  ww .j  a  v a 2s.c  o  m
 *            id of commit
 * @param formatter
 *            diff formatter
 * @return list of diff entries
 * @throws IOException
 *             if any i/o errors occurs
 */
private List<DiffEntry> commitToWorkingTree(String commitId, DiffFormatter formatter) throws IOException {
    ObjectId commitA = repository.resolve(commitId);
    if (commitA == null) {
        File heads = new File(repository.getWorkTree().getPath() + "/.git/refs/heads");
        if (heads.exists() && heads.list().length == 0) {
            return Collections.emptyList();
        }
        throw new IllegalArgumentException("Invalid commit id " + commitId);
    }
    RevTree treeA;
    try (RevWalk revWalkA = new RevWalk(repository)) {
        treeA = revWalkA.parseTree(commitA);
    }

    List<DiffEntry> diff;
    try (ObjectReader reader = repository.newObjectReader()) {
        CanonicalTreeParser iterA = new CanonicalTreeParser();
        iterA.reset(reader, treeA);
        FileTreeIterator iterB = new FileTreeIterator(repository);
        // Seems bug in DiffFormatter when work with working. Disable detect
        // renames by formatter and do it later.
        formatter.setDetectRenames(false);
        diff = formatter.scan(iterA, iterB);
        if (!request.isNoRenames()) {
            // Detect renames.
            RenameDetector renameDetector = createRenameDetector();
            ContentSource.Pair sourcePairReader = new ContentSource.Pair(ContentSource.create(reader),
                    ContentSource.create(iterB));
            renameDetector.addAll(diff);
            diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
        }
    }
    return diff;
}