[PATCH/RFC 2/9] add support for --date=unix to complement %at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]