From ad6f028f067673cadadbc2219fcb0bb864300a6c Mon Sep 17 00:00:00 2001 From: Issac Trotts Date: Thu, 10 Jan 2019 22:30:46 -0800 Subject: log: add %S option (like --source) to log --format Make it possible to write for example git log --format="%H,%S" where the %S at the end is a new placeholder that prints out the ref (tag/branch) for each commit. Using %d might seem like an alternative but it only shows the ref for the last commit in the branch. Signed-off-by: Issac Trotts Signed-off-by: Junio C Hamano --- pretty.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pretty.c') diff --git a/pretty.c b/pretty.c index b83a3ecd233..1b453fbb59a 100644 --- a/pretty.c +++ b/pretty.c @@ -1084,6 +1084,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ struct commit_list *p; const char *arg; int ch; + char **slot; /* these are independent of the commit */ switch (placeholder[0]) { @@ -1194,6 +1195,14 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ load_ref_decorations(NULL, DECORATE_SHORT_REFS); format_decorations_extended(sb, commit, c->auto_color, "", ", ", ""); return 1; + case 'S': /* tag/branch like --source */ + if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources)) + return 0; + slot = revision_sources_at(c->pretty_ctx->rev->sources, commit); + if (!(slot && *slot)) + return 0; + strbuf_addstr(sb, *slot); + return 1; case 'g': /* reflog info */ switch(placeholder[1]) { case 'd': /* reflog selector */ @@ -1498,6 +1507,9 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder, case 'N': w->notes = 1; break; + case 'S': + w->source = 1; + break; } return 0; } -- cgit v1.2.3