blob: 87f3456c40f24662d28411fda9b2cf05b82bf007 [file] [log] [blame]
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -07001// Copyright (C) 2013 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
17import com.google.common.collect.Lists;
18
19import org.eclipse.jgit.lib.PersonIdent;
20import org.eclipse.jgit.revwalk.RevCommit;
21import org.eclipse.jgit.util.GitDateFormatter;
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070022
23import java.util.List;
24
25class CommitJsonData {
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070026 static class Commit {
27 String commit;
28 List<String> parents;
29 Ident author;
30 Ident committer;
31 String message;
32 }
33
34 static class Ident {
35 String name;
36 String email;
37 String time;
38 }
39
Dave Borowitza03760a2014-01-29 16:17:28 -080040 static Commit toJsonData(RevCommit c, GitDateFormatter df) {
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070041 Commit result = new Commit();
42 result.commit = c.name();
43 result.parents = Lists.newArrayListWithCapacity(c.getParentCount());
44 for (RevCommit parent : c.getParents()) {
45 result.parents.add(parent.name());
46 }
Dave Borowitza03760a2014-01-29 16:17:28 -080047 result.author = toJsonData(c.getAuthorIdent(), df);
48 result.committer = toJsonData(c.getCommitterIdent(), df);
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070049 result.message = c.getFullMessage();
50 return result;
51 }
52
Dave Borowitza03760a2014-01-29 16:17:28 -080053 private static Ident toJsonData(PersonIdent ident, GitDateFormatter df) {
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070054 Ident result = new Ident();
55 result.name = ident.getName();
56 result.email = ident.getEmailAddress();
Dave Borowitza03760a2014-01-29 16:17:28 -080057 result.time = df.formatDate(ident);
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070058 return result;
59 }
60
61 private CommitJsonData() {
62 }
63}