Java Code Examples for org.eclipse.jgit.revwalk.RevCommit#getCommitterIdent()

The following examples show how to use org.eclipse.jgit.revwalk.RevCommit#getCommitterIdent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlameMessageBehavior.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
	
	String tooltipId = params.getParameterValue("tooltip").toString();
	String commitHash = params.getParameterValue("commit").toString();
	RevCommit commit = getProject().getRevCommit(commitHash, true);
	String authoring;
	if (commit.getAuthorIdent() != null) {
		authoring = commit.getAuthorIdent().getName();
		if (commit.getCommitterIdent() != null)
			authoring += " " + DateUtils.formatAge(commit.getCommitterIdent().getWhen());
		authoring = "'" + JavaScriptEscape.escapeJavaScript(authoring) + "'";
	} else {
		authoring = "undefined";
	}
	String message = JavaScriptEscape.escapeJavaScript(commit.getFullMessage());
	String script = String.format("onedev.server.blameMessage.show('%s', %s, '%s');", tooltipId, authoring, message); 
	target.appendJavaScript(script);
}
 
Example 2
Source File: GitRepository.java    From centraldogma with Apache License 2.0 6 votes vote down vote up
private static Commit toCommit(RevCommit revCommit) {
    final Author author;
    final PersonIdent committerIdent = revCommit.getCommitterIdent();
    final long when;
    if (committerIdent == null) {
        author = Author.UNKNOWN;
        when = 0;
    } else {
        author = new Author(committerIdent.getName(), committerIdent.getEmailAddress());
        when = committerIdent.getWhen().getTime();
    }

    try {
        return CommitUtil.newCommit(author, when, revCommit.getFullMessage());
    } catch (Exception e) {
        throw new StorageException("failed to create a Commit", e);
    }
}
 
Example 3
Source File: GitSCM.java    From repositoryminer with Apache License 2.0 6 votes vote down vote up
private Commit processCommit(RevCommit revCommit) {
	PersonIdent author = revCommit.getAuthorIdent();
	PersonIdent committer = revCommit.getCommitterIdent();

	Developer myAuthor = new Developer(author.getName(), author.getEmailAddress());
	Developer myCommitter = new Developer(committer.getName(), committer.getEmailAddress());

	List<String> parents = new ArrayList<String>();
	for (RevCommit parent : revCommit.getParents()) {
		parents.add(parent.getName());
	}

	List<Change> changes = null;
	try {
		changes = getChangesForCommitedFiles(revCommit.getName());
	} catch (IOException e) {
		close();
		throw new RepositoryMinerException(e);
	}

	return new Commit(null, revCommit.getName(), myAuthor, myCommitter, revCommit.getFullMessage().trim(), changes,
			parents, author.getWhen(), committer.getWhen(), (parents.size() > 1), null);
}
 
Example 4
Source File: GitUtils.java    From jphp with Apache License 2.0 6 votes vote down vote up
public static ArrayMemory valueOf(RevCommit value) {
    ArrayMemory memory = valueOf((RevObject) value);

    memory.refOfIndex("commitTime").assign(value.getCommitTime());
    memory.refOfIndex("encoding").assign(value.getEncodingName());
    memory.refOfIndex("shortMessage").assign(value.getShortMessage());
    memory.refOfIndex("fullMessage").assign(value.getFullMessage());
    
    ArrayMemory parents = new ArrayMemory();
    for (RevCommit revCommit : value.getParents()) {
        parents.add(valueOf((RevObject)revCommit));
    }

    memory.refOfIndex("parents").assign(parents);

    PersonIdent authorIdent = value.getAuthorIdent();
    memory.refOfIndex("author").assign(authorIdent == null ? Memory.NULL : valueOf(authorIdent));

    PersonIdent committerIdent = value.getCommitterIdent();
    memory.refOfIndex("committer").assign(committerIdent == null ? Memory.NULL : valueOf(committerIdent));

    return memory;
}
 
Example 5
Source File: VersionControlGit.java    From mdw with Apache License 2.0 5 votes vote down vote up
private CommitInfo getCommitInfo(RevCommit revCommit) {
    CommitInfo commitInfo = new CommitInfo(revCommit.getId().name());
    PersonIdent committerIdent = revCommit.getCommitterIdent();
    commitInfo.setCommitter(committerIdent.getName());
    commitInfo.setEmail(committerIdent.getEmailAddress());
    if ((commitInfo.getCommitter() == null || commitInfo.getCommitter().isEmpty()) && commitInfo.getEmail() != null)
        commitInfo.setCommitter(commitInfo.getEmail());
    commitInfo.setDate(committerIdent.getWhen());
    commitInfo.setMessage(revCommit.getShortMessage());
    return commitInfo;
}
 
Example 6
Source File: SubtreeMerger.java    From git-merge-repos with Apache License 2.0 5 votes vote down vote up
private PersonIdent getLatestPersonIdent(Collection<RevCommit> commits) {
	PersonIdent latest = null;
	for (RevCommit commit : commits) {
		PersonIdent ident = commit.getCommitterIdent();
		Date when = ident.getWhen();
		if (latest == null || when.after(latest.getWhen())) {
			latest = ident;
		}
	}
	return latest;
}
 
Example 7
Source File: JGitAPIImpl.java    From git-client-plugin with MIT License 4 votes vote down vote up
/**
 * Formats a commit into the raw format.
 *
 * @param commit
 *      Commit to format.
 * @param parent
 *      Optional parent commit to produce the diff against. This only matters
 *      for merge commits, and git-log/git-whatchanged/etc behaves differently with respect to this.
 */
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE",
        justification = "Windows git implementation requires specific line termination")
void format(RevCommit commit, RevCommit parent, PrintWriter pw, Boolean useRawOutput) throws IOException {
    if (parent!=null)
        pw.printf("commit %s (from %s)\n", commit.name(), parent.name());
    else
        pw.printf("commit %s\n", commit.name());

    pw.printf("tree %s\n", commit.getTree().name());
    for (RevCommit p : commit.getParents())
        pw.printf("parent %s\n",p.name());
    FastDateFormat iso = FastDateFormat.getInstance(ISO_8601);
    PersonIdent a = commit.getAuthorIdent();
    pw.printf("author %s <%s> %s\n", a.getName(), a.getEmailAddress(), iso.format(a.getWhen()));
    PersonIdent c = commit.getCommitterIdent();
    pw.printf("committer %s <%s> %s\n", c.getName(), c.getEmailAddress(), iso.format(c.getWhen()));

    // indent commit messages by 4 chars
    String msg = commit.getFullMessage();
    if (msg.endsWith("\n")) msg=msg.substring(0,msg.length()-1);
    msg = msg.replace("\n","\n    ");
    msg="\n    "+msg+"\n";

    pw.println(msg);

    // see man git-diff-tree for the format
    try (Repository repo = getRepository();
         ObjectReader or = repo.newObjectReader();
         TreeWalk tw = new TreeWalk(or)) {
    if (parent != null) {
        /* Caller provided a parent commit, use it */
        tw.reset(parent.getTree(), commit.getTree());
    } else {
        if (commit.getParentCount() > 0) {
            /* Caller failed to provide parent, but a parent
             * is available, so use the parent in the walk
             */
            tw.reset(commit.getParent(0).getTree(), commit.getTree());
        } else {
            /* First commit in repo has 0 parent count, but
             * the TreeWalk requires exactly two nodes for its
             * walk.  Use the same node twice to satisfy
             * TreeWalk. See JENKINS-22343 for details.
             */
            tw.reset(commit.getTree(), commit.getTree());
        }
    }
    tw.setRecursive(true);
    tw.setFilter(TreeFilter.ANY_DIFF);

    final RenameDetector rd = new RenameDetector(repo);

    rd.reset();
    rd.addAll(DiffEntry.scan(tw));
    List<DiffEntry> diffs = rd.compute(or, null);
    if (useRawOutput) {
     for (DiffEntry diff : diffs) {
         pw.printf(":%06o %06o %s %s %s\t%s",
                 diff.getOldMode().getBits(),
                 diff.getNewMode().getBits(),
                 diff.getOldId().name(),
                 diff.getNewId().name(),
                 statusOf(diff),
                 diff.getChangeType()==ChangeType.ADD ? diff.getNewPath() : diff.getOldPath());

         if (hasNewPath(diff)) {
             pw.printf(" %s",diff.getNewPath()); // copied to
         }
         pw.println();
         pw.println();
     }
        }
    }
}