Skip to content
Permalink
Browse files
416: Expose committer date in CommitMetadata
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Jun 15, 2020
1 parent f92cfb5 commit 5397abe44191249dbd6f87ab0d526c91638c7880
Show file tree
Hide file tree
Showing 29 changed files with 107 additions and 63 deletions.
@@ -72,7 +72,7 @@ private Optional<Hash> findIntegratedHash() {

private boolean hasLegacyIntegrationNotice(Repository localRepo, Commit commit) {
// Commits before this date are assumed to have been serviced by the old PR notifier
return commit.date().isBefore(ZonedDateTime.of(2020, 4, 28, 14, 0, 0, 0, ZoneId.of("UTC")));
return commit.authored().isBefore(ZonedDateTime.of(2020, 4, 28, 14, 0, 0, 0, ZoneId.of("UTC")));
}

private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repository localRepo, URI issueTracker, String issuePrefix, HostUserToEmailAuthor hostUserToEmailAuthor, HostUserToUserName hostUserToUserName, HostUserToRole hostUserToRole, WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification, String subjectPrefix) throws IOException {
@@ -38,7 +38,7 @@ public static String toTextBrief(HostedRepository repository, Commit commit) {
if (!commit.author().equals(commit.committer())) {
printer.println("Committer: " + commit.committer().name() + " <" + commit.committer().email() + ">");
}
printer.println("Date: " + commit.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
printer.println("Date: " + commit.authored().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
printer.println("URL: " + repository.webUrl(commit.hash()));

return writer.toString();
@@ -56,7 +56,7 @@ private JSONObject commitToChanges(HostedRepository repository, Repository local
}
ret.put("issue", issueIds);
ret.put("user", commit.author().name());
ret.put("date", commit.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
ret.put("date", commit.authored().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));

return ret;
}
@@ -89,7 +89,7 @@ public void onNewCommits(HostedRepository repository,
query.put("text", branch.name() + ": " + commit.hash().abbreviate() + ": " + title + "\n" +
"Author: " + commit.author().name() + "\n" +
"Committer: " + commit.author().name() + "\n" +
"Date: " + commit.date().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "\n");
"Date: " + commit.authored().format(DateTimeFormatter.RFC_1123_DATE_TIME) + "\n");

var attachment = JSON.object();
attachment.put("fallback", "Link to commit");
@@ -304,10 +304,11 @@ public Optional<CommitMetadata> commitMetadata(Hash hash) {
var commit = o.get("commit").asObject();
var author = new Author(commit.get("author").get("name").asString(),
commit.get("author").get("email").asString());
var authored = ZonedDateTime.parse(commit.get("author").get("date").asString());
var committer = new Author(commit.get("committer").get("name").asString(),
commit.get("committer").get("email").asString());
var date = ZonedDateTime.parse(commit.get("author").get("date").asString());
var committed = ZonedDateTime.parse(commit.get("committer").get("date").asString());
var message = Arrays.asList(commit.get("message").asString().split("\n"));
return Optional.of(new CommitMetadata(hash, parents, author, committer, date, message));
return Optional.of(new CommitMetadata(hash, parents, author, authored, committer, committed, message));
}
}
@@ -337,10 +337,11 @@ public Optional<CommitMetadata> commitMetadata(Hash hash) {
.collect(Collectors.toList());
var author = new Author(c.get("author_name").asString(),
c.get("author_email").asString());
var authored = ZonedDateTime.parse(c.get("authored_date").asString());
var committer = new Author(c.get("committer_name").asString(),
c.get("committer_email").asString());
var date = ZonedDateTime.parse(c.get("authored_date").asString());
var committed = ZonedDateTime.parse(c.get("comitted_date").asString());
var message = Arrays.asList(c.get("message").asString().split("\n"));
return Optional.of(new CommitMetadata(hash, parents, author, committer, date, message));
return Optional.of(new CommitMetadata(hash, parents, author, authored, committer, committed, message));
}
}
@@ -43,11 +43,12 @@ class AuthorCheckTests {

private static Commit commit(Author author) {
var committer = new Author("Foo", "foo@bar.org");
var committed = ZonedDateTime.now();
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var authored = ZonedDateTime.now();
var message = List.of("Initial commit");
var metadata = new CommitMetadata(hash, parents, author, committer, date, message);
var metadata = new CommitMetadata(hash, parents, author, authored, committer, committed, message);
return new Commit(metadata, List.of());
}

@@ -59,8 +59,8 @@ private static Commit commit(List<Diff> parentDiffs) {
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash, hash);
var message = List.of("A commit");
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, parentDiffs);
}

@@ -42,11 +42,10 @@ class BlacklistCheckTests {

private static Commit commit(Hash hash) {
var author = new Author("Foo", "foo@bar.org");
var committer = author;
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var authored = ZonedDateTime.now();
var message = List.of("Initial commit");
var metadata = new CommitMetadata(hash, parents, author, committer, date, message);
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -80,7 +80,7 @@ private static Commit mergeCommit(Author author, Author committer) {
var parents = List.of(hash, hash);
var date = ZonedDateTime.now();
var message = List.of("Merge");
var metadata = new CommitMetadata(hash, parents, author, committer, date, message);
var metadata = new CommitMetadata(hash, parents, author, date, committer, date, message);
return new Commit(metadata, List.of());
}

@@ -89,7 +89,7 @@ private static Commit commit(Author author, Author committer) {
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var message = List.of("Initial commit");
var metadata = new CommitMetadata(hash, parents, author, committer, date, message);
var metadata = new CommitMetadata(hash, parents, author, date, committer, date, message);
return new Commit(metadata, List.of());
}

@@ -60,8 +60,8 @@ private static Commit commit(List<Diff> parentDiffs) {
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash, hash);
var message = List.of("A commit");
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, parentDiffs);
}

@@ -60,8 +60,8 @@ private static List<Diff> parentDiffs(String line) {
private static Commit commit(Hash hash, List<String> message, List<Diff> parentDiffs) {
var author = new Author("Foo Bar", "foo@bar.org");
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, parentDiffs);
}

@@ -70,8 +70,8 @@ private static Commit mergeCommit() {
var parents = List.of(new Hash("12345789012345789012345678901234567890"),
new Hash("12345789012345789012345678901234567890"));
var message = List.of("Merge");
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(Hash.zero(), parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(Hash.zero(), parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -81,8 +81,8 @@ private static Commit commit(List<String> message) {
var author = new Author("foo", "foo@host.org");
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash);
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -56,8 +56,8 @@ private static Commit commit(List<String> message) {
var author = new Author("foo", "foo@host.org");
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash, hash);
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -56,8 +56,8 @@ private static Commit commit(List<String> message) {
var author = new Author("foo", "foo@host.org");
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash);
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -152,8 +152,8 @@ private static Commit commit(int id, String... message) {
var author = new Author("foo", "foo@host.org");
var hash = new Hash(("" + id).repeat(40));
var parents = List.of(Hash.zero());
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, List.of(message));
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, List.of(message));
return new Commit(metadata, List.of());
}

@@ -396,4 +396,4 @@ void singlePrefixedAlwaysProblemListedConf4() {

}

}
}
@@ -101,13 +101,13 @@ private static Commit commit(List<String> reviewers) {
private static Commit commit(Author author, List<String> reviewers) {
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var authored = ZonedDateTime.now();
var message = new ArrayList<String>();
message.addAll(List.of("Initial commit"));
if (!reviewers.isEmpty()) {
message.addAll(List.of("", "Reviewed-by: " + String.join(", ", reviewers)));
}
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, List.of());
}

@@ -71,8 +71,8 @@ private static Commit commit(List<Diff> diffs) {
var author = new Author("foo", "foo@localhost");
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(hash);
var date = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, author, date, List.of("Added symlink"));
var authored = ZonedDateTime.now();
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, List.of("Added symlink"));
return new Commit(metadata, diffs);
}

@@ -66,9 +66,9 @@ private static Commit commit(List<Diff> parentDiffs) {
var author = new Author("Foo Bar", "foo@bar.org");
var hash = new Hash("0123456789012345678901234567890123456789");
var parents = List.of(new Hash("12345789012345789012345678901234567890"));
var date = ZonedDateTime.now();
var authored = ZonedDateTime.now();
var message = List.of("Initial commit", "", "Reviewed-by: baz");
var metadata = new CommitMetadata(hash, parents, author, author, date, message);
var metadata = new CommitMetadata(hash, parents, author, authored, author, authored, message);
return new Commit(metadata, parentDiffs);
}

@@ -63,8 +63,12 @@ public boolean isInitialCommit() {
return metadata.isInitialCommit();
}

public ZonedDateTime date() {
return metadata.date();
public ZonedDateTime authored() {
return metadata.authored();
}

public ZonedDateTime committed() {
return metadata.committed();
}

public boolean isMerge() {
@@ -30,18 +30,21 @@ public class CommitMetadata {
private final Hash hash;
private final List<Hash> parents;
private final Author author;
private final ZonedDateTime authored;
private final Author committer;
private final ZonedDateTime date;
private final ZonedDateTime committed;
private final List<String> message;

public CommitMetadata(Hash hash, List<Hash> parents,
Author author, Author committer,
ZonedDateTime date, List<String> message) {
Author author, ZonedDateTime authored,
Author committer, ZonedDateTime committed,
List<String> message) {
this.hash = hash;
this.parents = parents;
this.author = author;
this.authored = authored;
this.committer = committer;
this.date = date;
this.committed = committed;
this.message = message;
}

@@ -65,8 +68,12 @@ public List<Hash> parents() {
return parents;
}

public ZonedDateTime date() {
return date;
public ZonedDateTime authored() {
return authored;
}

public ZonedDateTime committed() {
return committed;
}

public boolean isInitialCommit() {
@@ -84,14 +91,14 @@ public int numParents() {
@Override
public String toString() {
final var formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
final var displayDate = date.format(formatter);
final var displayDate = authored.format(formatter);
return String.format("%s %-12s %s %s",
hash().toString(), author(), displayDate, message.get(0));
}

@Override
public int hashCode() {
return Objects.hash(hash, parents, author, committer, date, message);
return Objects.hash(hash, parents, author, authored, committer, committed, message);
}

@Override
@@ -104,8 +111,9 @@ public boolean equals(Object o) {
return Objects.equals(hash, other.hash) &&
Objects.equals(parents, other.parents) &&
Objects.equals(author, other.author) &&
Objects.equals(authored, other.authored) &&
Objects.equals(committer, other.committer) &&
Objects.equals(date, other.date) &&
Objects.equals(committed, other.committed) &&
Objects.equals(message, other.message);
}
}
@@ -39,9 +39,10 @@ class GitCommitMetadata {
private static final String parentsFormat = "%P";
private static final String authorNameFormat = "%an";
private static final String authorEmailFormat = "%ae";
private static final String authorDateFormat = "%aI";
private static final String committerNameFormat = "%cn";
private static final String committerEmailFormat = "%ce";
private static final String timestampFormat = "%aI";
private static final String committerDateFormat = "%cI";

private static final String messageDelimiter = "=@=@=@=@=@";
private static final String messageFormat = "%B" + messageDelimiter;
@@ -51,9 +52,10 @@ class GitCommitMetadata {
parentsFormat,
authorNameFormat,
authorEmailFormat,
authorDateFormat,
committerNameFormat,
committerEmailFormat,
timestampFormat,
committerDateFormat,
messageFormat);

public static CommitMetadata read(UnixStreamReader reader) throws IOException {
@@ -69,20 +71,24 @@ public static CommitMetadata read(UnixStreamReader reader) throws IOException {
parents.add(new Hash(parentHash));
}

var dateFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

var authorName = reader.readLine();
log.finer("authorName: " + authorName);
var authorEmail = reader.readLine();
log.finer("authorEmail: " + authorEmail);
var author = new Author(authorName, authorEmail);
var authored = ZonedDateTime.parse(reader.readLine(), dateFormatter);
log.finer("authorDate: " + authored);

var committerName = reader.readLine();
log.finer("committerName: " + committerName);
var committerEmail = reader.readLine();
log.finer("committerEmail " + committerName);
var committer = new Author(committerName, committerEmail);
var committed = ZonedDateTime.parse(reader.readLine(), dateFormatter);
log.finer("committerDate: " + committed);

var formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
var date = ZonedDateTime.parse(reader.readLine(), formatter);

var message = new ArrayList<String>();
var line = reader.readLine();
@@ -96,6 +102,6 @@ public static CommitMetadata read(UnixStreamReader reader) throws IOException {
message.add(prefix);
}

return new CommitMetadata(hash, parents, author, committer, date, message);
return new CommitMetadata(hash, parents, author, authored, committer, committed, message);
}
}

1 comment on commit 5397abe

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 5397abe Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.