git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: eletuchy@gmail.com
To: git@vger.kernel.org
Cc: marius@trolltech.com, Eugene Letuchy <eugene@facebook.com>
Subject: [PATCH] Make git blame date output format configurable, a la git log
Date: Fri, 20 Feb 2009 05:24:12 -0800	[thread overview]
Message-ID: <1235136252-29649-1-git-send-email-eletuchy@gmail.com> (raw)

From: Eugene Letuchy <eugene@facebook.com>

Adds 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-format 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

The tests pass. The mailmap test needed to be modified to expect iso
formatted blames rather than the new "default".

Signed-off-by: Eugene Letuchy <eugene@facebook.com>
---
 Documentation/blame-options.txt |    6 ++++++
 builtin-blame.c                 |   31 ++++++++++++++++++-------------
 t/t4203-mailmap.sh              |    2 +-
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index 1ab1b96..75663ec 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -63,6 +63,12 @@ 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 <format>::
+	The value is one of the following alternatives:
+	{relative,local,default,iso,rfc,short}.  The default format
+	can be set using the blame.date config variable. 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
diff --git a/builtin-blame.c b/builtin-blame.c
index 114a214..9ebab43 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -1,5 +1,5 @@
 /*
- * Pickaxe
+ * Blame / Pickaxe
  *
  * Copyright (c) 2006, Junio C Hamano
  */
@@ -40,6 +40,9 @@ static int reverse;
 static int blank_boundary;
 static int incremental;
 static int xdl_opts = XDF_NEED_MINIMAL;
+
+static enum date_mode date_mode;
+
 static struct string_list mailmap;
 
 #ifndef DEBUG
@@ -1507,9 +1510,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
 			       int show_raw_time)
 {
 	static char time_buf[128];
-	time_t t = time;
-	int minutes, tz;
-	struct tm *tm;
+	int tz;
 
 	if (show_raw_time) {
 		sprintf(time_buf, "%lu %s", time, tz_str);
@@ -1517,15 +1518,7 @@ static const char *format_time(unsigned long time, const char *tz_str,
 	}
 
 	tz = atoi(tz_str);
-	minutes = tz < 0 ? -tz : tz;
-	minutes = (minutes / 100)*60 + (minutes % 100);
-	minutes = tz < 0 ? -minutes : minutes;
-	t = time + minutes * 60;
-	tm = gmtime(&t);
-
-	strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S ", tm);
-	strcat(time_buf, tz_str);
-	return time_buf;
+	return show_date(time, tz, date_mode);
 }
 
 #define OUTPUT_ANNOTATE_COMPAT	001
@@ -1967,6 +1960,8 @@ static void prepare_blame_range(struct scoreboard *sb,
 
 static int git_blame_config(const char *var, const char *value, void *cb)
 {
+	const char *default_date_mode;
+
 	if (!strcmp(var, "blame.showroot")) {
 		show_root = git_config_bool(var, value);
 		return 0;
@@ -1975,6 +1970,11 @@ 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")) {
+		git_config_string(&default_date_mode, var, value);
+		date_mode = parse_date_format(default_date_mode);
+		return 0;
+	}
 	return git_default_config(var, value, cb);
 }
 
@@ -2212,6 +2212,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	static int show_stats = 0;
 	static const char *revs_file = NULL;
 	static const char *contents_from = NULL;
+	static const char *date_format = NULL;
 	static const struct option options[] = {
 		OPT_BOOLEAN(0, "incremental", &incremental, "Show blame entries as we find them, incrementally"),
 		OPT_BOOLEAN('b', NULL, &blank_boundary, "Show blank SHA-1 for boundary commits (Default: off)"),
@@ -2228,6 +2229,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 		OPT_BIT('w', NULL, &xdl_opts, "Ignore whitespace differences", XDF_IGNORE_WHITESPACE),
 		OPT_STRING('S', NULL, &revs_file, "file", "Use revisions from <file> instead of calling git-rev-list"),
 		OPT_STRING(0, "contents", &contents_from, "file", "Use <file>'s contents as the final image"),
+		OPT_STRING(0, "date-format", &date_format, "date mode", "Specify date formatting: relative,local,default,iso,rfc,short. ."),
 		{ OPTION_CALLBACK, 'C', NULL, &opt, "score", "Find line copies within and across files", PARSE_OPT_OPTARG, blame_copy_callback },
 		{ OPTION_CALLBACK, 'M', NULL, &opt, "score", "Find line movements within and across files", PARSE_OPT_OPTARG, blame_move_callback },
 		OPT_CALLBACK('L', NULL, &bottomtop, "n,m", "Process only line range n,m, counting from 1", blame_bottomtop_callback),
@@ -2266,6 +2268,9 @@ parse_done:
 	if (cmd_is_annotate)
 		output_option |= OUTPUT_ANNOTATE_COMPAT;
 
+	if (date_format)
+		date_mode = parse_date_format(date_format);
+
 	if (DIFF_OPT_TST(&revs.diffopt, FIND_COPIES_HARDER))
 		opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
 			PICKAXE_BLAME_COPY_HARDER);
diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 9a7d1b4..13b64dc 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -208,7 +208,7 @@ ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four
 EOF
 
 test_expect_success 'Blame output (complex mapping)' '
-	git blame one >actual &&
+	git blame --date-format=iso one >actual &&
 	test_cmp expect actual
 '
 
-- 
1.6.2.rc1.14.g397c24.dirty

             reply	other threads:[~2009-02-20 13:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-20 13:24 eletuchy [this message]
2009-02-20 13:40 ` [PATCH] Make git blame date output format configurable, a la git log Johannes Schindelin
2009-02-20 13:55   ` Eugene Letuchy
2009-02-20 13:57     ` Eugene Letuchy
2009-02-20 14:06     ` Johannes Schindelin
2009-02-20 14:27 ` Jeff King
2009-02-20 16:13   ` Eugene Letuchy
2009-02-20 17:18     ` Jeff King
2009-02-20 16:59 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1235136252-29649-1-git-send-email-eletuchy@gmail.com \
    --to=eletuchy@gmail.com \
    --cc=eugene@facebook.com \
    --cc=git@vger.kernel.org \
    --cc=marius@trolltech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).