]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-log.c
ui-log.c: improve handling of range-search argument
[ps-cgit] / ui-log.c
index 5eb5c813beedaebf7bb0921f20c892c0556f9628..27f5a1a111cef792b45b9bb35b399a25c53e1a58 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -9,6 +9,7 @@
 #include "cgit.h"
 #include "html.h"
 #include "ui-shared.h"
+#include "vector.h"
 
 int files, add_lines, rem_lines;
 
@@ -33,7 +34,8 @@ void inspect_files(struct diff_filepair *pair)
        files++;
        if (ctx.repo->enable_log_linecount)
                cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
-                               &new_size, &binary, 0, count_lines);
+                               &new_size, &binary, 0, ctx.qry.ignorews,
+                               count_lines);
 }
 
 void show_commit_decorations(struct commit *commit)
@@ -100,7 +102,7 @@ void print_commit(struct commit *commit)
                files = 0;
                add_lines = 0;
                rem_lines = 0;
-               cgit_diff_commit(commit, inspect_files);
+               cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);
                html("</td><td>");
                htmlf("%d", files);
                if (ctx.repo->enable_log_linecount) {
@@ -110,6 +112,9 @@ void print_commit(struct commit *commit)
        }
        html("</td></tr>\n");
        if (ctx.qry.showmsg) {
+               struct strbuf notes = STRBUF_INIT;
+               format_note(NULL, commit->object.sha1, &notes, PAGE_ENCODING, 0);
+
                if (ctx.repo->enable_log_filecount) {
                        cols++;
                        if (ctx.repo->enable_log_linecount)
@@ -119,6 +124,15 @@ void print_commit(struct commit *commit)
                        cols);
                html_txt(info->msg);
                html("</td></tr>\n");
+               if (notes.len != 0) {
+                       html("<tr class='nohover'>");
+                       html("<td class='lognotes-label'>Notes:</td>");
+                       htmlf("<td colspan='%d' class='lognotes'>",
+                               cols);
+                       html_txt(notes.buf);
+                       html("</td></tr>\n");
+               }
+               strbuf_release(&notes);
        }
        cgit_free_commitinfo(info);
 }
@@ -135,35 +149,86 @@ static const char *disambiguate_ref(const char *ref)
        return ref;
 }
 
+static char *next_token(char **src)
+{
+       char *result;
+
+       if (!src || !*src)
+               return NULL;
+       while (isspace(**src))
+               (*src)++;
+       if (!**src)
+               return NULL;
+       result = *src;
+       while (**src) {
+               if (isspace(**src)) {
+                       **src = '\0';
+                       (*src)++;
+                       break;
+               }
+               (*src)++;
+       }
+       return result;
+}
+
 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
                    char *path, int pager)
 {
        struct rev_info rev;
        struct commit *commit;
-       const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
-       int argc = 2;
+       struct vector vec = VECTOR_INIT(char *);
        int i, columns = 3;
+       char *arg;
+
+       /* First argv is NULL */
+       vector_push(&vec, NULL, 0);
 
        if (!tip)
                tip = ctx.qry.head;
+       tip = disambiguate_ref(tip);
+       vector_push(&vec, &tip, 0);
 
-       argv[1] = disambiguate_ref(tip);
-
-       if (grep && pattern && (!strcmp(grep, "grep") ||
-                               !strcmp(grep, "author") ||
-                               !strcmp(grep, "committer")))
-               argv[argc++] = fmt("--%s=%s", grep, pattern);
+       if (grep && pattern && *pattern) {
+               pattern = xstrdup(pattern);
+               if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
+                   !strcmp(grep, "committer")) {
+                       arg = fmt("--%s=%s", grep, pattern);
+                       vector_push(&vec, &arg, 0);
+               }
+               if (!strcmp(grep, "range")) {
+                       /* Split the pattern at whitespace and add each token
+                        * as a revision expression. Do not accept other
+                        * rev-list options. Also, replace the previously
+                        * pushed tip (it's no longer relevant).
+                        */
+                       vec.count--;
+                       while ((arg = next_token(&pattern))) {
+                               if (*arg == '-') {
+                                       fprintf(stderr, "Bad range expr: %s\n",
+                                               arg);
+                                       break;
+                               }
+                               vector_push(&vec, &arg, 0);
+                       }
+               }
+       }
 
        if (path) {
-               argv[argc++] = "--";
-               argv[argc++] = path;
+               arg = "--";
+               vector_push(&vec, &arg, 0);
+               vector_push(&vec, &path, 0);
        }
+
+       /* Make sure the vector is NULL-terminated */
+       vector_push(&vec, NULL, 0);
+       vec.count--;
+
        init_revisions(&rev, NULL);
        rev.abbrev = DEFAULT_ABBREV;
        rev.commit_format = CMIT_FMT_DEFAULT;
        rev.verbose_header = 1;
        rev.show_root_diff = 0;
-       setup_revisions(argc, argv, &rev, NULL);
+       setup_revisions(vec.count, vec.data, &rev, NULL);
        load_ref_decorations(DECORATE_FULL_REFS);
        rev.show_decorations = 1;
        rev.grep_filter.regflags |= REG_ICASE;
@@ -212,8 +277,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
                commit->parents = NULL;
        }
        if (pager) {
-               htmlf("</table><div class='pager'>",
-                    columns);
+               html("</table><div class='pager'>");
                if (ofs > 0) {
                        cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
                                      ctx.qry.sha1, ctx.qry.vpath,