]> source.dussan.org Git - jgit.git/commitdiff
Make use of the many date formatting options in the log command 82/4382/6
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 9 Oct 2011 20:01:39 +0000 (22:01 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 26 Oct 2011 21:15:24 +0000 (23:15 +0200)
Change-Id: I30f1049fce086f2cf7e39ba3ad8b335df3a7b827

org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java

index 1c95fd5f97520c6d0472cd329dd952740881a5cf..b57b1d7f7c581cc8a3371782bdba9f15a1a8e309 100644 (file)
@@ -183,6 +183,7 @@ usage_configureTheServiceInDaemonServicename=configure the service in daemon.ser
 usage_createBranchAndCheckout=create branch and checkout
 usage_deleteBranchEvenIfNotMerged=delete branch (even if not merged)
 usage_deleteFullyMergedBranch=delete fully merged branch
+usage_date=date format, one of default, rfc, local, iso, short, raw (as defined by git-log(1) ), locale or localelocal (jgit extensions)
 usage_detectRenames=detect renamed files
 usage_diffAlgorithm=the diff algorithm to use. Currently supported are: 'myers', 'histogram'
 usage_directoriesToExport=directories to export
index 6cc00938053e3d85849f5aa06fc548f22c199154..f0b2ca90c85c4b3b9bd01f555cb6b3b8f97a7e6e 100644 (file)
@@ -47,18 +47,14 @@ package org.eclipse.jgit.pgm;
 
 import java.io.BufferedOutputStream;
 import java.io.IOException;
-import java.text.DateFormat;
 import java.text.MessageFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
-import java.util.TimeZone;
 
 import org.eclipse.jgit.diff.DiffFormatter;
 import org.eclipse.jgit.diff.RawText;
@@ -73,14 +69,15 @@ import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.notes.NoteMap;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevTree;
-import org.eclipse.jgit.util.SystemReader;
+import org.eclipse.jgit.util.GitDateFormatter;
+import org.eclipse.jgit.util.GitDateFormatter.Format;
 import org.kohsuke.args4j.Option;
 
 @Command(common = true, usage = "usage_viewCommitHistory")
 class Log extends RevWalkTextBuiltin {
-       private final TimeZone myTZ = SystemReader.getInstance().getTimeZone();
 
-       private final DateFormat fmt;
+       private GitDateFormatter dateFormatter = new GitDateFormatter(
+                       Format.DEFAULT);
 
        private final DiffFormatter diffFmt = new DiffFormatter( //
                        new BufferedOutputStream(System.out));
@@ -102,6 +99,13 @@ class Log extends RevWalkTextBuiltin {
                additionalNoteRefs.add(notesRef);
        }
 
+       @Option(name = "--date", usage = "usage_date")
+       void dateFormat(String date) {
+               if (date.toLowerCase().equals(date))
+                       date = date.toUpperCase();
+               dateFormatter = new GitDateFormatter(Format.valueOf(date));
+       }
+
        // BEGIN -- Options shared with Diff
        @Option(name = "-p", usage = "usage_showPatch")
        boolean showPatch;
@@ -175,7 +179,7 @@ class Log extends RevWalkTextBuiltin {
 
 
        Log() {
-               fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy ZZZZZ", Locale.US);
+               dateFormatter = new GitDateFormatter(Format.DEFAULT);
        }
 
        @Override
@@ -246,10 +250,8 @@ class Log extends RevWalkTextBuiltin {
 
                final PersonIdent author = c.getAuthorIdent();
                out.println(MessageFormat.format(CLIText.get().authorInfo, author.getName(), author.getEmailAddress()));
-
-               final TimeZone authorTZ = author.getTimeZone();
-               fmt.setTimeZone(authorTZ != null ? authorTZ : myTZ);
-               out.println(MessageFormat.format(CLIText.get().dateInfo, fmt.format(author.getWhen())));
+               out.println(MessageFormat.format(CLIText.get().dateInfo,
+                               dateFormatter.formatDate(author)));
 
                out.println();
                final String[] lines = c.getFullMessage().split("\n");