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

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

Introduction

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

Prototype

public LogCommand addRange(AnyObjectId since, AnyObjectId until)
        throws MissingObjectException, IncorrectObjectTypeException 

Source Link

Document

Adds the range since..until

Usage

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

License:Open Source License

/**
 * Builds the commit comment to use when checking in
 * /*from   www  . j  a va  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:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

private void setRevisionRange(LogCommand logCommand, LogRequest request) throws IOException {
    if (request != null) {
        String revisionRangeSince = request.getRevisionRangeSince();
        String revisionRangeUntil = request.getRevisionRangeUntil();
        if (revisionRangeSince != null && revisionRangeUntil != null) {
            ObjectId since = repository.resolve(revisionRangeSince);
            ObjectId until = repository.resolve(revisionRangeUntil);
            logCommand.addRange(since, until);
        }//from  www . ja v  a  2  s . co  m
    }
}

From source file:org.eclipse.egit.internal.relengtools.GetBugsOperation.java

License:Open Source License

private void getBugNumbersForProject(IProject project, IProgressMonitor monitor, Set<Integer> set)
        throws Exception {

    final RepositoryMapping rm = RepositoryMapping.getMapping(project);
    final Repository repository = rm.getRepository();

    final RevCommit previousCommit = ShowInfoHandler.getCommitForTag(repository,
            getProjectTag(project).getName());
    final RevCommit latestCommit = ShowInfoHandler.getLatestCommitFor(rm, repository, project);

    final Git git = new Git(repository);
    final LogCommand log = git.log();
    log.addRange(previousCommit, latestCommit);
    for (final RevCommit commit : log.call()) {
        findBugNumber(commit.getFullMessage(), set);
    }/* w w w.  jav a 2 s .c  o m*/
}

From source file:org.eclipse.egit.internal.relengtools.ShowInfoHandler.java

License:Open Source License

public static void showLogBetween(final Repository repo, final RevCommit oldCommit, final RevCommit newCommit)
        throws MissingObjectException, IncorrectObjectTypeException, NoHeadException, Exception {
    final Git git = new Git(repo);
    final LogCommand command = git.log();
    command.addRange(oldCommit, newCommit);
    System.out.println("\nCommits:");
    for (final RevCommit rc : command.call()) {
        System.out.println(rc);//from  w w w .  j  a  va2  s .c om
        System.out.print("Tags: ");
        System.out.println(getTagsForCommit(repo, rc));
        System.out.println(rc.getShortMessage());
    }
}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

@Override
public List<CommitRef> update() {
    List<CommitRef> commits = new ArrayList<CommitRef>();
    try {//from  w  ww.ja  v a  2  s.co  m
        if (repository == null) {
            prepareWorkspace();
            initRepository();
        }
        Git git = new Git(repository);
        AnyObjectId oldHead = repository.resolve(Constants.HEAD);
        if (oldHead == null) {
            LOGGER.debug("Local repository is empty. Fetching remote repository.");
            FetchResult fetchResult = doRemoteUpdate();
            if (fetchResult.getTrackingRefUpdate(Constants.R_REMOTES + "origin/" + watchBranch) == null) {
                LOGGER.debug("Nothing to fetch from remote repository.");
                return null;
            }
            doCheckout(fetchResult);
        } else {
            LOGGER.debug("Local repository exists. Pulling remote repository.");
            git.pull().call();
        }
        AnyObjectId newHead = repository.resolve(Constants.HEAD);
        if (newHead == null) {
            LOGGER.debug("New HEAD of local repository doesnt exist.");
            return null;
        }
        if (newHead != oldHead) {
            LogCommand logCommand = git.log();
            if (oldHead == null) {
                LOGGER.debug("Retrieving revisions from HEAD [{}] on", newHead.name());
                logCommand.add(newHead);
            } else {
                LOGGER.debug("Retrieving revisions in range [{}, {}]", newHead.name(), oldHead.name());
                logCommand.addRange(oldHead, newHead);
            }
            Iterable<RevCommit> revisions = logCommand.call();
            for (RevCommit revision : revisions) {
                commits.add(new GitCommitRef(revision));
            }
        }
    } catch (Exception e) {
        throw new ScmException(e);
    }
    return commits;
}