git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Will Palmer <wmpalmer@gmail.com>
Date
Mar 28, 2011, 23:17 UTC
Message-ID
<1301354251-23380-3-git-send-email-wmpalmer@gmail.com>
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
Previous: Will PalmerNext: Will Palmer
Message 3 of 14 in “add long forms for format placeholders”
  1. 0/9 add long forms for format placeholdersWill Palmer, Mar 28, 2011
  2. 1/9 mention --date=raw in rev-list and blame helpWill Palmer, Mar 28, 2011
  3. 2/9 add support for --date=unix to complement %atWill Palmer, Mar 28, 2011
  4. 3/9 interpret %C(invalid) as we would %%C(invalid)Will Palmer, Mar 28, 2011
  5. 4/9 add sanity length check to format_person_partWill Palmer, Mar 28, 2011
  6. 5/9 refactor pretty.c into "parse" and "format" stepsWill Palmer, Mar 28, 2011
  7. 6/9 add long-form %(wrap:...) for %w(...)Will Palmer, Mar 28, 2011
  8. 7/9 add long form %(color:...) for %C(...)Will Palmer, Mar 28, 2011
  9. 8/9 add long forms %(authordate) and %(committerdate)Will Palmer, Mar 28, 2011
  10. 9/9 add long forms for author and committer identityWill Palmer, Mar 28, 2011
  11. Junio C HamanoMar 29, 2011
  12. Will PalmerMar 29, 2011
  13. Michael J GruberMar 29, 2011
  14. Will PalmerMar 29, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.