pretty: allow showing specific trailers
[gitweb.git] / trailer.c
index e769c5b72c587b4ae48b1f575781682e162c71e8..d6da555cd71bed97acae89bc37787b81dfe423f4 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -793,7 +793,9 @@ static size_t find_patch_start(const char *str)
        const char *s;
 
        for (s = str; *s; s = next_line(s)) {
-               if (starts_with(s, "---"))
+               const char *v;
+
+               if (skip_prefix(s, "---", &v) && isspace(*v))
                        return s - str;
        }
 
@@ -1078,7 +1080,11 @@ void trailer_info_get(struct trailer_info *info, const char *str,
 
        ensure_configured();
 
-       patch_start = find_patch_start(str);
+       if (opts->no_divider)
+               patch_start = strlen(str);
+       else
+               patch_start = find_patch_start(str);
+
        trailer_end = find_trailer_end(str, patch_start);
        trailer_start = find_trailer_start(str, trailer_end);
 
@@ -1126,7 +1132,7 @@ static void format_trailer_info(struct strbuf *out,
        size_t i;
 
        /* If we want the whole block untouched, we can take the fast path. */
-       if (!opts->only_trailers && !opts->unfold) {
+       if (!opts->only_trailers && !opts->unfold && !opts->filter) {
                strbuf_add(out, info->trailer_start,
                           info->trailer_end - info->trailer_start);
                return;
@@ -1141,10 +1147,12 @@ static void format_trailer_info(struct strbuf *out,
                        struct strbuf val = STRBUF_INIT;
 
                        parse_trailer(&tok, &val, NULL, trailer, separator_pos);
-                       if (opts->unfold)
-                               unfold_value(&val);
+                       if (!opts->filter || opts->filter(&tok, opts->filter_data)) {
+                               if (opts->unfold)
+                                       unfold_value(&val);
 
-                       strbuf_addf(out, "%s: %s\n", tok.buf, val.buf);
+                               strbuf_addf(out, "%s: %s\n", tok.buf, val.buf);
+                       }
                        strbuf_release(&tok);
                        strbuf_release(&val);