Skip to contentSkip to conversation

Make git blame's date output format configurable, like git log

PATCH In review [email protected] 3 participants 6 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Make git blame's date output format configurable, like git log

From: Eugene Letuchy <[email protected]>

Add the following:
- git config value blame.date that expects one of the git log date formats ({relative,local,default,iso,rfc,short})
- git blame command line option --date expects one of the git log date formats ({relative,local,default,iso,rfc,short})
- documentation in blame-options.txt
- git blame uses the appropriate date.c functions and enums to make sense of the date format and provide appropriate data
- git blame continues to line up the output columns (by padding the date column up to the max width of the chosen date format)
- the date format for git blame without both blame.date and --date continues to be ISO for backwards compatibility
- git annotate ignores the date format specifiers and continues to uses the ISO format, as before

---
 Documentation/blame-options.txt |    8 +++++
 builtin-blame.c                 |   62 +++++++++++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 16 deletions(-)
Documentation/blame-options.txt +8 -0
index 1ab1b96..ad00d36 100644
@@ -63,6 +63,14 @@ of lines before or after the line given by <start>.
 	tree copy has the contents of the named file (specify
 	`-` to make the command read from the standard input).
 
+--date <format>::
+	The value is one of the following alternatives:
+	{relative,local,default,iso,rfc,short}. 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
+	of the --date option at linkgit:git-log[1].
+
 -M|<num>|::
 	Detect moving lines in the file as well.  When a commit
 	moves a block of lines in a file (e.g. the original file
builtin-blame.c +46 -16

101 lines not on this page · raw message

Signature · 1 line
1.6.2.rc1.14.g07c3.dirty
#2 lore raw
In reply to [email protected]

builtin-blame.c static int git_blame_config(const char *var, const char *value, void *cb) · line 1982

Quoted 9 lines · On Fri, Feb 20, 2009 at 02:51:11PM -0800, [email protected] wrote:
builtin-blame.c +3 -0
@@ -1975,6 +1975,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
 		blank_boundary = git_config_bool(var, value);
 		return 0;
 	}
+	if (!strcmp(var, "blame.date") && value[0]) {
+		blame_date_mode = parse_date_format(value);
+	}
 	return git_default_config(var, value, cb);
 }

When there is a config value we are expecting to have a value rather than a boolean, we usually print an error rather than silently discarding. IOW, something like this:

  if (!strcmp(var, "blame.date")) {
          if (!value)
                  return config_error_nonbool(var);
          blame_date_mode = parse_date_format(value);
  }
Quoted 10 lines
builtin-blame.c +10 -0
+	switch (blame_date_mode) {
+	case DATE_RFC2822:
+		blame_date_width = sizeof("Thu, 19 Oct 2006 16:00:04 -0700");
+		break;
+	case DATE_ISO8601:
+		blame_date_width = sizeof("2006-10-19 16:00:04 -0700");
+		break;
+	case DATE_SHORT:
+		blame_date_width = sizeof("2006-10-19");
+		break;

builtin-blame.c int cmd_blame(int argc, const char **argv, const char *prefix) · line 2297

Quoted 10 lines
builtin-blame.c +10 -0
+	case DATE_RELATIVE:
+		/* unfortunately "normal" is the fallback for "relative" */
+		/* blame_date_width = sizeof("14 minutes ago"); */
+		/* break; */
+	case DATE_LOCAL:
+	case DATE_NORMAL:
+		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
+		break;
+	}
+	blame_date_width -= 1; /* strip the null */

Maybe this should be a date_format_width() library function?

Other than that, the patch looks reasonable to me.

-Peff

#3 lore raw
Quoted 15 lines · Jeff King

builtin-blame.c static int git_blame_config(const char *var, const char *value, void *cb) · line 1982

Quoted 9 lines · On Fri, Feb 20, 2009 at 02:51:11PM -0800, [email protected] wrote:
builtin-blame.c +3 -0
@@ -1975,6 +1975,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
 		blank_boundary = git_config_bool(var, value);
 		return 0;
 	}
+	if (!strcmp(var, "blame.date") && value[0]) {
+		blame_date_mode = parse_date_format(value);
+	}
 	return git_default_config(var, value, cb);
 }

When there is a config value we are expecting to have a value rather than a boolean, we usually print an error rather than silently discarding.

Oops, missed that. Yes, this needs fixing.

Thanks.

#4 lore raw
In reply to Jeff King
Quoted 16 lines · Jeff King

builtin-blame.c static int git_blame_config(const char *var, const char *value, void *cb) · line 1982

Quoted 9 lines · On Fri, Feb 20, 2009 at 02:51:11PM -0800, [email protected] wrote:
builtin-blame.c +3 -0
@@ -1975,6 +1975,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)
              blank_boundary = git_config_bool(var, value);
              return 0;
      }
+     if (!strcmp(var, "blame.date") && value[0]) {
+             blame_date_mode = parse_date_format(value);
+     }
      return git_default_config(var, value, cb);
 }

When there is a config value we are expecting to have a value rather than a boolean, we usually print an error rather than silently discarding. IOW, something like this:

Quoted 6 lines
 if (!strcmp(var, "blame.date")) {
         if (!value)
                 return config_error_nonbool(var);
         blame_date_mode = parse_date_format(value);

}

I'll make that change to the patch.

Quoted 21 lines
Quoted 10 lines
builtin-blame.c +10 -0
+     switch (blame_date_mode) {
+     case DATE_RFC2822:
+             blame_date_width = sizeof("Thu, 19 Oct 2006 16:00:04 -0700");
+             break;
+     case DATE_ISO8601:
+             blame_date_width = sizeof("2006-10-19 16:00:04 -0700");
+             break;
+     case DATE_SHORT:
+             blame_date_width = sizeof("2006-10-19");
+             break;

builtin-blame.c int cmd_blame(int argc, const char **argv, const char *prefix) · line 2297

Quoted 10 lines
builtin-blame.c +10 -0
+     case DATE_RELATIVE:
+             /* unfortunately "normal" is the fallback for "relative" */
+             /* blame_date_width = sizeof("14 minutes ago"); */
+             /* break; */
+     case DATE_LOCAL:
+     case DATE_NORMAL:
+             blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
+             break;
+     }
+     blame_date_width -= 1; /* strip the null */
Quoted 2 lines

Maybe this should be a date_format_width() library function?

I think that's a possible change, but unfortunately my next two patches would not apply cleanly with a date_format_width change.

I'm a n00b with respect to git contribution, but is there a procedure for pushing my blame_date branch remotely so that it's possible to track a series of patches?

Quoted 5 lines

Other than that, the patch looks reasonable to me.

-Peff

Signature · 1 line
Eugene
#5 lore raw
Quoted 8 lines · Eugene Letuchy
Quoted 1 line

Maybe this should be a date_format_width() library function?

I think that's a possible change, but unfortunately my next two patches would not apply cleanly with a date_format_width change.

I'm a n00b with respect to git contribution, but is there a procedure for pushing my blame_date branch remotely so that it's possible to track a series of patches?

Updating previous work depends on whether it has been picked up in 'next' by Junio; once patches are there, they cannot be rewritten. In that case, you can send a follow-up patch.

In your case, though, the patch is still in 'pu', so you can repost. So I think it makes sense to use "rebase -i" (or the tool of your choice) to make a cleaned up series, and then repost the whole thing as a series.

-Peff