[PATCH 4/5] pretty: support %G to show the generation number of a commit
- From
Jeff King <peff@peff.net>
- Date
- Jul 11, 2011, 16:18 UTC
- Message-ID
- <20110711161827.GD10418@sigill.intra.peff.net>
- In-Reply-To
- <20110711161332.GA10057@sigill.intra.peff.net>
This might be useful for external programs doing topological sorting or other graph analysis. It's also handy for testing the generation calculation code.
Signed-off-by: Jeff King <peff@peff.net> --- Documentation/pretty-formats.txt | 1 + pretty.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 561cc9f..c58ab52 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -133,6 +133,7 @@ The placeholders are: - '%gD': reflog selector, e.g., `refs/stash@\{1\}` - '%gd': shortened reflog selector, e.g., `stash@\{1\}` - '%gs': reflog subject +- '%G': generation number (i.e., distance of path to farthest root ancestor) - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue diff --git a/pretty.c b/pretty.c index f45eb54..8f1b321 100644 --- a/pretty.c +++ b/pretty.c @@ -965,6 +965,9 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder, return 2; } return 0; /* unknown %g placeholder */ + case 'G': + strbuf_addf(sb, "%lu", commit_generation(commit)); + return 1; case 'N': if (c->pretty_ctx->show_notes) { format_display_notes(commit->object.sha1, sb,
-- 1.7.6.37.g989c6