Am 02.08.19 um 23:20 schrieb Junio C Hamano:
> René Scharfe <l....@web.de> writes:
>
>> Having cmd_log_init_finish() call load_ref_decorations() before
>> setup_revisions() would indeed solve the issue as well.  But we need
>> to call the latter to check if --pretty=raw was given and avoid loading
>> decorations in that case, don't we?
>
> I was thinking about giving an instance of the decoration_filter to
> either rev_info or setup_revision_opt, and moving the call to
> load_ref_decorations() and the decision to make that call from
> cmd_log_init_finish() to setup_revisions().

Sure, but we'd need to move the code to handle the raw format as well, no?
Perhaps like this?  It depends on callers of parse_revision_opt() calling
setup_revisions() before using decorations.  And it may have other side
effects; I'm not comfortable with this change.

---
 builtin/log.c  | 10 +++++-----
 revision.c     | 17 ++++++++++++++++-
 revision.h     |  4 ++++
 t/t4202-log.sh | 15 +++++++++++++++
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 1cf9e37736..5a1544276f 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -203,6 +203,10 @@ static void cmd_log_init_finish(int argc, const char 
**argv, const char *prefix,
                             PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
                             PARSE_OPT_KEEP_DASHDASH);

+       rev->decoration_filter = &decoration_filter;
+       rev->decoration_given = decoration_given;
+       rev->decoration_style = decoration_style;
+
        if (quiet)
                rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
        argc = setup_revisions(argc, argv, rev, opt);
@@ -245,16 +249,12 @@ static void cmd_log_init_finish(int argc, const char 
**argv, const char *prefix,
                 * "log --pretty=raw" is special; ignore UI oriented
                 * configuration variables such as decoration.
                 */
-               if (!decoration_given)
-                       decoration_style = 0;
                if (!rev->abbrev_commit_given)
                        rev->abbrev_commit = 0;
        }

-       if (decoration_style) {
+       if (rev->decoration_style)
                rev->show_decorations = 1;
-               load_ref_decorations(&decoration_filter, decoration_style);
-       }

        if (rev->line_level_traverse)
                line_log_init(rev, line_cb.prefix, &line_cb.args);
diff --git a/revision.c b/revision.c
index 07412297f0..709d6a273c 100644
--- a/revision.c
+++ b/revision.c
@@ -2063,7 +2063,6 @@ static int handle_revision_opt(struct rev_info *revs, int 
argc, const char **arg
                revs->simplify_by_decoration = 1;
                revs->limited = 1;
                revs->prune = 1;
-               load_ref_decorations(NULL, DECORATE_SHORT_REFS);
        } else if (!strcmp(arg, "--date-order")) {
                revs->sort_order = REV_SORT_BY_COMMIT_DATE;
                revs->topo_order = 1;
@@ -2716,6 +2715,22 @@ int setup_revisions(int argc, const char **argv, struct 
rev_info *revs, struct s
        if (revs->expand_tabs_in_log < 0)
                revs->expand_tabs_in_log = revs->expand_tabs_in_log_default;

+       if (revs->pretty_given && revs->commit_format == CMIT_FMT_RAW) {
+               /*
+                * "log --pretty=raw" is special; ignore UI oriented
+                * configuration variables such as decoration.
+                */
+               if (!revs->decoration_given)
+                       revs->decoration_style = 0;
+       }
+
+       if (revs->decoration_style)
+               load_ref_decorations(revs->decoration_filter,
+                                    revs->decoration_style);
+       else if (revs->simplify_by_decoration)
+               load_ref_decorations(revs->decoration_filter,
+                                    DECORATE_SHORT_REFS);
+
        return left;
 }

diff --git a/revision.h b/revision.h
index 4134dc6029..67ffe095a9 100644
--- a/revision.h
+++ b/revision.h
@@ -186,6 +186,7 @@ struct rev_info {
                        pretty_given:1,
                        abbrev_commit:1,
                        abbrev_commit_given:1,
+                       decoration_given:1,
                        zero_commit:1,
                        use_terminator:1,
                        missing_newline:1,
@@ -269,6 +270,9 @@ struct rev_info {
        /* line level range that we are chasing */
        struct decoration line_log_data;

+       struct decoration_filter *decoration_filter;
+       int decoration_style;
+
        /* copies of the parent lists, for --full-diff display */
        struct saved_parents *saved_parents_slab;

diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index c20209324c..bb66d1d93c 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -837,6 +837,21 @@ test_expect_success 'decorate-refs and 
decorate-refs-exclude' '
        test_cmp expect.decorate actual
 '

+test_expect_success 'decorate-refs-exclude and simplify-by-decoration' '
+       cat >expect.decorate <<-\EOF &&
+       Merge-tag-reach (HEAD -> master)
+       reach (tag: reach, reach)
+       seventh (tag: seventh)
+       Merge-branch-tangle
+       Merge-branch-side-early-part-into-tangle (tangle)
+       tangle-a (tag: tangle-a)
+       EOF
+       git log -n6 --decorate=short --pretty="tformat:%f%d" \
+               --decorate-refs-exclude="*octopus*" \
+               --simplify-by-decoration >actual &&
+       test_cmp expect.decorate actual
+'
+
 test_expect_success 'log.decorate config parsing' '
        git log --oneline --decorate=full >expect.full &&
        git log --oneline --decorate=short >expect.short &&
--
2.22.0

Reply via email to