diff options
context:
space:
mode:
-rw-r--r--cgitrc.5.txt5
-rw-r--r--source/cgit.c3
-rw-r--r--source/cgit.h1
-rw-r--r--source/ui-patch.c5
-rwxr-xr-xtests/t0108-patch.sh13
5 files changed, 27 insertions, 0 deletions
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b5f1cdb..049b234 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -320,6 +320,11 @@ max-message-length::
Specifies the maximum number of commit message characters to display in
"log" view. Default value: "80".
+max-patch-count::
+ Specifies the maximum number of commits emitted as a series by the
+ "patch" view when an explicit revision range is requested. A single
+ commit is unaffected. Default value: "50". Set to "0" for no limit.
+
max-ref-count::
Specifies the number of branches and tags to list per section on the
"refs" view, and per page on the dedicated branch and tag pages that
diff --git a/source/cgit.c b/source/cgit.c
index f83d15d..5af2232 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -269,6 +269,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.max_repo_count = INT_MAX;
} else if (!strcmp(name, "max-commit-count"))
ctx.cfg.max_commit_count = atoi(value);
+ else if (!strcmp(name, "max-patch-count"))
+ ctx.cfg.max_patch_count = atoi(value);
else if (!strcmp(name, "project-list"))
ctx.cfg.project_list = strdup_first_line(expand_macros(value));
else if (!strcmp(name, "scan-path"))
@@ -422,6 +424,7 @@ static void prepare_context(void)
ctx.cfg.enable_git_config = 0;
ctx.cfg.max_repo_count = 50;
ctx.cfg.max_commit_count = 50;
+ ctx.cfg.max_patch_count = 50;
ctx.cfg.max_diff_files = 200; /* larger commits render stat only */
ctx.cfg.max_diff_lines = 1000; /* larger file diffs link out */
ctx.cfg.max_msg_len = 80;
diff --git a/source/cgit.h b/source/cgit.h
index aaf90f8..b7caaf5 100644
--- a/source/cgit.h
+++ b/source/cgit.h
@@ -250,6 +250,7 @@ struct cgit_config {
int max_atom_items;
int max_repo_count;
int max_commit_count;
+ int max_patch_count;
int max_diff_files;
int max_diff_lines;
int max_msg_len;
diff --git a/source/ui-patch.c b/source/ui-patch.c
index 9395769..6d8a8ad 100644
--- a/source/ui-patch.c
+++ b/source/ui-patch.c
@@ -91,6 +91,11 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
if (prefix)
rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix);
setup_revisions(rev_argc, rev_argv, &rev, NULL);
+ // A single commit resolves to a parent..commit range, so this only
+ // bounds an explicit id/id2 range and keeps one request from
+ // emitting a patch for the entire history.
+ if (ctx.cfg.max_patch_count > 0)
+ rev.max_count = ctx.cfg.max_patch_count;
prepare_revision_walk(&rev);
while ((commit = get_revision(&rev)) != NULL) {
diff --git a/tests/t0108-patch.sh b/tests/t0108-patch.sh
index 18973bb..ffcba96 100755
--- a/tests/t0108-patch.sh
+++ b/tests/t0108-patch.sh
@@ -59,4 +59,17 @@ test_expect_success 'compare with output of git-format-patch(1)' '
test_cmp tmp_ tmp2
'
+test_expect_success 'max-patch-count bounds a patch range' '
+ {
+ echo "cache-size=0" &&
+ echo "max-patch-count=2" &&
+ echo "repo.url=foo" &&
+ echo "repo.path=$PWD/repos/foo/.git"
+ } >patchcountrc &&
+ id=$(git --git-dir="$PWD/repos/foo/.git" rev-parse HEAD) &&
+ root=$(git --git-dir="$PWD/repos/foo/.git" rev-list --max-parents=0 HEAD) &&
+ CGIT_CONFIG="$PWD/patchcountrc" QUERY_STRING="url=foo/patch&id=$id&id2=$root" cgit >tmp &&
+ test $(grep -c "^From " tmp) -eq 2
+'
+
test_done