git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Will Palmer <wmpalmer@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Will Palmer <wmpalmer@gmail.com>
Subject: [PATCH/RFC 2/9] add support for --date=unix to complement %at
Date: Tue, 29 Mar 2011 00:17:24 +0100	[thread overview]
Message-ID: <1301354251-23380-3-git-send-email-wmpalmer@gmail.com> (raw)
In-Reply-To: <1301354251-23380-1-git-send-email-wmpalmer@gmail.com>

this adds support for --date=unix to the "git log" family of commands,
which would cause %ad and %cd to act like %at and %ct respectively.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
---
 Documentation/blame-options.txt    |    2 +-
 Documentation/git-rev-list.txt     |    2 +-
 Documentation/rev-list-options.txt |    4 +++-
 builtin/blame.c                    |    3 +++
 cache.h                            |    3 ++-
 date.c                             |    7 +++++++
 6 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index e11a3da..2586606 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -72,7 +72,7 @@ of lines before or after the line given by <start>.
 
 --date <format>::
 	The value is one of the following alternatives:
-	{relative,local,default,iso,rfc,short,raw}. If --date is
+	{relative,local,default,iso,rfc,short,unix,raw}. If --date is
 	not provided, the value of the blame.date config variable is
 	used. If the blame.date config variable is also not set, the
 	iso format is used. For more information, See the discussion
diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index ce3692c..7e1d4bf 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -37,7 +37,7 @@ SYNOPSIS
 	     [ \--regexp-ignore-case | -i ]
 	     [ \--extended-regexp | -E ]
 	     [ \--fixed-strings | -F ]
-	     [ \--date=(local|relative|default|iso|rfc|short|raw) ]
+	     [ \--date=(local|relative|default|iso|rfc|short|unix|raw) ]
 	     [ [\--objects | \--objects-edge] [ \--unpacked ] ]
 	     [ \--pretty | \--header ]
 	     [ \--bisect ]
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index 9c47ad8..9ad68a7 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -13,7 +13,7 @@ include::pretty-options.txt[]
 
 	Synonym for `--date=relative`.
 
---date=(relative|local|default|iso|rfc|short|raw)::
+--date=(relative|local|default|iso|rfc|short|unix|raw)::
 
 	Only takes effect for dates shown in human-readable format, such
 	as when using "--pretty". `log.date` config variable sets a default
@@ -31,6 +31,8 @@ format, often found in E-mail messages.
 +
 `--date=short` shows only date but not time, in `YYYY-MM-DD` format.
 +
+`--date=unix` shows the date as a UNIX timestamp, ignoring timezone.
++
 `--date=raw` shows the date in the internal raw git format `%s %z` format.
 +
 `--date=default` shows timestamps in the original timezone
diff --git a/builtin/blame.c b/builtin/blame.c
index f6b03f7..c6e43a0 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2366,6 +2366,9 @@ parse_done:
 	case DATE_RAW:
 		blame_date_width = sizeof("1161298804 -0700");
 		break;
+	case DATE_UNIX:
+		blame_date_width = sizeof("1161298804");
+		break;
 	case DATE_SHORT:
 		blame_date_width = sizeof("2006-10-19");
 		break;
diff --git a/cache.h b/cache.h
index f2dabef..fa564fa 100644
--- a/cache.h
+++ b/cache.h
@@ -814,7 +814,8 @@ enum date_mode {
 	DATE_LOCAL,
 	DATE_ISO8601,
 	DATE_RFC2822,
-	DATE_RAW
+	DATE_RAW,
+	DATE_UNIX
 };
 
 const char *show_date(unsigned long time, int timezone, enum date_mode mode);
diff --git a/date.c b/date.c
index 00f9eb5..ce48220 100644
--- a/date.c
+++ b/date.c
@@ -157,6 +157,11 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 		return timebuf;
 	}
 
+	if (mode == DATE_UNIX) {
+		snprintf(timebuf, sizeof(timebuf), "%lu", time);
+		return timebuf;
+	}
+
 	if (mode == DATE_RELATIVE) {
 		struct timeval now;
 		gettimeofday(&now, NULL);
@@ -672,6 +677,8 @@ enum date_mode parse_date_format(const char *format)
 		return DATE_NORMAL;
 	else if (!strcmp(format, "raw"))
 		return DATE_RAW;
+	else if (!strcmp(format, "unix"))
+		return DATE_UNIX;
 	else
 		die("unknown date format %s", format);
 }
-- 
1.7.4.2

  parent reply	other threads:[~2011-03-28 23:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28 23:17 [PATCH/RFC 0/9] add long forms for format placeholders Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 1/9] mention --date=raw in rev-list and blame help Will Palmer
2011-03-28 23:17 ` Will Palmer [this message]
2011-03-28 23:17 ` [PATCH/RFC 3/9] interpret %C(invalid) as we would %%C(invalid) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 4/9] add sanity length check to format_person_part Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 5/9] refactor pretty.c into "parse" and "format" steps Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 6/9] add long-form %(wrap:...) for %w(...) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 7/9] add long form %(color:...) for %C(...) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 8/9] add long forms %(authordate) and %(committerdate) Will Palmer
2011-03-28 23:17 ` [PATCH/RFC 9/9] add long forms for author and committer identity Will Palmer
2011-03-29  0:28 ` [PATCH/RFC 0/9] add long forms for format placeholders Junio C Hamano
2011-03-29  6:44   ` Will Palmer
2011-03-29  6:46   ` Michael J Gruber
2011-03-29  7:27     ` Will Palmer

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=1301354251-23380-3-git-send-email-wmpalmer@gmail.com \
    --to=wmpalmer@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).