| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.gitiles; |
| 16 | |
| 17 | import com.google.common.collect.Lists; |
| 18 | |
| 19 | import org.eclipse.jgit.lib.PersonIdent; |
| 20 | import org.eclipse.jgit.revwalk.RevCommit; |
| 21 | import org.eclipse.jgit.util.GitDateFormatter; |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 22 | |
| 23 | import java.util.List; |
| 24 | |
| 25 | class CommitJsonData { |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 26 | 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 Borowitz | a03760a | 2014-01-29 16:17:28 -0800 | [diff] [blame] | 40 | static Commit toJsonData(RevCommit c, GitDateFormatter df) { |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 41 | 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 Borowitz | a03760a | 2014-01-29 16:17:28 -0800 | [diff] [blame] | 47 | result.author = toJsonData(c.getAuthorIdent(), df); |
| 48 | result.committer = toJsonData(c.getCommitterIdent(), df); |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 49 | result.message = c.getFullMessage(); |
| 50 | return result; |
| 51 | } |
| 52 | |
| Dave Borowitz | a03760a | 2014-01-29 16:17:28 -0800 | [diff] [blame] | 53 | private static Ident toJsonData(PersonIdent ident, GitDateFormatter df) { |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 54 | Ident result = new Ident(); |
| 55 | result.name = ident.getName(); |
| 56 | result.email = ident.getEmailAddress(); |
| Dave Borowitz | a03760a | 2014-01-29 16:17:28 -0800 | [diff] [blame] | 57 | result.time = df.formatDate(ident); |
| Dave Borowitz | d6ebc2d | 2013-11-01 11:44:06 -0700 | [diff] [blame] | 58 | return result; |
| 59 | } |
| 60 | |
| 61 | private CommitJsonData() { |
| 62 | } |
| 63 | } |