]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: make file exists check more efficient
authorDenton Liu <liu.denton@gmail.com>
Tue, 7 Apr 2020 14:27:51 +0000 (10:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Apr 2020 23:57:30 +0000 (16:57 -0700)
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>
sequencer.c

index faab0b13e8d72e3945111dbec3b423072a36fe9c..a961cf5a9bea1736547aec6fc2d115ffb18c4e82 100644 (file)
@@ -433,11 +433,9 @@ static int read_oneliner(struct strbuf *buf,
 {
        int orig_len = buf->len;
 
-       if (!file_exists(path))
-               return 0;
-
        if (strbuf_read_file(buf, path, 0) < 0) {
-               warning_errno(_("could not read '%s'"), path);
+               if (errno != ENOENT && errno != ENOTDIR)
+                       warning_errno(_("could not read '%s'"), path);
                return 0;
        }