]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: configurably warn on non-existent files
authorDenton Liu <liu.denton@gmail.com>
Tue, 7 Apr 2020 14:27:53 +0000 (10:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Apr 2020 23:57:30 +0000 (16:57 -0700)
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>
sequencer.c

index 6c4e8743ef26bcbece6974bb5fcd1a2515980b60..32cc289da3adb3b8e9174a9e3cfbf796a736d6dd 100644 (file)
@@ -420,6 +420,7 @@ static int write_message(const void *buf, size_t len, const char *filename,
 }
 
 #define READ_ONELINER_SKIP_IF_EMPTY (1 << 0)
+#define READ_ONELINER_WARN_MISSING (1 << 1)
 
 /*
  * 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,
        int orig_len = buf->len;
 
        if (strbuf_read_file(buf, path, 0) < 0) {
-               if (errno != ENOENT && errno != ENOTDIR)
+               if ((flags & READ_ONELINER_WARN_MISSING) ||
+                   (errno != ENOENT && errno != ENOTDIR))
                        warning_errno(_("could not read '%s'"), path);
                return 0;
        }