Example usage for org.eclipse.jgit.revplot PlotWalk next

List of usage examples for org.eclipse.jgit.revplot PlotWalk next

Introduction

In this page you can find the example usage for org.eclipse.jgit.revplot PlotWalk next.

Prototype

@Override
public RevCommit next() throws MissingObjectException, IncorrectObjectTypeException, IOException 

Source Link

Usage

From source file:org.commonjava.aprox.subsys.git.GitManager.java

License:Apache License

public List<ChangeSummary> getChangelog(final File f, final int start, final int length)
        throws GitSubsystemException {
    if (length == 0) {
        return Collections.emptyList();
    }/*from  w ww. j a va 2 s . c o  m*/

    try {
        final ObjectId oid = repo.resolve(Constants.HEAD);

        final PlotWalk pw = new PlotWalk(repo);
        final RevCommit rc = pw.parseCommit(oid);
        toChangeSummary(rc);
        pw.markStart(rc);

        final String filepath = relativize(f);
        logger.info("Getting changelog for: {} (start: {}, length: {})", filepath, start, length);

        if (!isEmpty(filepath) && !filepath.equals("/")) {
            pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));
        } else {
            pw.setTreeFilter(TreeFilter.ANY_DIFF);
        }

        final List<ChangeSummary> changelogs = new ArrayList<ChangeSummary>();
        int count = 0;
        final int stop = length > 0 ? length + 1 : 0;
        RevCommit commit = null;
        while ((commit = pw.next()) != null && (stop < 1 || count < stop)) {
            if (count < start) {
                count++;
                continue;
            }

            //                printFiles( commit );
            changelogs.add(toChangeSummary(commit));
            count++;
        }

        if (length < -1) {
            final int remove = (-1 * length) - 1;
            for (int i = 0; i < remove; i++) {
                changelogs.remove(changelogs.size() - 1);
            }
        }

        return changelogs;
    } catch (RevisionSyntaxException | IOException e) {
        throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f,
                e.getMessage());
    }
}

From source file:org.commonjava.indy.subsys.git.GitManager.java

License:Apache License

public List<ChangeSummary> getChangelog(final File f, final int start, final int length)
        throws GitSubsystemException {
    return lockAnd(me -> {
        if (length == 0) {
            return Collections.emptyList();
        }// www .  j  a  va  2s. c  o  m

        try {
            final ObjectId oid = repo.resolve(Constants.HEAD);

            final PlotWalk pw = new PlotWalk(repo);
            final RevCommit rc = pw.parseCommit(oid);
            toChangeSummary(rc);
            pw.markStart(rc);

            final String filepath = relativize(f);
            logger.info("Getting changelog for: {} (start: {}, length: {})", filepath, start, length);

            if (!isEmpty(filepath) && !filepath.equals("/")) {
                pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));
            } else {
                pw.setTreeFilter(TreeFilter.ANY_DIFF);
            }

            final List<ChangeSummary> changelogs = new ArrayList<ChangeSummary>();
            int count = 0;
            final int stop = length > 0 ? length + 1 : 0;
            RevCommit commit = null;
            while ((commit = pw.next()) != null && (stop < 1 || count < stop)) {
                if (count < start) {
                    count++;
                    continue;
                }

                //                printFiles( commit );
                changelogs.add(toChangeSummary(commit));
                count++;
            }

            if (length < -1) {
                final int remove = (-1 * length) - 1;
                for (int i = 0; i < remove; i++) {
                    changelogs.remove(changelogs.size() - 1);
                }
            }

            return changelogs;
        } catch (RevisionSyntaxException | IOException e) {
            throw new GitSubsystemException("Failed to resolve HEAD commit for: %s. Reason: %s", e, f,
                    e.getMessage());
        }
    });
}