@matheusbsbs / matheus-bagliano / commits / 5b2f6d9cd5
Fork 0

sequencer: make file exists check more efficient

We currently check whether a file exists and return early before reading the file. Instead of accessing the file twice, always read the file and check `errno` to see if the file doesn't exist. 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 5b2f6d9cd50b1c8909326c7175aef288a9915f33
1 file changed +2 -4
sequencer.c
+2 -4
@@ -433,11 +433,9 @@ static int read_oneliner(struct strbuf *buf,
433 {
434 int orig_len = buf->len;
435
436 - if (!file_exists(path))
437 - return 0;
438 -
436 if (strbuf_read_file(buf, path, 0) < 0) {
440 - warning_errno(_("could not read '%s'"), path);
437 + if (errno != ENOENT && errno != ENOTDIR)
438 + warning_errno(_("could not read '%s'"), path);
439 return 0;
440 }
441