Merge branch 'jc/noent-notdir'
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Jun 2017 20:47:06 +0000 (13:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Jun 2017 20:47:07 +0000 (13:47 -0700)
Our code often opens a path to an optional file, to work on its
contents when we can successfully open it. We can ignore a failure
to open if such an optional file does not exist, but we do want to
report a failure in opening for other reasons (e.g. we got an I/O
error, or the file is there, but we lack the permission to open).

The exact errors we need to ignore are ENOENT (obviously) and
ENOTDIR (less obvious). Instead of repeating comparison of errno
with these two constants, introduce a helper function to do so.

* jc/noent-notdir:
treewide: use is_missing_file_error() where ENOENT and ENOTDIR are checked
compat-util: is_missing_file_error()

1  2 
apply.c
builtin/rm.c
builtin/update-index.c
diff-lib.c
dir.c
git-compat-util.h
setup.c
sha1_name.c
wrapper.c
diff --cc apply.c
Simple merge
diff --cc builtin/rm.c
Simple merge
Simple merge
diff --cc diff-lib.c
Simple merge
diff --cc dir.c
Simple merge
Simple merge
diff --cc setup.c
index e3f7699a902aed20a83820067cf913df2f3750a9,bb6a2c1bebf8081f62f65fcbc221e20e5fa4aa93..ba6e855178847a37044eacceae0ebcb17d8e990b
+++ b/setup.c
@@@ -143,17 -142,13 +143,17 @@@ int check_filename(const char *prefix, 
                        return 1;
                name = arg + 2;
        } else if (prefix)
 -              name = prefix_filename(prefix, strlen(prefix), arg);
 +              name = to_free = prefix_filename(prefix, arg);
        else
                name = arg;
 -      if (!lstat(name, &st))
 +      if (!lstat(name, &st)) {
 +              free(to_free);
                return 1; /* file exists */
 -      if (is_missing_file_error(errno))
 +      }
-       if (errno == ENOENT || errno == ENOTDIR) {
++      if (is_missing_file_error(errno)) {
 +              free(to_free);
                return 0; /* file does not exist */
 +      }
        die_errno("failed to stat '%s'", arg);
  }
  
diff --cc sha1_name.c
Simple merge
diff --cc wrapper.c
Simple merge