git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add a --dateformat= option to git-for-each-ref
@ 2007-09-26  9:09 Andy Parkins
  2007-09-26 12:58 ` Jeff King
  0 siblings, 1 reply; 15+ messages in thread
From: Andy Parkins @ 2007-09-26  9:09 UTC (permalink / raw)
  To: git

I wanted to get date information in RFC2822 format out of a tag using
git-for-each-ref; but there was no way to specify that.  This patch
addresses that omission by adding a --dateformat option.

For example (I'm in BST, +0100 at present):

 $ git-for-each-ref --dateformat=normal --format='%(taggerdate)' refs/tags/v1.5.2
 Sun May 20 00:30:42 2007 -0700
 $ git-for-each-ref --dateformat=relative --format='%(taggerdate)' refs/tags/v1.5.2
 4 months ago
 $ git-for-each-ref --dateformat=short --format='%(taggerdate)' refs/tags/v1.5.2
 2007-05-20
 $ git-for-each-ref --dateformat=local --format='%(taggerdate)' refs/tags/v1.5.2
 Sun May 20 08:30:42 2007
 $ git-for-each-ref --dateformat=iso8601 --format='%(taggerdate)' refs/tags/v1.5.2
 2007-05-20 00:30:42 -0700
 $ git-for-each-ref --dateformat=rfc2822 --format='%(taggerdate)' refs/tags/v1.5.2
 Sun, 20 May 2007 00:30:42 -0700

The default is to use 'normal', which leaves existing behaviour
unchanged.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 Documentation/git-for-each-ref.txt |    6 ++++++
 builtin-for-each-ref.c             |   18 +++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 6df8e85..1b8fdb8 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'git-for-each-ref' [--count=<count>]\*
                    [--shell|--perl|--python|--tcl]
+                   [--dateformat=normal|relative|short|local|iso8601|rfc2822]
                    [--sort=<key>]\* [--format=<format>] [<pattern>]
 
 DESCRIPTION
@@ -58,6 +59,11 @@ OPTIONS
 	the specified host language.  This is meant to produce
 	a scriptlet that can directly be `eval`ed.
 
+--dateformat::
+	If given, all timestamp fields will be output in the specified
+	format.  This is only really relevant for innvocations using the
+	--format option with a `%(date)`-type field.
+
 
 FIELD NAMES
 -----------
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 0afa1c5..80e58fc 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -80,6 +80,7 @@ static struct {
 static const char **used_atom;
 static cmp_type *used_atom_type;
 static int used_atom_cnt, sort_atom_limit, need_tagged;
+static enum date_mode date_mode = DATE_NORMAL;
 
 /*
  * Used to parse format string and sort specifiers
@@ -362,7 +363,7 @@ static void grab_date(const char *buf, struct atom_value *v)
 	tz = strtol(zone, NULL, 10);
 	if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
 		goto bad;
-	v->s = xstrdup(show_date(timestamp, tz, 0));
+	v->s = xstrdup(show_date(timestamp, tz, date_mode));
 	v->ul = timestamp;
 	return;
  bad:
@@ -870,6 +871,21 @@ int cmd_for_each_ref(int ac, const char **av, const char *prefix)
 			sort->atom = parse_atom(arg, arg+len);
 			continue;
 		}
+		if (!prefixcmp(arg, "--dateformat=")) {
+			arg += 13;
+			if (!prefixcmp(arg,"relative")) {
+				date_mode = DATE_RELATIVE;
+			} else if (!prefixcmp(arg,"short")) {
+				date_mode = DATE_SHORT;
+			} else if (!prefixcmp(arg,"local")) {
+				date_mode = DATE_LOCAL;
+			} else if (!prefixcmp(arg,"iso8601")) {
+				date_mode = DATE_ISO8601;
+			} else if (!prefixcmp(arg,"rfc2822")) {
+				date_mode = DATE_RFC2822;
+			}
+			continue;
+		}
 		break;
 	}
 	if (quote_style < 0)
-- 
1.5.3.1.5.g4e560-dirty

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2007-09-29  8:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-26  9:09 [PATCH] Add a --dateformat= option to git-for-each-ref Andy Parkins
2007-09-26 12:58 ` Jeff King
2007-09-28 14:15   ` Andy Parkins
2007-09-28 14:17     ` [PATCH 1/4] Add parse_date_format() convenience function for converting a format string to an enum date_mode Andy Parkins
2007-09-28 14:17     ` [PATCH 2/4] Use parse_date_format() in revisions.c to parse the --date parameter Andy Parkins
2007-09-28 15:22       ` Johannes Schindelin
2007-09-28 18:00         ` Andy Parkins
2007-09-28 18:11           ` Junio C Hamano
2007-09-29  7:39             ` [PATCH 1/3] Use parse_date_format() convenience function for converting a format string to an enum date_mode in revisions.c Andy Parkins
2007-09-29  7:39             ` [PATCH 2/3] Make for-each-ref allow atom names like "<name>:<something>" Andy Parkins
2007-09-29  7:39             ` [PATCH 3/3] Make for-each-ref's grab_date() support per-atom formatting Andy Parkins
2007-09-28 14:17     ` [PATCH 3/4] Make for-each-ref allow atom names like "<name>:<something>" Andy Parkins
2007-09-28 14:17     ` [PATCH 4/4] Make for-each-ref's grab_date() support per-atom formatting Andy Parkins
2007-09-29  8:17       ` Junio C Hamano
2007-09-28 18:47     ` [PATCH] Add a --dateformat= option to git-for-each-ref Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).