|
29 | 29 | #include "quote.h" |
30 | 30 | #include "strbuf.h" |
31 | 31 | #include "tree-verify.h" |
| 32 | +#include "parse.h" |
| 33 | + |
| 34 | +#define INCREMENTAL_MAX_COMMITS 1000 |
32 | 35 |
|
33 | 36 | enum connectivity_check_mode { |
34 | 37 | CONNECTIVITY_CHECK_FULL, |
35 | 38 | CONNECTIVITY_CHECK_INCREMENTAL, |
| 39 | + CONNECTIVITY_CHECK_AUTO, |
36 | 40 | }; |
37 | 41 |
|
38 | 42 | struct connectivity_check { |
39 | 43 | enum connectivity_check_mode mode; |
| 44 | + unsigned long max_commits; |
40 | 45 | }; |
41 | 46 |
|
42 | 47 | static void parse_connectivity_check(struct repository *repo, |
43 | 48 | const char *arg, |
44 | 49 | struct connectivity_check *check) |
45 | 50 | { |
| 51 | + const char *cutoff; |
| 52 | + |
46 | 53 | if (!strcmp(arg, "full")) |
47 | 54 | check->mode = CONNECTIVITY_CHECK_FULL; |
48 | 55 | else if (!strcmp(arg, "incremental")) |
49 | 56 | check->mode = CONNECTIVITY_CHECK_INCREMENTAL; |
| 57 | + else if (!strcmp(arg, "auto")) |
| 58 | + check->mode = CONNECTIVITY_CHECK_AUTO; |
| 59 | + else if (skip_prefix(arg, "auto=", &cutoff) && |
| 60 | + git_parse_ulong(cutoff, &check->max_commits)) |
| 61 | + check->mode = CONNECTIVITY_CHECK_AUTO; |
50 | 62 | else |
51 | 63 | die(_("unknown --connectivity-check mode '%s'"), arg); |
52 | 64 |
|
@@ -752,7 +764,9 @@ int cmd_rev_list(int argc, |
752 | 764 | int bisect_find_all = 0; |
753 | 765 | int use_bitmap_index = 0; |
754 | 766 | int filter_provided_objects = 0; |
755 | | - struct connectivity_check connectivity_check = { 0 }; |
| 767 | + struct connectivity_check connectivity_check = { |
| 768 | + .max_commits = INCREMENTAL_MAX_COMMITS, |
| 769 | + }; |
756 | 770 | const char *show_progress = NULL; |
757 | 771 | int ret = 0; |
758 | 772 |
|
@@ -1005,9 +1019,19 @@ int cmd_rev_list(int argc, |
1005 | 1019 | * The incremental check would still work, but it would verify |
1006 | 1020 | * the whole object graph like the full check, with extra |
1007 | 1021 | * per-commit overhead on top, so use the full check. |
| 1022 | + * |
| 1023 | + * Otherwise the walk is limited, and revs.commits already holds |
| 1024 | + * all incoming commits, so counting them for "auto" is cheap. |
1008 | 1025 | */ |
1009 | | - if (!revs.limited) |
| 1026 | + if (!revs.limited) { |
1010 | 1027 | connectivity_check.mode = CONNECTIVITY_CHECK_FULL; |
| 1028 | + } else if (connectivity_check.mode == CONNECTIVITY_CHECK_AUTO) { |
| 1029 | + if (commit_list_count(revs.commits) <= |
| 1030 | + connectivity_check.max_commits) |
| 1031 | + connectivity_check.mode = CONNECTIVITY_CHECK_INCREMENTAL; |
| 1032 | + else |
| 1033 | + connectivity_check.mode = CONNECTIVITY_CHECK_FULL; |
| 1034 | + } |
1011 | 1035 |
|
1012 | 1036 | if (connectivity_check.mode == CONNECTIVITY_CHECK_INCREMENTAL) { |
1013 | 1037 | struct commit *commit; |
|
0 commit comments