Add utility methods for decoding the author, committer to RevCommit
[egit/zawir.git] / org.spearce.jgit / src / org / spearce / jgit / pgm / Log.java
blobdf0328d9fe3e9e014132bb49f780319e070010f1
1 /*
2 * Copyright (C) 2008 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org.spearce.jgit.pgm;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.TimeZone;
23 import org.spearce.jgit.lib.PersonIdent;
24 import org.spearce.jgit.revwalk.RevCommit;
26 class Log extends RevWalkTextBuiltin {
27 private final TimeZone myTZ = TimeZone.getDefault();
29 private final DateFormat fmt;
31 Log() {
32 fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ");
35 @Override
36 protected void show(final RevCommit c) throws Exception {
37 out.print("commit ");
38 c.getId().copyTo(outbuffer, out);
39 out.println();
41 final PersonIdent author = c.getAuthorIdent();
42 out.print("Author: ");
43 out.print(author.getName());
44 out.print(" <");
45 out.print(author.getEmailAddress());
46 out.print(">");
47 out.println();
49 final TimeZone authorTZ = author.getTimeZone();
50 fmt.setTimeZone(authorTZ != null ? authorTZ : myTZ);
51 out.print("Date: ");
52 out.print(fmt.format(author.getWhen()));
53 out.println();
55 out.println();
56 final String[] lines = c.getFullMessage().split("\n");
57 for (final String s : lines) {
58 out.print(" ");
59 out.print(s);
60 out.println();
63 out.println();
64 out.flush();