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

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

Introduction

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

Prototype

@NonNull
public RevCommit parseCommit(AnyObjectId id)
        throws MissingObjectException, IncorrectObjectTypeException, IOException 

Source Link

Document

Locate a reference to a commit and immediately parse its content.

Usage

From source file:com.madgag.agit.CommitViewerActivity.java

License:Open Source License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.commit_navigation_animation_layout);

    relationAnimations.put(PARENT, new RelationAnimations(push_child_out, pull_parent_in));
    relationAnimations.put(CHILD, new RelationAnimations(push_parent_out, pull_child_in));

    currentCommitView = (CommitView) findViewById(R.id.commit_nav_current_commit);
    nextCommitView = (CommitView) findViewById(R.id.commit_nav_next_commit);

    CommitSelectedListener commitSelectedListener = new CommitSelectedListener() {
        public void onCommitSelected(Relation relation, PlotCommit<PlotLane> commit) {
            setCommit(commit, relation);
        }/*from   w w w  .  j a  va 2s .  c  o m*/
    };
    try {
        ObjectId revisionId = GitIntents.commitIdFrom(getIntent()); // intent.getStringExtra("commit");
        Log.d(TAG, revisionId.getName());
        PlotWalk revWalk = generatePlotWalk();

        commit = (PlotCommit<PlotLane>) revWalk.parseCommit(revisionId);

        setup(currentCommitView, commitSelectedListener, revWalk);
        setup(nextCommitView, commitSelectedListener, revWalk);

        currentCommitView.setCommit(commit);
        setCurrentCommitViewVisible();
    } catch (Exception e) {
        Log.e(TAG, "Problem my friend", e);
    }
}

From source file:com.madgag.agit.CommitViewerActivity.java

License:Open Source License

private PlotWalk generatePlotWalk() throws IOException {
    long start = currentTimeMillis();
    PlotWalk revWalk = new PlotWalk(repo());

    for (ObjectId startId : logStartProvider.get()) {
        revWalk.markStart(revWalk.parseCommit(startId));
    }/*w  w  w.  ja v a 2  s  . co  m*/

    PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
    plotCommitList.source(revWalk);
    plotCommitList.fillTo(Integer.MAX_VALUE);
    long duration = currentTimeMillis() - start;
    Log.d(TAG, "generatePlotWalk duration" + duration);
    return revWalk;
}

From source file:de.fau.osr.core.vcs.impl.GitVcsClient.java

License:Open Source License

public Iterator<String> getCommitListForFileodification(String path) {
    String filename = path.replaceAll(Matcher.quoteReplacement("\\"), "/");
    PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
    PlotWalk revWalk = new PlotWalk(repo);
    ArrayList<String> commitIDList = new ArrayList<String>();
    try {//from  w  w  w .j a  v  a 2  s.co  m
        ObjectId rootId = repo.resolve("HEAD");
        if (rootId != null) {
            RevCommit root = revWalk.parseCommit(rootId);
            revWalk.markStart(root);
            revWalk.setTreeFilter(
                    // VERY IMPORTANT: This works only with unix-style file paths. NO "\" allowed.
                    AndTreeFilter.create(PathFilter.create(filename), TreeFilter.ANY_DIFF));
            plotCommitList.source(revWalk);
            plotCommitList.fillTo(Integer.MAX_VALUE);

            Iterator<PlotCommit<PlotLane>> commitListIterator = plotCommitList.iterator();
            while (commitListIterator.hasNext()) {
                commitIDList.add(commitListIterator.next().getName());
            }
            return commitIDList.iterator();
        }

    } catch (AmbiguousObjectException ex) {

    } catch (IOException ex) {

    }
    return commitIDList.iterator();
}

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

License:Apache License

public ChangeSummary getHeadCommit(final File f) throws GitSubsystemException {
    try {/*  w w w.  j  av a 2s .c  om*/
        final ObjectId oid = repo.resolve("HEAD");

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

        final String filepath = relativize(f);

        pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));

        final PlotCommitList<PlotLane> cl = new PlotCommitList<>();
        cl.source(pw);
        cl.fillTo(1);

        final PlotCommit<PlotLane> commit = cl.get(0);

        return toChangeSummary(commit);
    } 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.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   ww w. j  a va 2s  .c om

    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 ChangeSummary getHeadCommit(final File f) throws GitSubsystemException {
    return lockAnd(me -> {
        try {//from   ww w .j  ava  2s .c  o m
            final ObjectId oid = repo.resolve("HEAD");

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

            final String filepath = relativize(f);

            pw.setTreeFilter(AndTreeFilter.create(PathFilter.create(filepath), TreeFilter.ANY_DIFF));

            final PlotCommitList<PlotLane> cl = new PlotCommitList<>();
            cl.source(pw);
            cl.fillTo(1);

            final PlotCommit<PlotLane> commit = cl.get(0);

            return toChangeSummary(commit);
        } 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();
        }/* w  ww .  j  a v a2 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.efaps.cli.rest.ImportCICall.java

License:Apache License

/**
 * Gets the file information.//from  ww  w  .ja  va 2  s  .com
 *
 * @param _file the _file
 * @return the file information
 */
protected String[] getFileInformation(final File _file) {
    final String[] ret = new String[2];

    try {
        final Repository repo = new FileRepository(evalGitDir(_file));

        final ObjectId lastCommitId = repo.resolve(Constants.HEAD);

        final PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
        final PlotWalk revWalk = new PlotWalk(repo);

        final RevCommit root = revWalk.parseCommit(lastCommitId);
        revWalk.markStart(root);
        revWalk.setTreeFilter(AndTreeFilter.create(
                PathFilter.create(_file.getPath().replaceFirst(repo.getWorkTree().getPath() + "/", "")),
                TreeFilter.ANY_DIFF));
        plotCommitList.source(revWalk);
        plotCommitList.fillTo(2);
        final PlotCommit<PlotLane> commit = plotCommitList.get(0);
        if (commit != null) {
            final PersonIdent authorIdent = commit.getAuthorIdent();
            final Date authorDate = authorIdent.getWhen();
            final TimeZone authorTimeZone = authorIdent.getTimeZone();
            final DateTime dateTime = new DateTime(authorDate.getTime(),
                    DateTimeZone.forTimeZone(authorTimeZone));
            ret[1] = dateTime.toString();
            ret[0] = commit.getId().getName();
        } else {
            ret[1] = new DateTime().toString();
            ret[0] = "UNKNOWN";
        }
    } catch (final RevisionSyntaxException | IOException e) {
        e.printStackTrace();
    }
    return ret;
}

From source file:org.efaps.eclipse.rest.RestClient.java

License:Apache License

protected String[] getFileInformation(final File _file) {
    final String[] ret = new String[2];

    try {//from   ww w .  ja  v a  2s .co  m
        final Repository repo = new FileRepository(evalGitDir(_file));

        final ObjectId lastCommitId = repo.resolve(Constants.HEAD);

        final PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
        final PlotWalk revWalk = new PlotWalk(repo);

        final RevCommit root = revWalk.parseCommit(lastCommitId);
        revWalk.markStart(root);
        revWalk.setTreeFilter(AndTreeFilter.create(
                PathFilter.create(_file.getPath().replaceFirst(repo.getWorkTree().getPath() + "/", "")),
                TreeFilter.ANY_DIFF));
        plotCommitList.source(revWalk);
        plotCommitList.fillTo(2);
        final PlotCommit<PlotLane> commit = plotCommitList.get(0);
        if (commit != null) {
            final PersonIdent authorIdent = commit.getAuthorIdent();
            final Date authorDate = authorIdent.getWhen();
            final TimeZone authorTimeZone = authorIdent.getTimeZone();
            final DateTime dateTime = new DateTime(authorDate.getTime(),
                    DateTimeZone.forTimeZone(authorTimeZone));
            ret[1] = dateTime.toString();
            ret[0] = commit.getId().getName();
        } else {
            ret[1] = new DateTime().toString();
            ret[0] = "UNKNOWN";
        }
    } catch (RevisionSyntaxException | IOException e) {
        e.printStackTrace();
    }
    return ret;
}

From source file:org.nbgit.ui.browser.BrowserController.java

License:Open Source License

public void show() {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            model.getCommitList().clear();
            PlotWalk walk = null;
            try {
                walk = new PlotWalk(model.getRepository());
                walk.sort(RevSort.BOUNDARY, true);
                if (model.hasPaths()) {
                    walk.setTreeFilter(model.createPathFilter());
                }// ww w. j  a  v  a2 s.c o  m
                for (Ref ref : model.getReferences())
                    walk.markStart(walk.parseCommit(ref.getObjectId()));
                model.getCommitList().source(walk);
                model.getCommitList().fillTo(Integer.MAX_VALUE);
            } catch (Throwable error) {
                model.setContent(error.getMessage());
            } finally {
                if (walk != null) {
                    walk.dispose();
                }
            }
        }
    });
}