[PATCH v5 04/22] sequencer: make file exists check more efficient
- From
Denton Liu <liu.denton@gmail.com>
- Date
- Apr 7, 2020, 14:27 UTC
- Message-ID
- <dc4674d222317fa2f503e6e1b3cad6a78dd70676.1586269543.git.liu.denton@gmail.com>
- In-Reply-To
- <cover.1586269542.git.liu.denton@gmail.com>
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> --- sequencer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/sequencer.c b/sequencer.c index faab0b13e8..a961cf5a9b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -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; }
-- 2.26.0.159.g23e2136ad0