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

The following examples show how to use org.eclipse.jgit.revwalk.RevCommit#getAuthorIdent() . These examples are extracted from open source projects. 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 Project: hop   File: UIGit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String getAuthorName( String commitId ) {
  if ( commitId.equals( IVCS.WORKINGTREE ) ) {
    Config config = git.getRepository().getConfig();
    return config.get( UserConfig.KEY ).getAuthorName()
        + " <" + config.get( UserConfig.KEY ).getAuthorEmail() + ">";
  } else {
    RevCommit commit = resolve( commitId );
    PersonIdent author = commit.getAuthorIdent();
    final StringBuilder r = new StringBuilder();
    r.append( author.getName() );
    r.append( " <" ); //$NON-NLS-1$
    r.append( author.getEmailAddress() );
    r.append( ">" ); //$NON-NLS-1$
    return r.toString();
  }
}
 
Example 2
Source Project: onedev   File: BlameMessageBehavior.java    License: 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 3
public CommitInfo createCommitInfo(RevCommit entry) {
    final Date date = GitUtils.getCommitDate(entry);
    PersonIdent authorIdent = entry.getAuthorIdent();
    String author = null;
    String name = null;
    String email = null;
    String avatarUrl = null;
    if (authorIdent != null) {
        author = authorIdent.getName();
        name = authorIdent.getName();
        email = authorIdent.getEmailAddress();

        // lets try default the avatar
        if (Strings.isNotBlank(email)) {
            avatarUrl = getAvatarUrl(email);
        }
    }
    boolean merge = entry.getParentCount() > 1;
    String shortMessage = entry.getShortMessage();
    String sha = entry.getName();
    return new CommitInfo(sha, author, name, email, avatarUrl, date, merge, shortMessage);
}
 
Example 4
Source Project: repositoryminer   File: GitSCM.java    License: 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 5
Source Project: jphp   File: GitUtils.java    License: 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 6
Source Project: Jpom   File: GitUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 获取对应分支的最后一次提交记录
 *
 * @param file       仓库文件夹
 * @param branchName 分支
 * @return 描述
 * @throws IOException     IO
 * @throws GitAPIException api
 */
public static String getLastCommitMsg(File file, String branchName) throws IOException, GitAPIException {
    try (Git git = Git.open(file)) {
        AnyObjectId anyObjectId = getAnyObjectId(git, branchName);
        Objects.requireNonNull(anyObjectId, "没有" + branchName + "分支");
        RevWalk walk = new RevWalk(git.getRepository());
        RevCommit revCommit = walk.parseCommit(anyObjectId);
        String time = new DateTime(revCommit.getCommitTime() * 1000L).toString();
        PersonIdent personIdent = revCommit.getAuthorIdent();
        return StrUtil.format("{} {} {}[{}] {}", branchName, revCommit.getShortMessage(), personIdent.getName(), personIdent.getEmailAddress(), time);
    }
}
 
Example 7
Source Project: netbeans   File: CommitCommand.java    License: Apache License 2.0 5 votes vote down vote up
private void transferTimestamp (org.eclipse.jgit.api.CommitCommand commit, RevCommit lastCommit) {
    PersonIdent lastAuthor = lastCommit.getAuthorIdent();
    if (lastAuthor != null) {
        PersonIdent author = commit.getAuthor();
        commit.setAuthor(lastAuthor.getTimeZone() == null
                ? new PersonIdent(author, lastAuthor.getWhen())
                : new PersonIdent(author, lastAuthor.getWhen(), lastAuthor.getTimeZone()));
    }
}
 
Example 8
Source Project: app-runner   File: GitCommit.java    License: MIT License 5 votes vote down vote up
public static GitCommit fromHEAD(Git git) throws Exception {
    ObjectId head = git.getRepository().resolve("HEAD");
    if (head != null) {
        RevCommit mostRecentCommit;
        try (RevWalk walk = new RevWalk(git.getRepository())) {
            mostRecentCommit = walk.parseCommit(head);
        }
        Date commitDate = new Date(1000L * mostRecentCommit.getCommitTime());
        String id = mostRecentCommit.getId().name();
        PersonIdent author = mostRecentCommit.getAuthorIdent();
        return new GitCommit(id, commitDate, author.getName(), mostRecentCommit.getFullMessage());
    } else {
        return null;
    }
}
 
Example 9
Source Project: coderadar   File: ExtractProjectCommitsAdapter.java    License: MIT License 5 votes vote down vote up
private Commit mapRevCommitToCommit(RevCommit rc) {
  Commit commit = new Commit();
  commit.setName(rc.getName());
  PersonIdent personIdent = rc.getAuthorIdent();
  commit.setAuthor(personIdent.getName());
  commit.setAuthorEmail(personIdent.getEmailAddress());
  commit.setComment(rc.getShortMessage());
  commit.setTimestamp(personIdent.getWhen().getTime());
  return commit;
}
 
Example 10
Source Project: git-client-plugin   File: JGitAPIImpl.java    License: 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();
     }
        }
    }
}