Example usage for org.eclipse.jgit.api LogCommand call

List of usage examples for org.eclipse.jgit.api LogCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api LogCommand call.

Prototype

@Override
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException 

Source Link

Document

Executes the Log command with all the options and parameters collected by the setter methods (e.g.

Usage

From source file:at.nonblocking.maven.nonsnapshot.impl.ScmHandlerGitImpl.java

License:Apache License

@Override
public boolean checkChangesSinceDate(final File moduleDirectory, final Date date) {
    if (this.git == null) {
        return false;
    }/*from   w  w w  .  jav  a 2 s . c  o  m*/

    try {
        String modulePath = PathUtil.relativePath(this.baseDir, moduleDirectory);

        LogCommand logCommand = this.git.log().setMaxCount(100);

        if (!modulePath.isEmpty()) {
            logCommand.addPath(modulePath);
        }

        for (RevCommit commit : logCommand.call()) {
            Date commitTime = new Date(commit.getCommitTime() * 1000L);
            if (commitTime.after(date)) {
                if (!commit.getFullMessage().startsWith(NONSNAPSHOT_COMMIT_MESSAGE_PREFIX)) {
                    LOG.debug("Module folder {}: Change since last commit: rev{} @ {} ({})",
                            new Object[] { moduleDirectory.getAbsolutePath(), commit.getId(), commitTime,
                                    commit.getFullMessage() });
                    return true;
                }
            } else {
                break;
            }
        }

    } catch (Exception e) {
        LOG.warn("Failed to check changes for path: {}" + moduleDirectory.getAbsolutePath(), e);
        return true;
    }

    return false;
}

From source file:br.edu.ifpb.scm.api.git.Git.java

/**
 * Recupera a lista de verses//from   w w  w  .  ja v  a  2 s .co m
 *
 * @param git Git JGit
 * @return List {@link List} de {@link Version}
 */
private List<Version> versions() {
    List<Version> listOfVersions = new ArrayList();
    LogCommand log = git.log();
    try {
        log.call().forEach(rc -> {
            try {
                listOfVersions.add(createVersion(rc));
            } catch (IOException ex) {
                Logger.getLogger(Git.class.getName()).log(Level.SEVERE, null, ex);
            }
        });
    } catch (GitAPIException | NullPointerException e) {
        e.printStackTrace();
        throw new SCMException("No foi ppossvel recuperar as verses", e);
    }
    return listOfVersions;
}

From source file:com.buildautomation.jgit.api.ListTags.java

License:Apache License

public static void listTags() throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        try (Git git = new Git(repository)) {
            List<Ref> call = git.tagList().call();
            for (Ref ref : call) {
                System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

                // fetch all commits for this tag
                LogCommand log = git.log();

                Ref peeledRef = repository.peel(ref);
                if (peeledRef.getPeeledObjectId() != null) {
                    log.add(peeledRef.getPeeledObjectId());
                } else {
                    log.add(ref.getObjectId());
                }/*  w ww .j  av  a 2  s .c o m*/

                Iterable<RevCommit> logs = log.call();
                for (RevCommit rev : logs) {
                    System.out.println("Commit: "
                            + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
                }
            }
        }
    }
}

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

License:Open Source License

@Override
public Loader<List<RevCommit>> onCreateLoader(int id, Bundle args) {
    return new AsyncLoader<List<RevCommit>>(getActivity()) {
        public List<RevCommit> loadInBackground() {
            Stopwatch stopwatch = new Stopwatch().start();
            Bundle args = getArguments();
            try {
                Repository repo = new FileRepository(args.getString(GITDIR));

                LogCommand log = new Git(repo).log();
                List<String> untilRevs = getArguments().getStringArrayList(UNTIL_REVS);
                if (untilRevs == null || untilRevs.isEmpty()) {
                    log.all();//ww  w.j  a v  a2 s.  c o m
                } else {
                    for (String untilRev : untilRevs) {
                        log.add(repo.resolve(untilRev));
                    }
                }

                List<RevCommit> sampleRevCommits = newArrayList(log.call());

                Log.d(TAG, "Found " + sampleRevCommits.size() + " commits " + stopwatch);

                return sampleRevCommits;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}

From source file:com.microsoft.gittf.core.tasks.CheckinHeadCommitTask.java

License:Open Source License

/**
 * Builds the commit comment to use when checking in
 * /*  www  .  j av  a  2 s .c  o  m*/
 * @param commitDelta
 * @return
 */
private String buildCommitComment(CommitDelta commitDelta) {
    /* In deep mode the task will use the ToCommit message */
    if (deep) {
        /*
         * If the meta data flag was set to true, then build the meta data
         * string
         */
        if (includeMetaDataInComment) {
            return buildCommitComment(commitDelta.getToCommit());
        }
        /* Otherwise just use the full message */
        else {
            return commitDelta.getToCommit().getFullMessage();
        }
    }

    /*
     * In Shallow mode use the log command to identify all the commit
     * included in the delta
     */
    try {
        /*
         * TODO: Need to replace this code to use better logic to figure out
         * the included commits topologically and not chronologically
         */

        LogCommand logCommand = new Git(repository).log();
        logCommand.addRange(commitDelta.getFromCommit().getId(), commitDelta.getToCommit().getId());
        logCommand.setMaxCount(OutputConstants.DEFAULT_MAXCOMMENTROLLUP + 1);
        Iterable<RevCommit> commits = logCommand.call();

        int commitCounter = 0;

        StringBuilder comment = new StringBuilder();

        comment.append(Messages.formatString("CheckinHeadCommitTask.ShallowCheckinRollupFormat", //$NON-NLS-1$
                ObjectIdUtil.abbreviate(repository, commitDelta.getToCommit().getId()),
                ObjectIdUtil.abbreviate(repository, commitDelta.getFromCommit().getId()))
                + OutputConstants.NEW_LINE);
        comment.append(OutputConstants.NEW_LINE);

        for (RevCommit commit : commits) {
            commitCounter++;

            if (commitCounter > OutputConstants.DEFAULT_MAXCOMMENTROLLUP) {
                comment.append(Messages.formatString(
                        "CheckinHeadCommitTask.ShallowCheckinCommentDisplayTruncatedFormat", //$NON-NLS-1$
                        OutputConstants.DEFAULT_MAXCOMMENTROLLUP,
                        ObjectIdUtil.abbreviate(repository, commit.getId()),
                        ObjectIdUtil.abbreviate(repository, commitDelta.getFromCommit().getId())));

                break;
            }

            comment.append(buildCommitComment(commit) + OutputConstants.NEW_LINE);
        }

        if (commitCounter == 1) {
            return buildCommitComment(commitDelta.getToCommit());
        }

        return comment.toString();
    } catch (Exception e) {
        // if we fail execute the log command we default to the destination
        // commit full message

        return buildCommitComment(commitDelta.getToCommit());
    }
}

From source file:com.sbt.plugins.MyMojo.java

License:Apache License

private void writeLogsInWriter(Writer writer) throws IOException, GitAPIException {
    Repository existingRepo = new FileRepositoryBuilder().setGitDir(new File("./.git")).build();
    Git git = new Git(existingRepo);
    LogCommand logCommand = git.log();
    Iterable<RevCommit> logs = logCommand.call();
    for (RevCommit current : logs) {
        writer.write(current.getName() + ": " + current.getFullMessage());
        writer.write(LINE_SEPARATOR);//from  ww  w .ja  v a  2s .  co m
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java

License:Open Source License

private static void addHistory(Git git, Trees.Tree tree, ObjectId revision, String path)
        throws MissingObjectException, IncorrectObjectTypeException, GitAPIException {
    LogCommand logCommand = git.log();
    logCommand.add(revision);//  w ww.ja va2  s.com

    logCommand.addPath(path);

    for (RevCommit revCommit : logCommand.call()) {
        Commit commit = GitDomain.createCommit(revCommit);
        tree.setLatestCommit(commit);
        break;
    }

}

From source file:com.thoughtworks.go.service.ConfigRepository.java

License:Apache License

Iterable<RevCommit> revisions() throws GitAPIException {
    LogCommand command = git.log();
    return command.call();
}

From source file:com.thoughtworks.go.service.ConfigRepository.java

License:Apache License

public GoConfigRevisions getCommits(final int pageSize, final int offset) {
    return doLocked(() -> {
        GoConfigRevisions goConfigRevisions = new GoConfigRevisions();
        try {/*from  w w  w .j  av  a 2s.c o  m*/
            LogCommand command = git.log().setMaxCount(pageSize).setSkip(offset);
            Iterable<RevCommit> revisions = command.call();
            for (RevCommit revision : revisions) {
                GoConfigRevision goConfigRevision = new GoConfigRevision((byte[]) null,
                        revision.getFullMessage());
                goConfigRevision.setCommitSHA(revision.name());
                goConfigRevisions.add(goConfigRevision);
            }
        } catch (Exception e) {
            // ignore
        }
        return goConfigRevisions;
    });
}

From source file:com.tnd.eso.integration.scm.scripts.repository.GitParser.java

License:Open Source License

public String getLastCommitRevision(String fileName) {
    try {//from ww  w  .  j a va2  s  .  c o m
        LogCommand logCommand = git.log().add(repo.resolve(Constants.HEAD)).addPath(fileName);

        for (RevCommit revCommit : logCommand.call()) {
            return head + "-" + revCommit.getName().substring(0, 7);
        }
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}