@matheusbsbs / matheus-bagliano / commits / bfa50c2c7f
Fork 0

sequencer: configurably warn on non-existent files

In the future, we plan on externing read_oneliner(). Future users of read_oneliner() will want the ability to output warnings in the event that the `path` doesn't exist. Introduce the `READ_ONELINER_WARN_MISSING` flag which, if active, would issue a warning when a file doesn't exist by always executing warning_errno() in the case where strbuf_read_file() fails. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 7, 2020 at 10:27 UTC bfa50c2c7f0cb806af6d272a84c16f114e15ceee
1 file changed +3 -1
sequencer.c
+3 -1
@@ -420,6 +420,7 @@ static int write_message(const void *buf, size_t len, const char *filename,
420 }
421
422 #define READ_ONELINER_SKIP_IF_EMPTY (1 << 0)
423 +#define READ_ONELINER_WARN_MISSING (1 << 1)
424
425 /*
426 * Reads a file that was presumably written by a shell script, i.e. with an
@@ -436,7 +437,8 @@ static int read_oneliner(struct strbuf *buf,
437 int orig_len = buf->len;
438
439 if (strbuf_read_file(buf, path, 0) < 0) {
439 - if (errno != ENOENT && errno != ENOTDIR)
440 + if ((flags & READ_ONELINER_WARN_MISSING) ||
441 + (errno != ENOENT && errno != ENOTDIR))
442 warning_errno(_("could not read '%s'"), path);
443 return 0;
444 }