From: Olliver Schinagl Date: Sat, 30 Mar 2024 08:10:27 GMT Subject: [RFC] bisect: Introduce skip-when to automatically skip commits Message-ID: <20240330081026.362962-2-oliver@schinagl.nl> Before I go dig myself in deeper, I'd like some feedback and opinions on whether this is the correct direction. If I got it right, do say so, as then I can start adding some tests and update the documentation. Olliver --- In some situations, it is needed to skip certain commits when bisecting, because the compile doesn't work, or tests are known to fail. For this purpose, we introduce the `--skip-when` flag which takes a script as an input and is expected to return exit code 125 if a commit is to be skipped, which uses a regular `git bisect skip` and the commit thus ends up on the skipped pile. In addition we also offer a git-hook, to make this as predictable and painless as possible. The script can do whatever it wants to to determine if a commit is to be skipped; From comparing the hash against a known list, to checking git notes for a keyword or, as the included example, the commit body. Signed-off-by: Olliver Schinagl --- bisect.c | 2 + builtin/bisect.c | 93 +++++++++++++++++++++++- templates/hooks--bisect-skip_when.sample | 10 +++ 3 files changed, 101 insertions(+), 4 deletions(-) create mode 100755 templates/hooks--bisect-skip_when.sample diff --git a/bisect.c b/bisect.c index 60aae2fe50..185909cca9 100644 --- a/bisect.c +++ b/bisect.c @@ -476,6 +476,7 @@ static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES") static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK") static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN") static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START") +static GIT_PATH_FUNC(git_path_bisect_skip_when, "BISECT_SKIP_WHEN") static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG") static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT") @@ -1179,6 +1180,7 @@ int bisect_clean_state(void) unlink_or_warn(git_path_bisect_log()); unlink_or_warn(git_path_bisect_names()); unlink_or_warn(git_path_bisect_run()); + unlink_or_warn(git_path_bisect_skip_when()); unlink_or_warn(git_path_bisect_terms()); unlink_or_warn(git_path_bisect_first_parent()); /* diff --git a/builtin/bisect.c b/builtin/bisect.c index 9891cf2604..6870142b85 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -4,6 +4,7 @@ #include "environment.h" #include "gettext.h" #include "hex.h" +#include "hook.h" #include "object-name.h" #include "oid-array.h" #include "parse-options.h" @@ -14,19 +15,21 @@ #include "revision.h" #include "run-command.h" #include "strvec.h" +#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK") static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START") +static GIT_PATH_FUNC(git_path_bisect_skip_when, "BISECT_SKIP_WHEN") static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG") static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES") static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT") static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN") #define BUILTIN_GIT_BISECT_START_USAGE \ - N_("git bisect start [--term-(new|bad)= --term-(old|good)=]" \ - " [--no-checkout] [--first-parent] [ [...]] [--]" \ - " [...]") + N_("git bisect start [--term-(new|bad)= --term-(old|good)=]\n" \ + " [--no-checkout] [--first-parent] [--skip-when=