Display notes in the rev-list when switch '--notes' is used.
Also expand notes place holder (%N) in user format.
Previously rev-list ignored both of these.

Signed-off-by: Jukka Lehtniemi <jukka.lehtni...@gmail.com>
---

Thanks for your feedback Peff!

 builtin/rev-list.c         |   16 +++++++++++++++-
 t/t6006-rev-list-format.sh |   22 +++++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ff5a383..ad8abcb 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -7,6 +7,7 @@
 #include "log-tree.h"
 #include "graph.h"
 #include "bisect.h"
+#include "notes.h"
 
 static const char rev_list_usage[] =
 "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -111,6 +112,7 @@ static void show_commit(struct commit *commit, void *data)
                ctx.date_mode = revs->date_mode;
                ctx.date_mode_explicit = revs->date_mode_explicit;
                ctx.fmt = revs->commit_format;
+               ctx.show_notes = revs->show_notes;
                pretty_print_commit(&ctx, commit, &buf);
                if (revs->graph) {
                        if (buf.len) {
@@ -159,6 +161,12 @@ static void show_commit(struct commit *commit, void *data)
        } else {
                if (graph_show_remainder(revs->graph))
                        putchar('\n');
+               if (revs->show_notes_given) {
+                       struct strbuf buf = STRBUF_INIT;
+                       format_display_notes(commit->object.sha1, &buf, 0, 
NOTES_SHOW_HEADER|NOTES_INDENT); 
+                       fwrite(buf.buf, 1, buf.len, stdout);
+                       strbuf_release(&buf);
+               }
        }
        maybe_flush_or_die(stdout, "stdout");
        finish_commit(commit, data);
@@ -309,6 +317,7 @@ int cmd_rev_list(int argc, const char **argv, const char 
*prefix)
 {
        struct rev_info revs;
        struct rev_list_info info;
+       struct userformat_want userformat_want = {0};
        int i;
        int bisect_list = 0;
        int bisect_show_vars = 0;
@@ -322,9 +331,14 @@ int cmd_rev_list(int argc, const char **argv, const char 
*prefix)
 
        memset(&info, 0, sizeof(info));
        info.revs = &revs;
+
+       userformat_find_requirements(NULL, &userformat_want);
+       if (userformat_want.notes)
+               revs.show_notes = 1;
        if (revs.bisect)
                bisect_list = 1;
-
+       if (revs.show_notes)
+               init_display_notes(&revs.notes_opt);
        if (DIFF_OPT_TST(&revs.diffopt, QUICK))
                info.flags |= REV_LIST_QUIET;
        for (i = 1 ; i < argc; i++) {
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index f94f0c4..ab616a0 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -7,7 +7,8 @@ test_description='git rev-list --pretty=format test'
 test_tick
 test_expect_success 'setup' '
 touch foo && git add foo && git commit -m "added foo" &&
-  echo changed >foo && git commit -a -m "changed foo"
+  echo changed >foo && git commit -a -m "changed foo" &&
+  git notes add -m "note foo"
 '
 
 # usage: test_format name format_string <expected_output
@@ -19,6 +20,25 @@ test_cmp expect.$1 output.$1
 "
 }
 
+test_expect_success 'notes switch' "
+cat >expect.notes_switch <<'EOF'
+131a310eb913d107dd3c09a65d1651175898735d
+
+Notes:
+    note foo
+86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+EOF
+git rev-list --notes master >output.notes_switch &&
+test_cmp expect.notes_switch output.notes_switch
+"
+
+test_format notes %N <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+note foo
+
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+EOF
+
 test_format percent %%h <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
 %h
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to