{"thread":{"id":"17924","subject":"[PATCH 1/2] Make git blame's date output format configurable, like git log","startedAt":"2009-02-20T21:23:07Z","lastAt":"2009-02-20T21:23:08Z","messageCount":2,"participants":["eletuchy@gmail.com"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"105655","messageId":"1235164988-19761-1-git-send-email-eletuchy@gmail.com","threadId":"17924","inReplyTo":null,"subject":"[PATCH] Make git blame date output format configurable, a la git log (take 2)","fromName":"","fromEmail":"eletuchy@gmail.com","sentAt":"2009-02-20T21:23:07Z","receivedAt":"2009-02-20T21:23:07Z","isPatch":true,"sender":{"key":"eletuchy@gmail.com","avatar":null},"body":"\nThis version of the patch incorporates Junio's and Peff's suggestions ... doesn't change the default format and gets rid of alignment bugs.\n"},{"id":"105653","messageId":"1235164988-19761-2-git-send-email-eletuchy@gmail.com","threadId":"17924","inReplyTo":"1235164988-19761-1-git-send-email-eletuchy@gmail.com","subject":"[PATCH 1/2] Make git blame's date output format configurable, like git log","fromName":"","fromEmail":"eletuchy@gmail.com","sentAt":"2009-02-20T21:23:08Z","receivedAt":"2009-02-20T21:23:08Z","isPatch":true,"sender":{"key":"eletuchy@gmail.com","avatar":null},"body":"From: Eugene Letuchy <eugene@facebook.com>\n\nAdd the following:\n - git config value blame.date that expects one of the git log date\n   formats ({relative,local,default,iso,rfc,short})\n - git blame command line option --date expects one of the git\n   log date formats ({relative,local,default,iso,rfc,short})\n - documentation in blame-options.txt\n - git blame uses the appropriate date.c functions and enums to\n   make sense of the date format and provide appropriate data\n - git blame continues to line up the output columns (by padding the\n   date column up to the max width of the chosen date format)\n - the date format for git blame without both blame.date and --date\n   continues to be ISO for backwards compatibility\n - git annotate ignores the date format specifiers and continues to\n   uses the ISO format, as before\n\nSigned-off-by: Eugene Letuchy <eugene@facebook.com>\n---\n Documentation/blame-options.txt |    8 +++++\n builtin-blame.c                 |   62 +++++++++++++++++++++++++++++----------\n 2 files changed, 54 insertions(+), 16 deletions(-)\n\ndiff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt\nindex 1ab1b96..ad00d36 100644\n--- a/Documentation/blame-options.txt\n+++ b/Documentation/blame-options.txt\n@@ -63,6 +63,14 @@ of lines before or after the line given by <start>.\n \ttree copy has the contents of the named file (specify\n \t`-` to make the command read from the standard input).\n \n+--date <format>::\n+\tThe value is one of the following alternatives:\n+\t{relative,local,default,iso,rfc,short}. If --date is not\n+\tprovided, the value of the blame.date config variable is\n+\tused. If the blame.date config variable is also not set, the\n+\tiso format is used. For more information, See the discussion\n+\tof the --date option at linkgit:git-log[1].\n+\n -M|<num>|::\n \tDetect moving lines in the file as well.  When a commit\n \tmoves a block of lines in a file (e.g. the original file\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 114a214..aa5c66c 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -1,5 +1,5 @@\n /*\n- * Pickaxe\n+ * Blame\n  *\n  * Copyright (c) 2006, Junio C Hamano\n  */\n@@ -40,6 +40,10 @@ static int reverse;\n static int blank_boundary;\n static int incremental;\n static int xdl_opts = XDF_NEED_MINIMAL;\n+\n+static enum date_mode blame_date_mode = DATE_ISO8601;\n+static size_t blame_date_width;\n+\n static struct string_list mailmap;\n \n #ifndef DEBUG\n@@ -1507,24 +1511,20 @@ static const char *format_time(unsigned long time, const char *tz_str,\n \t\t\t       int show_raw_time)\n {\n \tstatic char time_buf[128];\n-\ttime_t t = time;\n-\tint minutes, tz;\n-\tstruct tm *tm;\n+\tconst char *time_str;\n+\tint time_len;\n+\tint tz;\n \n \tif (show_raw_time) {\n \t\tsprintf(time_buf, \"%lu %s\", time, tz_str);\n-\t\treturn time_buf;\n \t}\n-\n-\ttz = atoi(tz_str);\n-\tminutes = tz < 0 ? -tz : tz;\n-\tminutes = (minutes / 100)*60 + (minutes % 100);\n-\tminutes = tz < 0 ? -minutes : minutes;\n-\tt = time + minutes * 60;\n-\ttm = gmtime(&t);\n-\n-\tstrftime(time_buf, sizeof(time_buf), \"%Y-%m-%d %H:%M:%S \", tm);\n-\tstrcat(time_buf, tz_str);\n+\telse {\n+\t\ttz = atoi(tz_str);\n+\t\ttime_str = show_date(time, tz, blame_date_mode);\n+\t\ttime_len = strlen(time_str);\n+\t\tmemcpy(time_buf, time_str, time_len);\n+\t\tmemset(time_buf + time_len, ' ', blame_date_width - time_len);\n+\t}\n \treturn time_buf;\n }\n \n@@ -1975,6 +1975,9 @@ static int git_blame_config(const char *var, const char *value, void *cb)\n \t\tblank_boundary = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"blame.date\") && value[0]) {\n+\t\tblame_date_mode = parse_date_format(value);\n+\t}\n \treturn git_default_config(var, value, cb);\n }\n \n@@ -2239,6 +2242,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \n \tgit_config(git_blame_config, NULL);\n \tinit_revisions(&revs, NULL);\n+\trevs.date_mode = blame_date_mode;\n+\n \tsave_commit_buffer = 0;\n \tdashdash_pos = 0;\n \n@@ -2263,8 +2268,33 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n parse_done:\n \targc = parse_options_end(&ctx);\n \n-\tif (cmd_is_annotate)\n+\tif (cmd_is_annotate) {\n \t\toutput_option |= OUTPUT_ANNOTATE_COMPAT;\n+\t\tblame_date_mode = DATE_ISO8601;\n+\t} else {\n+\t\tblame_date_mode = revs.date_mode;\n+\t}\n+\n+\tswitch (blame_date_mode) {\n+\tcase DATE_RFC2822:\n+\t\tblame_date_width = sizeof(\"Thu, 19 Oct 2006 16:00:04 -0700\");\n+\t\tbreak;\n+\tcase DATE_ISO8601:\n+\t\tblame_date_width = sizeof(\"2006-10-19 16:00:04 -0700\");\n+\t\tbreak;\n+\tcase DATE_SHORT:\n+\t\tblame_date_width = sizeof(\"2006-10-19\");\n+\t\tbreak;\n+\tcase DATE_RELATIVE:\n+\t\t/* unfortunately \"normal\" is the fallback for \"relative\" */\n+\t\t/* blame_date_width = sizeof(\"14 minutes ago\"); */\n+\t\t/* break; */\n+\tcase DATE_LOCAL:\n+\tcase DATE_NORMAL:\n+\t\tblame_date_width = sizeof(\"Thu Oct 19 16:00:04 2006 -0700\");\n+\t\tbreak;\n+\t}\n+\tblame_date_width -= 1; /* strip the null */\n \n \tif (DIFF_OPT_TST(&revs.diffopt, FIND_COPIES_HARDER))\n \t\topt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |\n-- \n1.6.2.rc1.14.g07c3.dirty\n"}]}