git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blame: draft of line format
@ 2017-01-31  2:28 Edmundo Carmona Antoranz
  2017-01-31  2:34 ` Edmundo Carmona Antoranz
  2017-01-31 19:41 ` Jeff King
  0 siblings, 2 replies; 4+ messages in thread
From: Edmundo Carmona Antoranz @ 2017-01-31  2:28 UTC (permalink / raw)
  To: git; +Cc: Edmundo Carmona Antoranz

---
 builtin/blame.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/builtin/blame.c b/builtin/blame.c
index 126b8c9e5..89c1a862d 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -52,6 +52,7 @@ static int xdl_opts;
 static int abbrev = -1;
 static int no_whole_file_rename;
 static int show_progress;
+static char *format_line;
 
 static struct date_mode blame_date_mode = { DATE_ISO8601 };
 static size_t blame_date_width;
@@ -1931,6 +1932,19 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
 		putchar('\n');
 }
 
+static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)
+{
+	struct pretty_print_context ctx = {0};
+	struct rev_info rev;
+
+	struct strbuf format = STRBUF_INIT;
+	strbuf_addstr(&format, format_line);
+	ctx.fmt = CMIT_FMT_USERFORMAT;
+	get_commit_format(format.buf, &rev);
+	pretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);
+	strbuf_release(&format);
+}
+
 static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 {
 	int cnt;
@@ -1939,11 +1953,15 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 	struct commit_info ci;
 	char hex[GIT_SHA1_HEXSZ + 1];
 	int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
+	struct strbuf line_revision_buf = STRBUF_INIT;
 
 	get_commit_info(suspect->commit, &ci, 1);
 	sha1_to_hex_r(hex, suspect->commit->object.oid.hash);
 
 	cp = nth_line(sb, ent->lno);
+
+	if (format_line)
+		pretty_info(hex, ent, &line_revision_buf);
 	for (cnt = 0; cnt < ent->num_lines; cnt++) {
 		char ch;
 		int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;
@@ -1968,6 +1986,10 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 			       format_time(ci.author_time, ci.author_tz.buf,
 					   show_raw_time),
 			       ent->lno + 1 + cnt);
+		} else if (format_line) {
+			printf("%s", line_revision_buf.buf);
+			printf(" %*d) ",
+			       max_digits, ent->lno + 1 + cnt);
 		} else {
 			if (opt & OUTPUT_SHOW_SCORE)
 				printf(" %*d %02d",
@@ -2007,6 +2029,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 	if (sb->final_buf_size && cp[-1] != '\n')
 		putchar('\n');
 
+	strbuf_release(&line_revision_buf);
 	commit_info_destroy(&ci);
 }
 
@@ -2605,6 +2628,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
 		OPT_BIT(0, "minimal", &xdl_opts, N_("Spend extra cycles to find better match"), XDF_NEED_MINIMAL),
 		OPT_STRING('S', NULL, &revs_file, N_("file"), N_("Use revisions from <file> instead of calling git-rev-list")),
+		OPT_STRING(0, "format-line", &format_line, N_("format-line"), N_("Use pretty format for revisions")),
 		OPT_STRING(0, "contents", &contents_from, N_("file"), N_("Use <file>'s contents as the final image")),
 		{ OPTION_CALLBACK, 'C', NULL, &opt, N_("score"), N_("Find line copies within and across files"), PARSE_OPT_OPTARG, blame_copy_callback },
 		{ OPTION_CALLBACK, 'M', NULL, &opt, N_("score"), N_("Find line movements within and across files"), PARSE_OPT_OPTARG, blame_move_callback },
-- 
2.11.0.rc1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] blame: draft of line format
  2017-01-31  2:28 [PATCH] blame: draft of line format Edmundo Carmona Antoranz
@ 2017-01-31  2:34 ` Edmundo Carmona Antoranz
  2017-01-31 19:41 ` Jeff King
  1 sibling, 0 replies; 4+ messages in thread
From: Edmundo Carmona Antoranz @ 2017-01-31  2:34 UTC (permalink / raw)
  To: Git List, Jeff King, pranit.bauva; +Cc: Edmundo Carmona Antoranz

I'm basing in on the "pretty API" so that we don't have to reinvent
the wheel. I have already noticed that many of the formatting options
available for pretty are not working... I'm sure it would require some
work setting up the call to pretty api but the basic is laid out
there.

Let me know of your thoughts.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] blame: draft of line format
  2017-01-31  2:28 [PATCH] blame: draft of line format Edmundo Carmona Antoranz
  2017-01-31  2:34 ` Edmundo Carmona Antoranz
@ 2017-01-31 19:41 ` Jeff King
  2017-03-06 23:29   ` Edmundo Carmona Antoranz
  1 sibling, 1 reply; 4+ messages in thread
From: Jeff King @ 2017-01-31 19:41 UTC (permalink / raw)
  To: Edmundo Carmona Antoranz; +Cc: git

On Mon, Jan 30, 2017 at 08:28:30PM -0600, Edmundo Carmona Antoranz wrote:

> +static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)
> +{
> +	struct pretty_print_context ctx = {0};
> +	struct rev_info rev;
> +
> +	struct strbuf format = STRBUF_INIT;
> +	strbuf_addstr(&format, format_line);
> +	ctx.fmt = CMIT_FMT_USERFORMAT;
> +	get_commit_format(format.buf, &rev);
> +	pretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);
> +	strbuf_release(&format);
> +}

I think this may be less awkward if you use format_commit_message() as
the entry point. Then you do not need a rev_info struct at all, it
touches fewer global variables, etc.

I don't know if that would cause the other difficulties you mentioned,
though.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] blame: draft of line format
  2017-01-31 19:41 ` Jeff King
@ 2017-03-06 23:29   ` Edmundo Carmona Antoranz
  0 siblings, 0 replies; 4+ messages in thread
From: Edmundo Carmona Antoranz @ 2017-03-06 23:29 UTC (permalink / raw)
  To: Jeff King; +Cc: Git List

On Tue, Jan 31, 2017 at 1:41 PM, Jeff King <peff@peff.net> wrote:
> On Mon, Jan 30, 2017 at 08:28:30PM -0600, Edmundo Carmona Antoranz wrote:
>
>> +static void pretty_info(char* revid, struct blame_entry *ent, struct strbuf *rev_buffer)
>> +{
>> +     struct pretty_print_context ctx = {0};
>> +     struct rev_info rev;
>> +
>> +     struct strbuf format = STRBUF_INIT;
>> +     strbuf_addstr(&format, format_line);
>> +     ctx.fmt = CMIT_FMT_USERFORMAT;
>> +     get_commit_format(format.buf, &rev);
>> +     pretty_print_commit(&ctx, ent->suspect->commit, rev_buffer);
>> +     strbuf_release(&format);
>> +}
>
> I think this may be less awkward if you use format_commit_message() as
> the entry point. Then you do not need a rev_info struct at all, it
> touches fewer global variables, etc.
>
> I don't know if that would cause the other difficulties you mentioned,
> though.
>
> -Peff

Thanks for the tip, Peff. It made the code to get rev info much
shorter. I'll work on some other improvements and then I'll send
another patch.

Best regards!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-07  1:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-31  2:28 [PATCH] blame: draft of line format Edmundo Carmona Antoranz
2017-01-31  2:34 ` Edmundo Carmona Antoranz
2017-01-31 19:41 ` Jeff King
2017-03-06 23:29   ` Edmundo Carmona Antoranz

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).