Add the F (filename) and L (line number) format specifiers. These are to be used with blame only and therefore only work with blame. Signed-off-by: Aleks Todorov <aleks.todorov.1337@xxxxxxxxx> --- pretty.c | 14 ++++++++++++++ pretty.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/pretty.c b/pretty.c index 0bc8ad8a9a..d2b7284854 100644 --- a/pretty.c +++ b/pretty.c @@ -1446,6 +1446,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ const char *arg, *eol; size_t res; char **slot; + char line_number[16]; /* these are independent of the commit */ res = strbuf_expand_literal(sb, placeholder); @@ -1549,6 +1550,19 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ if (!commit->object.parsed) parse_object(the_repository, &commit->object.oid); + if (c->pretty_ctx->is_blame) { + switch (placeholder[0]) { + case 'F': /* filename */ + strbuf_addstr(sb, c->pretty_ctx->filename); + return 1; + case 'L': /* line number */ + snprintf(line_number, sizeof(line_number), "%zu", + c->pretty_ctx->line); + strbuf_addstr(sb, line_number); + return 1; + } + } + switch (placeholder[0]) { case 'H': /* commit hash */ strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT)); diff --git a/pretty.h b/pretty.h index df267afe4a..eb54070ecb 100644 --- a/pretty.h +++ b/pretty.h @@ -51,6 +51,11 @@ struct pretty_print_context { unsigned encode_email_headers:1; struct pretty_print_describe_status *describe_status; + /* Blame fields */ + bool is_blame; + const char *filename; + size_t line; + /* * Fields below here are manipulated internally by pp_* functions and * should not be counted on by callers. -- 2.43.0