From: Andy Parkins <andyparkins@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH] Add a --dateformat= option to git-for-each-ref
Date: Wed, 26 Sep 2007 10:09:18 +0100 [thread overview]
Message-ID: <200709261009.18777.andyparkins@gmail.com> (raw)
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
next reply other threads:[~2007-09-26 9:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-26 9:09 Andy Parkins [this message]
2007-09-26 12:58 ` [PATCH] Add a --dateformat= option to git-for-each-ref 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200709261009.18777.andyparkins@gmail.com \
--to=andyparkins@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).