[PATCH 1/2] bisect--helper: `is_expected_rev` shell function in C
- From
Pranit Bauva <pranit.bauva@gmail.com>
- Date
- Jun 8, 2016, 15:24 UTC
- Message-ID
- <20160608152415.7770-1-pranit.bauva@gmail.com>
Reimplement `is_expected_rev` shell function in C. This will further be called from `check_expected_revs` function. This is a quite small function thus subcommand facility is redundant.
Mentored-by: Lars Schneider <larsxschneider@gmail.com> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> --- This applies on the previous patches.
builtin/bisect--helper.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 4153e8a..06bc9b8 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -160,6 +160,20 @@ int bisect_reset(const char *commit) return bisect_clean_state(); } +static int is_expected_rev(const char *expected_hex) +{ + struct strbuf actual_hex = STRBUF_INIT; + + if (!file_exists(git_path_bisect_expected_rev())) + return 0; + + if (!strbuf_read_file(&actual_hex, git_path_bisect_expected_rev(), 0)) + return 0; + + strbuf_trim(&actual_hex); + return !strcmp(actual_hex.buf, expected_hex); +} + int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { enum {
-- 2.8.3