Git fork

Merge branch 'dm/compat-s-ifmt-for-zos'

Long overdue departure from the assumption that S_IFMT is shared by
everybody made in 2005.

* dm/compat-s-ifmt-for-zos:
compat: convert modes to use portable file type values

+113 -7
+8
Makefile
··· 191 191 # Define NO_TRUSTABLE_FILEMODE if your filesystem may claim to support 192 192 # the executable mode bit, but doesn't really do so. 193 193 # 194 + # Define NEEDS_MODE_TRANSLATION if your OS strays from the typical file type 195 + # bits in mode values (e.g. z/OS defines I_SFMT to 0xFF000000 as opposed to the 196 + # usual 0xF000). 197 + # 194 198 # Define NO_IPV6 if you lack IPv6 support and getaddrinfo(). 195 199 # 196 200 # Define NO_UNIX_SOCKETS if your system does not offer unix sockets. ··· 1229 1233 endif 1230 1234 ifdef NO_TRUSTABLE_FILEMODE 1231 1235 BASIC_CFLAGS += -DNO_TRUSTABLE_FILEMODE 1236 + endif 1237 + ifdef NEEDS_MODE_TRANSLATION 1238 + COMPAT_CFLAGS += -DNEEDS_MODE_TRANSLATION 1239 + COMPAT_OBJS += compat/stat.o 1232 1240 endif 1233 1241 ifdef NO_IPV6 1234 1242 BASIC_CFLAGS += -DNO_IPV6
-7
cache.h
··· 65 65 * 66 66 * The value 0160000 is not normally a valid mode, and 67 67 * also just happens to be S_IFDIR + S_IFLNK 68 - * 69 - * NOTE! We *really* shouldn't depend on the S_IFxxx macros 70 - * always having the same values everywhere. We should use 71 - * our internal git values for these things, and then we can 72 - * translate that to the OS-specific value. It just so 73 - * happens that everybody shares the same bit representation 74 - * in the UNIX world (and apparently wider too..) 75 68 */ 76 69 #define S_IFGITLINK 0160000 77 70 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
+48
compat/stat.c
··· 1 + #define _POSIX_C_SOURCE 200112L 2 + #include <sys/stat.h> /* *stat, S_IS* */ 3 + #include <sys/types.h> /* mode_t */ 4 + 5 + static inline mode_t mode_native_to_git(mode_t native_mode) 6 + { 7 + mode_t perm_bits = native_mode & 07777; 8 + if (S_ISREG(native_mode)) 9 + return 0100000 | perm_bits; 10 + if (S_ISDIR(native_mode)) 11 + return 0040000 | perm_bits; 12 + if (S_ISLNK(native_mode)) 13 + return 0120000 | perm_bits; 14 + if (S_ISBLK(native_mode)) 15 + return 0060000 | perm_bits; 16 + if (S_ISCHR(native_mode)) 17 + return 0020000 | perm_bits; 18 + if (S_ISFIFO(native_mode)) 19 + return 0010000 | perm_bits; 20 + if (S_ISSOCK(native_mode)) 21 + return 0140000 | perm_bits; 22 + /* Non-standard type bits were given. */ 23 + return perm_bits; 24 + } 25 + 26 + int git_stat(const char *path, struct stat *buf) 27 + { 28 + int rc = stat(path, buf); 29 + if (rc == 0) 30 + buf->st_mode = mode_native_to_git(buf->st_mode); 31 + return rc; 32 + } 33 + 34 + int git_fstat(int fd, struct stat *buf) 35 + { 36 + int rc = fstat(fd, buf); 37 + if (rc == 0) 38 + buf->st_mode = mode_native_to_git(buf->st_mode); 39 + return rc; 40 + } 41 + 42 + int git_lstat(const char *path, struct stat *buf) 43 + { 44 + int rc = lstat(path, buf); 45 + if (rc == 0) 46 + buf->st_mode = mode_native_to_git(buf->st_mode); 47 + return rc; 48 + }
+23
configure.ac
··· 873 873 SNPRINTF_RETURNS_BOGUS= 874 874 fi 875 875 GIT_CONF_SUBST([SNPRINTF_RETURNS_BOGUS]) 876 + # 877 + # Define NEEDS_MODE_TRANSLATION if your OS strays from the typical file type 878 + # bits in mode values. 879 + AC_CACHE_CHECK([whether the platform uses typical file type bits], 880 + [ac_cv_sane_mode_bits], [ 881 + AC_EGREP_CPP(yippeeyeswehaveit, 882 + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT], 883 + [#if S_IFMT == 0170000 && \ 884 + S_IFREG == 0100000 && S_IFDIR == 0040000 && S_IFLNK == 0120000 && \ 885 + S_IFBLK == 0060000 && S_IFCHR == 0020000 && \ 886 + S_IFIFO == 0010000 && S_IFSOCK == 0140000 887 + yippeeyeswehaveit 888 + #endif 889 + ]), 890 + [ac_cv_sane_mode_bits=yes], 891 + [ac_cv_sane_mode_bits=no]) 892 + ]) 893 + if test $ac_cv_sane_mode_bits = yes; then 894 + NEEDS_MODE_TRANSLATION= 895 + else 896 + NEEDS_MODE_TRANSLATION=UnfortunatelyYes 897 + fi 898 + GIT_CONF_SUBST([NEEDS_MODE_TRANSLATION]) 876 899 877 900 878 901 ## Checks for library functions.
+34
git-compat-util.h
··· 475 475 #define on_disk_bytes(st) ((st).st_blocks * 512) 476 476 #endif 477 477 478 + #ifdef NEEDS_MODE_TRANSLATION 479 + #undef S_IFMT 480 + #undef S_IFREG 481 + #undef S_IFDIR 482 + #undef S_IFLNK 483 + #undef S_IFBLK 484 + #undef S_IFCHR 485 + #undef S_IFIFO 486 + #undef S_IFSOCK 487 + #define S_IFMT 0170000 488 + #define S_IFREG 0100000 489 + #define S_IFDIR 0040000 490 + #define S_IFLNK 0120000 491 + #define S_IFBLK 0060000 492 + #define S_IFCHR 0020000 493 + #define S_IFIFO 0010000 494 + #define S_IFSOCK 0140000 495 + #ifdef stat 496 + #undef stat 497 + #endif 498 + #define stat(path, buf) git_stat(path, buf) 499 + extern int git_stat(const char *, struct stat *); 500 + #ifdef fstat 501 + #undef fstat 502 + #endif 503 + #define fstat(fd, buf) git_fstat(fd, buf) 504 + extern int git_fstat(int, struct stat *); 505 + #ifdef lstat 506 + #undef lstat 507 + #endif 508 + #define lstat(path, buf) git_lstat(path, buf) 509 + extern int git_lstat(const char *, struct stat *); 510 + #endif 511 + 478 512 #define DEFAULT_PACKED_GIT_LIMIT \ 479 513 ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) 480 514