Skip to contentSkip to conversation

--format=pretty: new modifiers cID, cIS, CIY

PATCH In review Jari Aalto 3 participants 7 messages Jun 15, 2016 Documentation

lore
Share & tools
lore

Jari Aalto

author
#0 lore raw

PATCH 1/1 --format=pretty: new modifiers cID, cIS, CIY

The default ISO 8601 modifier %ci is quite verbose displaying everything up to the timezone. This consumes considerable amount of characters. The new modifiers offer way to display just the needed amount of information, down to:

%cID date: YYYY-MM-DD
%cIH hour: YYYY-MM-DD HH:MM
%cIS second: YYYY-MM-DD HH:MM:SS

Signed-off-by Jari Aalto <jari.aalto AT cante.net>
---
 Documentation/pretty-formats.txt |    5 ++++-
 cache.h                          |    3 +++
 date.c                           |   17 +++++++++++++++++
 pretty.c                         |   35 ++++++++++++++++++++++++++++++-----
 4 files changed, 54 insertions(+), 6 deletions(-)
Documentation/pretty-formats.txt +4 -1
index 0193c3c..cb1bbac 100644
@@ -113,7 +113,10 @@ The placeholders are:
 - '%cD': committer date, RFC2822 style
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
-- '%ci': committer date, ISO 8601 format
+- '%ci': committer date, ISO 8601 format, long YYYY-MM-DD HH:MM:SS TZ
+- '%cIM': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM
+- '%cIS': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM:SS
+- '%cID': committer date, ISO 8601 format, short YYYY-MM-DD
 - '%e': encoding
 - '%s': subject
 - '%b': body
cache.h +3 -0
index 549f4bb..1fae94a 100644
@@ -444,6 +444,9 @@ enum date_mode {
 	DATE_SHORT,
 	DATE_LOCAL,
 	DATE_ISO8601,
+	DATE_ISO8601_YYYYMMDD,
+	DATE_ISO8601_YYYYMMDDHHMM,
+	DATE_ISO8601_YYYYMMDDHHMMSS,
 	DATE_RFC2822
 };
 
date.c +17 -0
index 8f70500..ded9caa 100644
@@ -144,6 +144,23 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tz);
+	else if (mode == DATE_ISO8601_YYYYMMDD)
+		sprintf(timebuf, "%04d-%02d-%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMM)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMMSS)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min, tm->tm_sec);
 	else if (mode == DATE_RFC2822)
 		sprintf(timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
 			weekday_names[tm->tm_wday], tm->tm_mday,
pretty.c +30 -5
index b987ff2..5a8774b 100644
@@ -282,9 +282,11 @@ static char *logmsg_reencode(const struct commit *commit,
 	return out;
 }
 
-static void format_person_part(struct strbuf *sb, char part,
-                               const char *msg, int len)
+static void format_person_part(struct strbuf *sb, char *ptr,
+			       const char *msg, int len)
 {
+	char part = ptr[0];
+	char next = ptr[1];
 	int start, end, tz = 0;
 	unsigned long date;
 	char *ep;
@@ -359,6 +361,26 @@ static void format_person_part(struct strbuf *sb, char part,
 	case 'i':	/* date, ISO 8601 */
 		strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
 		return;
+	case 'I':	/* date, ISO 8601 + fine grained details */
+		switch (next) {
+		case 'D':	/* up till date */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDD));
+			return;
+		case 'S':	/* up till date + sec */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMMSS));
+
+			return;
+		default:	/* up till hour */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMM));
+
+		}
+		return;
 	}
 }
 
@@ -532,11 +554,11 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
 		strbuf_add(sb, msg + c->subject.off, c->subject.len);
 		return;
 	case 'a':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->author.off, c->author.len);
 		return;
 	case 'c':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->committer.off, c->committer.len);
 		return;
 	case 'e':
@@ -571,7 +593,10 @@ void format_commit_message(const struct commit *commit,
 		"cD",		/* committer date, RFC2822 style */
 		"cr",		/* committer date, relative */
 		"ct",		/* committer date, UNIX timestamp */
-		"ci",		/* committer date, ISO 8601 */
+		"ci",		/* committer date, ISO 8601 full, with TZ */
+		"cID",		/* committer date, ISO 8601 YYYY-MM-DD */
+		"cIM",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM */
+		"cIS",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM:SS*/
 		"e",		/* encoding */
 		"s",		/* subject */
 		"b",		/* body */
Signature · 5 lines
1.5.4-rc5.GIT-dirty


-- 
Welcome to FOSS revolution: we fix and modify until it shines
#1 lore raw
Quoted 10 lines · Jari Aalto
pretty.c +10 -0
+	case 'I':	/* date, ISO 8601 + fine grained details */
+		switch (next) {
+		case 'D':	/* up till date */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDD));
+			return;
+		case 'S':	/* up till date + sec */
+			strbuf_addstr(sb,
+					show_date(date, tz,

pretty.c static void format_person_part(struct strbuf *sb, char part, · line 383

Quoted 10 lines
pretty.c +10 -0
+						DATE_ISO8601_YYYYMMDDHHMMSS));
+
+			return;
+		default:	/* up till hour */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMM));
+
+		}
+		return;

I think this "default" is not quite nice. If you want to support down-to-hour, you'd beter explicitly support 'H'. "default:" should error out, saying "Ah, oh, sorry, I do not support %cIX (yet)".

Otherwise, it casts the set of truncated ISO 8601 date format we supports in stone. People would depend on being able to say "%cIhour" and a new implementation cannot introduce %cIh modifier that means something.

But I do not like the idea of adding more short-hand format this way. I think we would very much prefer, instead of piling hacks on top of the originally supported "minimum set", to introduce a truly extensible syntax, like:

%cT(flexible formatting specification for committer time)

or even

%c(flexible formatting specification for committer info)

and that specification may say which field to format with what prettiness. For example:

	%c(name|initial) %c(time|local,HH:MM) %c(time|gmt,HH) <%c(email)>

might say:

	JCH 15:00 23 <[email protected]>

(23 is because US/Pacific is 8 hours behind right now).

Of course, %a(likewise for author time) can be defined the same way.

author
#2 lore raw

* Fri 2008-02-01 Junio C Hamano <[email protected]>

Quoted 2 lines

But I do not like the idea of adding more short-hand format this way.

I'd welcome if this mimimum set of ISO date handling woudl be included, because I feel they address the needs more versatily than the current %ci, which is too long with down to TZ.

I find it that the YYY-MM-DD HH:MM meets the needs 99% of the case, like in ls(1) listing when the LC_* is properly configured.

[extensible syntax]

Quoted 1 line
	%c(name|initial) %c(time|local,HH:MM) %c(time|gmt,HH) <%c(email)>

This would be good. In the mean time, when we wait for this feature to surface, the current patch would address immediate needs.

Jari

Signature · 1 line
Welcome to FOSS revolution: we fix and modify until it shines
#3 lore raw
In reply to Junio C Hamano

[resent, sorry]

Quoted 4 lines · --- Junio C Hamano

I think we would very much prefer, instead of
piling hacks on top of the originally supported
"minimum set", to introduce a truly extensible
syntax, like:

I concur, but pretty-please make it a super set of date(1) to the extent possible. It will lessen the confusion.

Maybe something like "%c(%Y-%m-%d %H:%M) ...", eg. such
that if `date +<format>' is legal, so is "%c(<format>)".

Tommy

      ____________________________________________________________________________________

Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping

#4 lore raw
Quoted 8 lines · Tommy Thorn

[resent, sorry]

Quoted 4 lines · --- Junio C Hamano

I think we would very much prefer, instead of
piling hacks on top of the originally supported
"minimum set", to introduce a truly extensible
syntax, like:

Quoted 8 lines

I concur, but pretty-please make it a super set of date(1) to the extent possible. It will lessen the confusion.

Maybe something like "%c(%Y-%m-%d %H:%M) ...", eg. such
that if `date +<format>' is legal, so is "%c(<format>)".

Please read what you are replying to again. If you said the above with %cT(...), it might have made some sense (but then how are you differentiate between local and original timezone?), but %c(...) needs to show not just the timestamp.

author
#5 lore raw

PATCH 1/1 --format=pretty: new modifiers cID, cIS, CIY

In reply to Junio C Hamano

The default ISO 8601 modifier %ci is quite verbose displaying everything up to the timezone. This consumes considerable amount of characters. The new modifiers offer way to display just the needed amount of information, down to:

        %cID    date: YYYY-MM-DD
        %cIM    hour: YYYY-MM-DD HH:MM
        %cIS    second: YYYY-MM-DD HH:MM:SS
Signed-off-by Jari Aalto <jari.aalto AT cante.net>

---

Quoted 4 lines

I think this "default" is not quite nice. If you want to support down-to-hour, you'd beter explicitly support 'H'. "default:" should error out, saying "Ah, oh, sorry, I do not support %cIX (yet)".

Here is correction and better 'case::default'.

Jari

 Documentation/pretty-formats.txt |    5 ++++-
 cache.h                          |    3 +++
 date.c                           |   17 +++++++++++++++++
 pretty.c                         |   36 +++++++++++++++++++++++++++++++-----
 4 files changed, 55 insertions(+), 6 deletions(-)
Documentation/pretty-formats.txt +4 -1
index 0193c3c..cb1bbac 100644
@@ -113,7 +113,10 @@ The placeholders are:
 - '%cD': committer date, RFC2822 style
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
-- '%ci': committer date, ISO 8601 format
+- '%ci': committer date, ISO 8601 format, long YYYY-MM-DD HH:MM:SS TZ
+- '%cIM': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM
+- '%cIS': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM:SS
+- '%cID': committer date, ISO 8601 format, short YYYY-MM-DD
 - '%e': encoding
 - '%s': subject
 - '%b': body
cache.h +3 -0
index 549f4bb..1fae94a 100644
@@ -444,6 +444,9 @@ enum date_mode {
 	DATE_SHORT,
 	DATE_LOCAL,
 	DATE_ISO8601,
+	DATE_ISO8601_YYYYMMDD,
+	DATE_ISO8601_YYYYMMDDHHMM,
+	DATE_ISO8601_YYYYMMDDHHMMSS,
 	DATE_RFC2822
 };
 
date.c +17 -0
index 8f70500..ded9caa 100644
@@ -144,6 +144,23 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tz);
+	else if (mode == DATE_ISO8601_YYYYMMDD)
+		sprintf(timebuf, "%04d-%02d-%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMM)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMMSS)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min, tm->tm_sec);
 	else if (mode == DATE_RFC2822)
 		sprintf(timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
 			weekday_names[tm->tm_wday], tm->tm_mday,
pretty.c +31 -5
index b987ff2..778faf4 100644
@@ -282,9 +282,11 @@ static char *logmsg_reencode(const struct commit *commit,
 	return out;
 }
 
-static void format_person_part(struct strbuf *sb, char part,
-                               const char *msg, int len)
+static void format_person_part(struct strbuf *sb, char *ptr,
+			       const char *msg, int len)
 {
+	char part = ptr[0];
+	char next = ptr[1];
 	int start, end, tz = 0;
 	unsigned long date;
 	char *ep;
@@ -359,6 +361,27 @@ static void format_person_part(struct strbuf *sb, char part,
 	case 'i':	/* date, ISO 8601 */
 		strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
 		return;
+	case 'I':	/* date, ISO 8601 + fine grained details */
+		switch (next) {
+		case 'D':	/* up till date */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDD));
+		case 'H':	/* up till hour */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMM));
+		case 'S':	/* up till date + sec */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMMSS));
+
+		default:	/* up till hour */
+			fprintf(stderr, "Error, uknown %%cI%c modifier",
+				next);
+
+		}
+		return;
 	}
 }
 
@@ -532,11 +555,11 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
 		strbuf_add(sb, msg + c->subject.off, c->subject.len);
 		return;
 	case 'a':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->author.off, c->author.len);
 		return;
 	case 'c':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->committer.off, c->committer.len);
 		return;
 	case 'e':
@@ -571,7 +594,10 @@ void format_commit_message(const struct commit *commit,
 		"cD",		/* committer date, RFC2822 style */
 		"cr",		/* committer date, relative */
 		"ct",		/* committer date, UNIX timestamp */
-		"ci",		/* committer date, ISO 8601 */
+		"ci",		/* committer date, ISO 8601 full, with TZ */
+		"cID",		/* committer date, ISO 8601 YYYY-MM-DD */
+		"cIM",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM */
+		"cIS",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM:SS*/
 		"e",		/* encoding */
 		"s",		/* subject */
 		"b",		/* body */
Signature · 1 line
1.5.4-rc5.GIT-dirty
author
#6 lore raw

PATCH 1/1 --format=pretty: new modifiers cID, cIM, CIS

In reply to Jari Aalto

The default ISO 8601 modifier %ci is quite verbose displaying everything up to the timezone. This consumes considerable amount of characters. The new modifiers offer way to display just the needed amount of information, down to:

        %cID    date: YYYY-MM-DD
        %cIM    hour: YYYY-MM-DD HH:MM
        %cIS    second: YYYY-MM-DD HH:MM:SS
Signed-off-by Jari Aalto <jari.aalto AT cante.net>

---

******************************************************
THIS IS SAME PATCH- ONLY COMMIT MESSAGE HAS BEEN FIXED TO SYNCH WITH THE CONTENT
******************************************************

 Documentation/pretty-formats.txt |    5 ++++-
 cache.h                          |    3 +++
 date.c                           |   17 +++++++++++++++++
 pretty.c                         |   35 ++++++++++++++++++++++++++++++-----
 4 files changed, 54 insertions(+), 6 deletions(-)
Documentation/pretty-formats.txt +4 -1
index 0193c3c..cb1bbac 100644
@@ -113,7 +113,10 @@ The placeholders are:
 - '%cD': committer date, RFC2822 style
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
-- '%ci': committer date, ISO 8601 format
+- '%ci': committer date, ISO 8601 format, long YYYY-MM-DD HH:MM:SS TZ
+- '%cIM': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM
+- '%cIS': committer date, ISO 8601 format, short YYYY-MM-DD HH:MM:SS
+- '%cID': committer date, ISO 8601 format, short YYYY-MM-DD
 - '%e': encoding
 - '%s': subject
 - '%b': body
cache.h +3 -0
index 549f4bb..1fae94a 100644
@@ -444,6 +444,9 @@ enum date_mode {
 	DATE_SHORT,
 	DATE_LOCAL,
 	DATE_ISO8601,
+	DATE_ISO8601_YYYYMMDD,
+	DATE_ISO8601_YYYYMMDDHHMM,
+	DATE_ISO8601_YYYYMMDDHHMMSS,
 	DATE_RFC2822
 };
 
date.c +17 -0
index 8f70500..ded9caa 100644
@@ -144,6 +144,23 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 				tm->tm_mday,
 				tm->tm_hour, tm->tm_min, tm->tm_sec,
 				tz);
+	else if (mode == DATE_ISO8601_YYYYMMDD)
+		sprintf(timebuf, "%04d-%02d-%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMM)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min);
+	else if (mode == DATE_ISO8601_YYYYMMDDHHMMSS)
+		sprintf(timebuf, "%04d-%02d-%02d %02d:%02d:%02d",
+				tm->tm_year + 1900,
+				tm->tm_mon + 1,
+				tm->tm_mday,
+				tm->tm_hour, tm->tm_min, tm->tm_sec);
 	else if (mode == DATE_RFC2822)
 		sprintf(timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
 			weekday_names[tm->tm_wday], tm->tm_mday,
pretty.c +30 -5
index b987ff2..5a8774b 100644
@@ -282,9 +282,11 @@ static char *logmsg_reencode(const struct commit *commit,
 	return out;
 }
 
-static void format_person_part(struct strbuf *sb, char part,
-                               const char *msg, int len)
+static void format_person_part(struct strbuf *sb, char *ptr,
+			       const char *msg, int len)
 {
+	char part = ptr[0];
+	char next = ptr[1];
 	int start, end, tz = 0;
 	unsigned long date;
 	char *ep;
@@ -359,6 +361,26 @@ static void format_person_part(struct strbuf *sb, char part,
 	case 'i':	/* date, ISO 8601 */
 		strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
 		return;
+	case 'I':	/* date, ISO 8601 + fine grained details */
+		switch (next) {
+		case 'D':	/* up till date */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDD));
+			return;
+		case 'S':	/* up till date + sec */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMMSS));
+
+			return;
+		default:	/* up till hour */
+			strbuf_addstr(sb,
+					show_date(date, tz,
+						DATE_ISO8601_YYYYMMDDHHMM));
+
+		}
+		return;
 	}
 }
 
@@ -532,11 +554,11 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
 		strbuf_add(sb, msg + c->subject.off, c->subject.len);
 		return;
 	case 'a':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->author.off, c->author.len);
 		return;
 	case 'c':
-		format_person_part(sb, placeholder[1],
+		format_person_part(sb, placeholder + 1,
 		                   msg + c->committer.off, c->committer.len);
 		return;
 	case 'e':
@@ -571,7 +593,10 @@ void format_commit_message(const struct commit *commit,
 		"cD",		/* committer date, RFC2822 style */
 		"cr",		/* committer date, relative */
 		"ct",		/* committer date, UNIX timestamp */
-		"ci",		/* committer date, ISO 8601 */
+		"ci",		/* committer date, ISO 8601 full, with TZ */
+		"cID",		/* committer date, ISO 8601 YYYY-MM-DD */
+		"cIM",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM */
+		"cIS",		/* committer date, ISO 8601 YYYY-MM-DD HH:MM:SS*/
 		"e",		/* encoding */
 		"s",		/* subject */
 		"b",		/* body */
Signature · 1 line
1.5.4-rc5.GIT-dirty