From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Jakub Narebski" <jnareb@gmail.com>, "Ted Ts'o" <tytso@mit.edu>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Clemens Buchacher" <drizzd@aon.at>,
"Shawn O. Pearce" <spearce@spearce.org>
Subject: [RFC/PATCHv2 4/6] pretty: support %G to show the generation number of a commit
Date: Wed, 13 Jul 2011 03:05:52 -0400 [thread overview]
Message-ID: <20110713070552.GD18566@sigill.intra.peff.net> (raw)
In-Reply-To: <20110713064709.GA18499@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>
---
This now includes some basic tests.
Documentation/pretty-formats.txt | 1 +
pretty.c | 3 ++
t/t6070-commit-generations.sh | 41 ++++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 0 deletions(-)
create mode 100755 t/t6070-commit-generations.sh
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,
diff --git a/t/t6070-commit-generations.sh b/t/t6070-commit-generations.sh
new file mode 100755
index 0000000..3e0f2ad
--- /dev/null
+++ b/t/t6070-commit-generations.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test_description='calculate and cache commit generations'
+. ./test-lib.sh
+
+test_expect_success 'setup history' '
+ test_commit one &&
+ test_commit two &&
+ test_commit three &&
+ test_commit four &&
+ git checkout -b other two &&
+ test_commit five &&
+ git checkout master &&
+ git merge other &&
+ test_commit six
+'
+
+cat >expect <<'EOF'
+5 six
+4 Merge branch 'other'
+2 five
+3 four
+2 three
+1 two
+0 one
+EOF
+test_expect_success 'check commit generations' '
+ git log --format="%G %s" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'cache file was created' '
+ test_path_is_file .git/cache/generations
+'
+
+test_expect_success 'cached values are the same' '
+ git log --format="%G %s" >actual &&
+ test_cmp expect actual
+'
+
+test_done
--
1.7.6.37.g989c6
next prev parent reply other threads:[~2011-07-13 7:06 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-13 6:47 [RFC/PATCHv2 0/6] generation numbers for faster traversals Jeff King
2011-07-13 6:57 ` [RFC/PATCHv2 1/6] decorate: allow storing values instead of pointers Jeff King
2011-07-13 17:52 ` Jonathan Nieder
2011-07-13 20:08 ` Jeff King
2011-07-14 17:34 ` Jeff King
2011-07-14 17:51 ` [PATCH 1/3] implement generic key/value map Jeff King
2011-07-14 18:52 ` Bert Wesarg
2011-07-14 18:54 ` Bert Wesarg
2011-07-14 18:55 ` Jeff King
2011-07-14 19:07 ` Bert Wesarg
2011-07-14 19:14 ` Jeff King
2011-07-14 19:18 ` Bert Wesarg
2011-07-14 17:52 ` [PATCH 2/3] fast-export: use object to uint32 map instead of "decorate" Jeff King
2011-07-15 9:40 ` Sverre Rabbelier
2011-07-15 20:00 ` Jeff King
2011-07-14 17:53 ` [PATCH 3/3] decorate: use "map" for the underlying implementation Jeff King
2011-07-14 21:06 ` [RFC/PATCHv2 1/6] decorate: allow storing values instead of pointers Junio C Hamano
2011-08-04 22:43 ` [RFC/PATCH 0/5] macro-based key/value maps Jeff King
2011-08-04 22:45 ` [PATCH 1/5] implement generic key/value map Jeff King
2011-08-04 22:46 ` [PATCH 2/5] fast-export: use object to uint32 map instead of "decorate" Jeff King
2011-08-04 22:46 ` [PATCH 3/5] decorate: use "map" for the underlying implementation Jeff King
2011-08-04 22:46 ` [PATCH 4/5] map: implement persistent maps Jeff King
2011-08-04 22:46 ` [PATCH 5/5] implement metadata cache subsystem Jeff King
2011-08-04 22:48 ` [RFC/PATCH 0/2] patch-id caching Jeff King
2011-08-04 22:49 ` [PATCH 1/2] cherry: read default config Jeff King
2011-08-04 22:49 ` [PATCH 2/2] cache patch ids on disk Jeff King
2011-08-04 22:52 ` Jeff King
2011-08-05 11:03 ` [RFC/PATCH 0/5] macro-based key/value maps Jeff King
2011-08-05 15:31 ` René Scharfe
2011-08-06 6:30 ` Jeff King
2011-07-13 7:04 ` [RFC/PATCHv2 2/6] add metadata-cache infrastructure Jeff King
2011-07-13 8:18 ` Bert Wesarg
2011-07-13 8:31 ` Jeff King
2011-07-13 8:45 ` Bert Wesarg
2011-07-13 19:18 ` Jeff King
2011-07-13 19:40 ` Junio C Hamano
2011-07-13 19:33 ` Junio C Hamano
2011-07-13 20:25 ` Jeff King
2011-07-13 7:05 ` [RFC/PATCHv2 3/6] commit: add commit_generation function Jeff King
2011-07-13 14:26 ` Eric Sunshine
2011-07-13 7:05 ` Jeff King [this message]
2011-07-13 7:06 ` [RFC/PATCHv2 5/6] check commit generation cache validity against grafts Jeff King
2011-07-13 14:26 ` Eric Sunshine
2011-07-13 19:35 ` Jeff King
2011-07-13 7:06 ` [RFC/PATCHv2 6/6] limit "contains" traversals based on commit generation Jeff King
2011-07-13 7:23 ` Jeff King
2011-07-13 20:33 ` Junio C Hamano
2011-07-13 20:58 ` Jeff King
2011-07-13 21:12 ` Junio C Hamano
2011-07-13 21:18 ` Jeff King
2011-07-15 18:22 ` Junio C Hamano
2011-07-15 20:40 ` Jeff King
2011-07-15 21:04 ` Junio C Hamano
2011-07-15 21:14 ` Jeff King
2011-07-15 21:01 ` Generation numbers and replacement objects Jakub Narebski
2011-07-15 21:10 ` Jeff King
2011-07-16 21:10 ` Jakub Narebski
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110713070552.GD18566@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=drizzd@aon.at \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=jrnieder@gmail.com \
--cc=spearce@spearce.org \
--cc=tytso@mit.edu \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).