{"thread":{"id":"40120","subject":"[PATCH] Use symbolic names for setup file access right","startedAt":"2015-08-18T13:41:24Z","lastAt":"2015-08-18T13:41:24Z","messageCount":1,"participants":["brilliantov@inbox.ru"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"268253","messageId":"1439905284-31649-1-git-send-email-brilliantov@inbox.ru","threadId":"40120","inReplyTo":null,"subject":"[PATCH] Use symbolic names for setup file access right","fromName":"","fromEmail":"brilliantov@inbox.ru","sentAt":"2015-08-18T13:41:24Z","receivedAt":"2015-08-18T13:41:24Z","isPatch":true,"sender":{"key":"brilliantov@inbox.ru","avatar":null},"body":"From: Brilliantov Kirill Vladimirovich <brilliantov@inbox.ru>\n\nSigned-off-by: Brilliantov Kirill Vladimirovich <brilliantov@inbox.ru>\n---\n archive-tar.c        | 15 +++++++++------\n archive-zip.c        |  7 +++++--\n archive.c            |  3 ++-\n builtin/add.c        |  3 ++-\n builtin/am.c         |  8 +++++---\n builtin/apply.c      |  6 ++++--\n builtin/archive.c    |  4 +++-\n builtin/clone.c      |  7 ++++---\n builtin/config.c     |  4 +++-\n builtin/index-pack.c |  7 +++++--\n builtin/init-db.c    |  5 +++--\n builtin/log.c        |  4 +++-\n builtin/mailsplit.c  |  3 ++-\n builtin/merge.c      |  9 +++++----\n builtin/notes.c      |  4 +++-\n builtin/replace.c    |  3 ++-\n builtin/tag.c        |  3 ++-\n builtin/worktree.c   |  3 ++-\n cache.h              |  6 ++++--\n compat/mingw.c       |  4 ++--\n compat/stat.c        | 21 ++++++++++-----------\n config.c             |  9 +++++++--\n copy.c               |  4 +++-\n diff-no-index.c      |  3 ++-\n entry.c              | 12 +++++++-----\n fast-import.c        |  9 +++++----\n file-access.h        | 27 +++++++++++++++++++++++++++\n http.c               |  8 +++++---\n lockfile.c           |  3 ++-\n merge-recursive.c    |  7 ++++---\n notes-merge.c        |  3 ++-\n refs.c               |  7 ++++---\n rerere.c             |  3 ++-\n sequencer.c          |  5 +++--\n server-info.c        |  3 ++-\n setup.c              |  5 +++--\n sha1_file.c          | 13 +++++++------\n test-delta.c         |  3 ++-\n trace.c              |  4 +++-\n wrapper.c            |  3 ++-\n 40 files changed, 172 insertions(+), 88 deletions(-)\n create mode 100644 file-access.h\n\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 0d1e6bd..94caa30 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -6,6 +6,7 @@\n #include \"archive.h\"\n #include \"streaming.h\"\n #include \"run-command.h\"\n+#include \"file-access.h\"\n \n #define RECORDSIZE\t(512)\n #define BLOCKSIZE\t(RECORDSIZE * 20)\n@@ -167,7 +168,8 @@ static void prepare_header(struct archiver_args *args,\n \t\t\t   struct ustar_header *header,\n \t\t\t   unsigned int mode, unsigned long size)\n {\n-\tsprintf(header->mode, \"%07o\", mode & 07777);\n+\tsprintf(header->mode, \"%07o\",\n+\t\tmode & (S_ISUID | S_ISGID | S_ISVTX | DIRECTORY_RW_ALL));\n \tsprintf(header->size, \"%011lo\", S_ISREG(mode) ? size : 0);\n \tsprintf(header->mtime, \"%011lo\", (unsigned long) args->time);\n \n@@ -192,7 +194,7 @@ static int write_extended_header(struct archiver_args *args,\n \tunsigned int mode;\n \tmemset(&header, 0, sizeof(header));\n \t*header.typeflag = TYPEFLAG_EXT_HEADER;\n-\tmode = 0100666;\n+\tmode = S_IFREG | FILE_RW_ALL;\n \tsprintf(header.name, \"%s.paxheader\", sha1_to_hex(sha1));\n \tprepare_header(args, &header, mode, size);\n \twrite_blocked(&header, sizeof(header));\n@@ -216,13 +218,14 @@ static int write_tar_entry(struct archiver_args *args,\n \n \tif (S_ISDIR(mode) || S_ISGITLINK(mode)) {\n \t\t*header.typeflag = TYPEFLAG_DIR;\n-\t\tmode = (mode | 0777) & ~tar_umask;\n+\t\tmode = (mode | DIRECTORY_RW_ALL) & ~tar_umask;\n \t} else if (S_ISLNK(mode)) {\n \t\t*header.typeflag = TYPEFLAG_LNK;\n-\t\tmode |= 0777;\n+\t\tmode |= DIRECTORY_RW_ALL;\n \t} else if (S_ISREG(mode)) {\n \t\t*header.typeflag = TYPEFLAG_REG;\n-\t\tmode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;\n+\t\tmode = (mode | ((mode & S_IXUSR)\n+\t\t\t? DIRECTORY_RW_ALL : FILE_RW_ALL)) & ~tar_umask;\n \t} else {\n \t\treturn error(\"unsupported file mode: 0%o (SHA1: %s)\",\n \t\t\t     mode, sha1_to_hex(sha1));\n@@ -300,7 +303,7 @@ static int write_global_extended_header(struct archiver_args *args)\n \tstrbuf_append_ext_header(&ext_header, \"comment\", sha1_to_hex(sha1), 40);\n \tmemset(&header, 0, sizeof(header));\n \t*header.typeflag = TYPEFLAG_GLOBAL_HEADER;\n-\tmode = 0100666;\n+\tmode = S_IFREG | FILE_RW_ALL;\n \tstrcpy(header.name, \"pax_global_header\");\n \tprepare_header(args, &header, mode, ext_header.len);\n \twrite_blocked(&header, sizeof(header));\ndiff --git a/archive-zip.c b/archive-zip.c\nindex ae3d67f..791c002 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -7,6 +7,7 @@\n #include \"utf8.h\"\n #include \"userdiff.h\"\n #include \"xdiff-interface.h\"\n+#include \"file-access.h\"\n \n static int zip_date;\n static int zip_time;\n@@ -249,8 +250,10 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tenum object_type type = sha1_object_info(sha1, &size);\n \n \t\tmethod = 0;\n-\t\tattr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :\n-\t\t\t(mode & 0111) ? ((mode) << 16) : 0;\n+\t\tattr2 = S_ISLNK(mode)\n+\t\t\t? ((mode | DIRECTORY_RW_ALL) << 16)\n+\t\t\t: (mode & (S_IXUSR | S_IXGRP | S_IXOTH))\n+\t\t\t\t? ((mode) << 16) : 0;\n \t\tif (S_ISREG(mode) && args->compression_level != 0 && size > 0)\n \t\t\tmethod = 8;\n \ndiff --git a/archive.c b/archive.c\nindex 01b0899..f248b64 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -7,6 +7,7 @@\n #include \"parse-options.h\"\n #include \"unpack-trees.h\"\n #include \"dir.h\"\n+#include \"file-access.h\"\n \n static char const * const archive_usage[] = {\n \tN_(\"git archive [<options>] <tree-ish> [<path>...]\"),\n@@ -241,7 +242,7 @@ int write_archive_entries(struct archiver_args *args,\n \t\tif (args->verbose)\n \t\t\tfprintf(stderr, \"%.*s\\n\", (int)len, args->base);\n \t\terr = write_entry(args, args->tree->object.sha1, args->base,\n-\t\t\t\t  len, 040777);\n+\t\t\t\t  len, S_IFDIR | DIRECTORY_RW_ALL);\n \t\tif (err)\n \t\t\treturn err;\n \t}\ndiff --git a/builtin/add.c b/builtin/add.c\nindex b2a5c57..e76946b 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -17,6 +17,7 @@\n #include \"revision.h\"\n #include \"bulk-checkin.h\"\n #include \"argv-array.h\"\n+#include \"file-access.h\"\n \n static const char * const builtin_add_usage[] = {\n \tN_(\"git add [<options>] [--] <pathspec>...\"),\n@@ -200,7 +201,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)\n \trev.diffopt.output_format = DIFF_FORMAT_PATCH;\n \trev.diffopt.use_color = 0;\n \tDIFF_OPT_SET(&rev.diffopt, IGNORE_DIRTY_SUBMODULES);\n-\tout = open(file, O_CREAT | O_WRONLY, 0666);\n+\tout = open(file, O_CREAT | O_WRONLY, FILE_RW_ALL);\n \tif (out < 0)\n \t\tdie(_(\"Could not open '%s' for writing.\"), file);\n \trev.diffopt.file = xfdopen(out, \"w\");\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 1399c8d..006f753 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -26,6 +26,7 @@\n #include \"notes-utils.h\"\n #include \"rerere.h\"\n #include \"prompt.h\"\n+#include \"file-access.h\"\n \n /**\n  * Returns 1 if the file is empty or does not exist, 0 otherwise.\n@@ -391,7 +392,7 @@ static void write_commit_msg(const struct am_state *state)\n \tint fd;\n \tconst char *filename = am_path(state, \"final-commit\");\n \n-\tfd = xopen(filename, O_WRONLY | O_CREAT, 0666);\n+\tfd = xopen(filename, O_WRONLY | O_CREAT, FILE_RW_ALL);\n \tif (write_in_full(fd, state->msg, state->msg_len) < 0)\n \t\tdie_errno(_(\"could not write to %s\"), filename);\n \tclose(fd);\n@@ -983,7 +984,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,\n \t\texit(128);\n \t}\n \n-\tif (mkdir(state->dir, 0777) < 0 && errno != EEXIST)\n+\tif (mkdir(state->dir, DIRECTORY_RW_ALL) < 0 && errno != EEXIST)\n \t\tdie_errno(_(\"failed to create directory '%s'\"), state->dir);\n \n \tif (split_mail(state, patch_format, paths, keep_cr) < 0) {\n@@ -1207,7 +1208,8 @@ static int parse_mail(struct am_state *state, const char *mail)\n \n \tcp.git_cmd = 1;\n \tcp.in = xopen(mail, O_RDONLY, 0);\n-\tcp.out = xopen(am_path(state, \"info\"), O_WRONLY | O_CREAT, 0777);\n+\tcp.out = xopen(am_path(state, \"info\"), O_WRONLY | O_CREAT,\n+\t\t\tDIRECTORY_RW_ALL);\n \n \targv_array_push(&cp.args, \"mailinfo\");\n \targv_array_push(&cp.args, state->utf8 ? \"-u\" : \"-n\");\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 54aba4e..db8e572 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -20,6 +20,7 @@\n #include \"xdiff-interface.h\"\n #include \"ll-merge.h\"\n #include \"rerere.h\"\n+#include \"file-access.h\"\n \n /*\n  *  --check turns on checking that the working tree matches the\n@@ -4102,7 +4103,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \t\tstruct stat st;\n \t\tif (!lstat(path, &st) && S_ISDIR(st.st_mode))\n \t\t\treturn 0;\n-\t\treturn mkdir(path, 0777);\n+\t\treturn mkdir(path, DIRECTORY_RW_ALL);\n \t}\n \n \tif (has_symlinks && S_ISLNK(mode))\n@@ -4111,7 +4112,8 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,\n \t\t */\n \t\treturn symlink(buf, path);\n \n-\tfd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666);\n+\tfd = open(path, O_CREAT | O_EXCL | O_WRONLY,\n+\t\t\t(mode & S_IXUSR) ? DIRECTORY_RW_ALL : FILE_RW_ALL);\n \tif (fd < 0)\n \t\treturn -1;\n \ndiff --git a/builtin/archive.c b/builtin/archive.c\nindex a1e3b94..2f4109a 100644\n--- a/builtin/archive.c\n+++ b/builtin/archive.c\n@@ -9,10 +9,12 @@\n #include \"parse-options.h\"\n #include \"pkt-line.h\"\n #include \"sideband.h\"\n+#include \"file-access.h\"\n \n static void create_output_file(const char *output_file)\n {\n-\tint output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);\n+\tint output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC,\n+\t\t\t\tFILE_RW_ALL);\n \tif (output_fd < 0)\n \t\tdie_errno(_(\"could not create archive file '%s'\"), output_file);\n \tif (output_fd != 1) {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 303a3a7..681fa71 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -24,6 +24,7 @@\n #include \"remote.h\"\n #include \"run-command.h\"\n #include \"connected.h\"\n+#include \"file-access.h\"\n \n /*\n  * Overall FIXMEs:\n@@ -305,7 +306,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,\n \tif (!dir)\n \t\tdie_errno(_(\"failed to open '%s'\"), src->buf);\n \n-\tif (mkdir(dest->buf, 0777)) {\n+\tif (mkdir(dest->buf, DIRECTORY_RW_ALL)) {\n \t\tif (errno != EEXIST)\n \t\t\tdie_errno(_(\"failed to create directory '%s'\"), dest->buf);\n \t\telse if (stat(dest->buf, &buf))\n@@ -350,7 +351,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,\n \t\t\t\tdie_errno(_(\"failed to create link '%s'\"), dest->buf);\n \t\t\toption_no_hardlinks = 1;\n \t\t}\n-\t\tif (copy_file_with_time(dest->buf, src->buf, 0666))\n+\t\tif (copy_file_with_time(dest->buf, src->buf, FILE_RW_ALL))\n \t\t\tdie_errno(_(\"failed to copy file to '%s'\"), dest->buf);\n \t}\n \tclosedir(dir);\n@@ -844,7 +845,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\tif (safe_create_leading_directories_const(work_tree) < 0)\n \t\t\tdie_errno(_(\"could not create leading directories of '%s'\"),\n \t\t\t\t  work_tree);\n-\t\tif (!dest_exists && mkdir(work_tree, 0777))\n+\t\tif (!dest_exists && mkdir(work_tree, DIRECTORY_RW_ALL))\n \t\t\tdie_errno(_(\"could not create work tree dir '%s'\"),\n \t\t\t\t  work_tree);\n \t\tjunk_work_tree = work_tree;\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 7188405..e918bdf 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -3,6 +3,7 @@\n #include \"color.h\"\n #include \"parse-options.h\"\n #include \"urlmatch.h\"\n+#include \"file-access.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\n@@ -576,7 +577,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tconfig_file = xstrdup(given_config_source.file ?\n \t\t\t\t      given_config_source.file : git_path(\"config\"));\n \t\tif (use_global_config) {\n-\t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);\n+\t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY,\n+\t\t\t\t\tFILE_RW_ALL);\n \t\t\tif (fd) {\n \t\t\t\tchar *content = default_user_config();\n \t\t\t\twrite_str_in_full(fd, content);\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 3f10840..833b39d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -11,6 +11,7 @@\n #include \"exec_cmd.h\"\n #include \"streaming.h\"\n #include \"thread-utils.h\"\n+#include \"file-access.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])\";\n@@ -308,7 +309,8 @@ static const char *open_pack_file(const char *pack_name)\n \t\t\t\t\t\t\"pack/tmp_pack_XXXXXX\");\n \t\t\tpack_name = xstrdup(tmp_file);\n \t\t} else\n-\t\t\toutput_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);\n+\t\t\toutput_fd = open(pack_name, O_CREAT | O_EXCL | O_RDWR,\n+\t\t\t\t\tFILE_RW_USER);\n \t\tif (output_fd < 0)\n \t\t\tdie_errno(_(\"unable to create '%s'\"), pack_name);\n \t\tnothread_data.pack_fd = output_fd;\n@@ -1397,7 +1399,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \t\tif (!keep_name)\n \t\t\tkeep_fd = odb_pack_keep(name, sizeof(name), sha1);\n \t\telse\n-\t\t\tkeep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);\n+\t\t\tkeep_fd = open(keep_name, O_RDWR | O_CREAT | O_EXCL,\n+\t\t\t\t\tFILE_RW_USER);\n \n \t\tif (keep_fd < 0) {\n \t\t\tif (errno != EEXIST)\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 49df78d..e3e5c35 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -8,6 +8,7 @@\n #include \"builtin.h\"\n #include \"exec_cmd.h\"\n #include \"parse-options.h\"\n+#include \"file-access.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n@@ -26,7 +27,7 @@ static const char *git_link;\n \n static void safe_create_dir(const char *dir, int share)\n {\n-\tif (mkdir(dir, 0777) < 0) {\n+\tif (mkdir(dir, DIRECTORY_RW_ALL) < 0) {\n \t\tif (errno != EEXIST) {\n \t\t\tperror(dir);\n \t\t\texit(1);\n@@ -542,7 +543,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t\tshared_repository = saved;\n-\t\t\t\tif (mkdir(argv[0], 0777) < 0)\n+\t\t\t\tif (mkdir(argv[0], DIRECTORY_RW_ALL) < 0)\n \t\t\t\t\tdie_errno(_(\"cannot mkdir %s\"), argv[0]);\n \t\t\t\tmkdir_tried = 1;\n \t\t\t\tgoto retry;\ndiff --git a/builtin/log.c b/builtin/log.c\nindex b50ef75..832343d 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -26,6 +26,7 @@\n #include \"version.h\"\n #include \"mailmap.h\"\n #include \"gpg-interface.h\"\n+#include \"file-access.h\"\n \n /* Set a default date-time format for git log (\"log.date\" config variable) */\n static const char *default_date_mode = NULL;\n@@ -1387,7 +1388,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tif (output_directory) {\n \t\tif (use_stdout)\n \t\t\tdie(_(\"standard output, or directory, which one?\"));\n-\t\tif (mkdir(output_directory, 0777) < 0 && errno != EEXIST)\n+\t\tif (mkdir(output_directory, DIRECTORY_RW_ALL) < 0 &&\n+\t\t\terrno != EEXIST)\n \t\t\tdie_errno(_(\"Could not create directory '%s'\"),\n \t\t\t\t  output_directory);\n \t}\ndiff --git a/builtin/mailsplit.c b/builtin/mailsplit.c\nindex 8e02ea1..3818860 100644\n--- a/builtin/mailsplit.c\n+++ b/builtin/mailsplit.c\n@@ -8,6 +8,7 @@\n #include \"builtin.h\"\n #include \"string-list.h\"\n #include \"strbuf.h\"\n+#include \"file-access.h\"\n \n static const char git_mailsplit_usage[] =\n \"git mailsplit [-d<prec>] [-f<n>] [-b] [--keep-cr] -o<directory> [(<mbox>|<Maildir>)...]\";\n@@ -62,7 +63,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)\n \t\tfprintf(stderr, \"corrupt mailbox\\n\");\n \t\texit(1);\n \t}\n-\tfd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\tfd = open(name, O_WRONLY | O_CREAT | O_EXCL, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(\"cannot open output file '%s'\", name);\n \toutput = xfdopen(fd, \"w\");\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 85c54dc..1a3a28e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -30,6 +30,7 @@\n #include \"fmt-merge-msg.h\"\n #include \"gpg-interface.h\"\n #include \"sequencer.h\"\n+#include \"file-access.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\n@@ -339,7 +340,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead\n \n \tprintf(_(\"Squash commit -- not updating HEAD\\n\"));\n \tfilename = git_path(\"SQUASH_MSG\");\n-\tfd = open(filename, O_WRONLY | O_CREAT, 0666);\n+\tfd = open(filename, O_WRONLY | O_CREAT, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(_(\"Could not write to '%s'\"), filename);\n \n@@ -755,7 +756,7 @@ static void add_strategies(const char *string, unsigned attr)\n static void write_merge_msg(struct strbuf *msg)\n {\n \tconst char *filename = git_path(\"MERGE_MSG\");\n-\tint fd = open(filename, O_WRONLY | O_CREAT, 0666);\n+\tint fd = open(filename, O_WRONLY | O_CREAT, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(_(\"Could not open '%s' for writing\"),\n \t\t\t  filename);\n@@ -968,7 +969,7 @@ static void write_merge_state(struct commit_list *remoteheads)\n \t\tstrbuf_addf(&buf, \"%s\\n\", sha1_to_hex(sha1));\n \t}\n \tfilename = git_path(\"MERGE_HEAD\");\n-\tfd = open(filename, O_WRONLY | O_CREAT, 0666);\n+\tfd = open(filename, O_WRONLY | O_CREAT, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(_(\"Could not open '%s' for writing\"), filename);\n \tif (write_in_full(fd, buf.buf, buf.len) != buf.len)\n@@ -978,7 +979,7 @@ static void write_merge_state(struct commit_list *remoteheads)\n \twrite_merge_msg(&merge_msg);\n \n \tfilename = git_path(\"MERGE_MODE\");\n-\tfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);\n+\tfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(_(\"Could not open '%s' for writing\"), filename);\n \tstrbuf_reset(&buf);\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 63f95fc..3119336 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -19,6 +19,7 @@\n #include \"string-list.h\"\n #include \"notes-merge.h\"\n #include \"notes-utils.h\"\n+#include \"file-access.h\"\n \n static const char * const git_notes_usage[] = {\n \tN_(\"git notes [--ref <notes-ref>] [list [<object>]]\"),\n@@ -168,7 +169,8 @@ static void prepare_note_data(const unsigned char *object, struct note_data *d,\n \n \t\t/* write the template message before editing: */\n \t\td->edit_path = git_pathdup(\"NOTES_EDITMSG\");\n-\t\tfd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n+\t\tfd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY,\n+\t\t\t\tFILE_RW_USER);\n \t\tif (fd < 0)\n \t\t\tdie_errno(_(\"could not create file '%s'\"), d->edit_path);\n \ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 6b3c469..70fe7b9 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -14,6 +14,7 @@\n #include \"parse-options.h\"\n #include \"run-command.h\"\n #include \"tag.h\"\n+#include \"file-access.h\"\n \n static const char * const git_replace_usage[] = {\n \tN_(\"git replace [-f] <object> <replacement>\"),\n@@ -203,7 +204,7 @@ static void export_object(const unsigned char *sha1, enum object_type type,\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n \tint fd;\n \n-\tfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);\n+\tfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(\"unable to open %s for writing\", filename);\n \ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex cccca99..c489ad1 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -17,6 +17,7 @@\n #include \"gpg-interface.h\"\n #include \"sha1-array.h\"\n #include \"column.h\"\n+#include \"file-access.h\"\n \n static const char * const git_tag_usage[] = {\n \tN_(\"git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<head>]\"),\n@@ -472,7 +473,7 @@ static void create_tag(const unsigned char *object, const char *tag,\n \n \t\t/* write the template message before editing: */\n \t\tpath = git_pathdup(\"TAG_EDITMSG\");\n-\t\tfd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n+\t\tfd = open(path, O_CREAT | O_TRUNC | O_WRONLY, FILE_RW_USER);\n \t\tif (fd < 0)\n \t\t\tdie_errno(_(\"could not create file '%s'\"), path);\n \ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 430b51e..c53d837 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -8,6 +8,7 @@\n #include \"run-command.h\"\n #include \"sigchain.h\"\n #include \"refs.h\"\n+#include \"file-access.h\"\n \n static const char * const worktree_usage[] = {\n \tN_(\"git worktree add [<options>] <path> <branch>\"),\n@@ -228,7 +229,7 @@ static int add_worktree(const char *path, const char *refname,\n \tatexit(remove_junk);\n \tsigchain_push_common(remove_junk_on_signal);\n \n-\tif (mkdir(sb_repo.buf, 0777))\n+\tif (mkdir(sb_repo.buf, DIRECTORY_RW_ALL))\n \t\tdie_errno(_(\"could not create directory of '%s'\"), sb_repo.buf);\n \tjunk_git_dir = xstrdup(sb_repo.buf);\n \tis_junk = 1;\ndiff --git a/cache.h b/cache.h\nindex 6bb7119..99e88e1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -9,6 +9,7 @@\n #include \"convert.h\"\n #include \"trace.h\"\n #include \"string-list.h\"\n+#include \"file-access.h\"\n \n #include SHA1_HEADER\n #ifndef git_SHA_CTX\n@@ -242,7 +243,8 @@ static inline unsigned create_ce_flags(unsigned stage)\n #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)\n #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)\n \n-#define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)\n+#define ce_permissions(mode) \\\n+\t(((mode) & S_IXUSR) ? DIRECTORY_RW_USER_R_ALL : FILE_RW_USER_R_ALL)\n static inline unsigned int create_ce_mode(unsigned int mode)\n {\n \tif (S_ISLNK(mode))\n@@ -261,7 +263,7 @@ static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,\n \tif (!trust_executable_bit && S_ISREG(mode)) {\n \t\tif (ce && S_ISREG(ce->ce_mode))\n \t\t\treturn ce->ce_mode;\n-\t\treturn create_ce_mode(0666);\n+\t\treturn create_ce_mode(FILE_RW_ALL);\n \t}\n \treturn create_ce_mode(mode);\n }\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 496e6f8..55e2aef 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -208,7 +208,7 @@ int mingw_unlink(const char *pathname)\n \t\treturn -1;\n \n \t/* read-only files cannot be removed */\n-\t_wchmod(wpathname, 0666);\n+\t_wchmod(wpathname, FILE_RW_ALL);\n \twhile ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {\n \t\tif (!is_file_in_use_error(GetLastError()))\n \t\t\tbreak;\n@@ -650,7 +650,7 @@ int mkstemp(char *template)\n \tchar *filename = mktemp(template);\n \tif (filename == NULL)\n \t\treturn -1;\n-\treturn open(filename, O_RDWR | O_CREAT, 0600);\n+\treturn open(filename, O_RDWR | O_CREAT, FILE_RW_USER);\n }\n \n int gettimeofday(struct timeval *tv, void *tz)\ndiff --git a/compat/stat.c b/compat/stat.c\nindex a2d3931..f040b25 100644\n--- a/compat/stat.c\n+++ b/compat/stat.c\n@@ -1,24 +1,23 @@\n-#define _POSIX_C_SOURCE 200112L\n-#include <sys/stat.h>  /* *stat, S_IS* */\n-#include <sys/types.h> /* mode_t       */\n+#include \"../file-access.h\"\n \n static inline mode_t mode_native_to_git(mode_t native_mode)\n {\n-\tmode_t perm_bits = native_mode & 07777;\n+\tmode_t perm_bits =\n+\t\tnative_mode & (S_ISUID | S_ISGID | S_ISVTX | DIRECTORY_RW_ALL);\n \tif (S_ISREG(native_mode))\n-\t\treturn 0100000 | perm_bits;\n+\t\treturn S_IFREG | perm_bits;\n \tif (S_ISDIR(native_mode))\n-\t\treturn 0040000 | perm_bits;\n+\t\treturn S_IFDIR | perm_bits;\n \tif (S_ISLNK(native_mode))\n-\t\treturn 0120000 | perm_bits;\n+\t\treturn S_IFLNK | perm_bits;\n \tif (S_ISBLK(native_mode))\n-\t\treturn 0060000 | perm_bits;\n+\t\treturn S_IFBLK | perm_bits;\n \tif (S_ISCHR(native_mode))\n-\t\treturn 0020000 | perm_bits;\n+\t\treturn S_IFCHR | perm_bits;\n \tif (S_ISFIFO(native_mode))\n-\t\treturn 0010000 | perm_bits;\n+\t\treturn S_IFIFO | perm_bits;\n \tif (S_ISSOCK(native_mode))\n-\t\treturn 0140000 | perm_bits;\n+\t\treturn S_IFSOCK | perm_bits;\n \t/* Non-standard type bits were given. */\n \treturn perm_bits;\n }\ndiff --git a/config.c b/config.c\nindex 9fd275f..1f01eb5 100644\n--- a/config.c\n+++ b/config.c\n@@ -13,6 +13,7 @@\n #include \"hashmap.h\"\n #include \"string-list.h\"\n #include \"utf8.h\"\n+#include \"file-access.h\"\n \n struct config_source {\n \tstruct config_source *prev;\n@@ -2066,7 +2067,9 @@ int git_config_set_multivar_in_file(const char *config_filename,\n \t\t}\n \t\tclose(in_fd);\n \n-\t\tif (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {\n+\t\tif (chmod(lock->filename.buf,\n+\t\t\tst.st_mode &\n+\t\t\t(S_ISUID | S_ISGID | S_ISVTX | DIRECTORY_RW_ALL)) < 0) {\n \t\t\terror(\"chmod on %s failed: %s\",\n \t\t\t\tlock->filename.buf, strerror(errno));\n \t\t\tret = CONFIG_NO_WRITE;\n@@ -2252,7 +2255,9 @@ int git_config_rename_section_in_file(const char *config_filename,\n \n \tfstat(fileno(config_file), &st);\n \n-\tif (chmod(lock->filename.buf, st.st_mode & 07777) < 0) {\n+\tif (chmod(lock->filename.buf,\n+\t\tst.st_mode &\n+\t\t(S_ISUID | S_ISGID | S_ISVTX | DIRECTORY_RW_ALL)) < 0) {\n \t\tret = error(\"chmod on %s failed: %s\",\n \t\t\t\tlock->filename.buf, strerror(errno));\n \t\tgoto out;\ndiff --git a/copy.c b/copy.c\nindex 574fa1f..c2116b9 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"file-access.h\"\n \n int copy_fd(int ifd, int ofd)\n {\n@@ -32,7 +33,8 @@ int copy_file(const char *dst, const char *src, int mode)\n {\n \tint fdi, fdo, status;\n \n-\tmode = (mode & 0111) ? 0777 : 0666;\n+\tmode = (mode & (S_IXUSR | S_IXGRP | S_IXOTH))\n+\t\t? DIRECTORY_RW_ALL : FILE_RW_ALL;\n \tif ((fdi = open(src, O_RDONLY)) < 0)\n \t\treturn fdi;\n \tif ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex 0320605..0f30018 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -16,6 +16,7 @@\n #include \"builtin.h\"\n #include \"string-list.h\"\n #include \"dir.h\"\n+#include \"file-access.h\"\n \n static int read_directory_contents(const char *path, struct string_list *list)\n {\n@@ -51,7 +52,7 @@ static int get_mode(const char *path, int *mode)\n \t\t*mode = 0;\n #endif\n \telse if (path == file_from_standard_input)\n-\t\t*mode = create_ce_mode(0666);\n+\t\t*mode = create_ce_mode(FILE_RW_ALL);\n \telse if (lstat(path, &st))\n \t\treturn error(\"Could not access '%s'\", path);\n \telse\ndiff --git a/entry.c b/entry.c\nindex 1eda8e9..f8359f1 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -2,6 +2,7 @@\n #include \"blob.h\"\n #include \"dir.h\"\n #include \"streaming.h\"\n+#include \"file-access.h\"\n \n static void create_directories(const char *path, int path_len,\n \t\t\t       const struct checkout *state)\n@@ -34,9 +35,10 @@ static void create_directories(const char *path, int path_len,\n \t\t * there, therefore we then try to unlink it and try\n \t\t * one more time to create the directory.\n \t\t */\n-\t\tif (mkdir(buf, 0777)) {\n+\t\tif (mkdir(buf, DIRECTORY_RW_ALL)) {\n \t\t\tif (errno == EEXIST && state->force &&\n-\t\t\t    !unlink_or_warn(buf) && !mkdir(buf, 0777))\n+\t\t\t    !unlink_or_warn(buf) &&\n+\t\t\t    !mkdir(buf, DIRECTORY_RW_ALL))\n \t\t\t\tcontinue;\n \t\t\tdie_errno(\"cannot create directory at '%s'\", buf);\n \t\t}\n@@ -75,7 +77,7 @@ static void remove_subtree(struct strbuf *path)\n \n static int create_file(const char *path, unsigned int mode)\n {\n-\tmode = (mode & 0100) ? 0777 : 0666;\n+\tmode = (mode & S_IXUSR) ? DIRECTORY_RW_ALL : FILE_RW_ALL;\n \treturn open(path, O_WRONLY | O_CREAT | O_EXCL, mode);\n }\n \n@@ -100,7 +102,7 @@ static int open_output_fd(char *path, const struct cache_entry *ce, int to_tempf\n \t\t       ? \".merge_link_XXXXXX\" : \".merge_file_XXXXXX\");\n \t\treturn mkstemp(path);\n \t} else {\n-\t\treturn create_file(path, !symlink ? ce->ce_mode : 0666);\n+\t\treturn create_file(path, !symlink ? ce->ce_mode : FILE_RW_ALL);\n \t}\n }\n \n@@ -201,7 +203,7 @@ static int write_entry(struct cache_entry *ce,\n \tcase S_IFGITLINK:\n \t\tif (to_tempfile)\n \t\t\treturn error(\"cannot create temporary submodule %s\", path);\n-\t\tif (mkdir(path, 0777) < 0)\n+\t\tif (mkdir(path, DIRECTORY_RW_ALL) < 0)\n \t\t\treturn error(\"cannot create submodule directory %s\", path);\n \t\tbreak;\n \tdefault:\ndiff --git a/fast-import.c b/fast-import.c\nindex 2ad4fee..b082b46 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -166,6 +166,7 @@ Format of STDIN stream:\n #include \"quote.h\"\n #include \"exec_cmd.h\"\n #include \"dir.h\"\n+#include \"file-access.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\n@@ -2303,11 +2304,11 @@ static void file_change_m(const char *p, struct branch *b)\n \tif (!p)\n \t\tdie(\"Corrupt mode: %s\", command_buf.buf);\n \tswitch (mode) {\n-\tcase 0644:\n-\tcase 0755:\n+\tcase FILE_RW_USER_R_ALL:\n+\tcase DIRECTORY_RW_USER_R_ALL:\n \t\tmode |= S_IFREG;\n-\tcase S_IFREG | 0644:\n-\tcase S_IFREG | 0755:\n+\tcase S_IFREG | FILE_RW_USER_R_ALL:\n+\tcase S_IFREG | DIRECTORY_RW_USER_R_ALL:\n \tcase S_IFLNK:\n \tcase S_IFDIR:\n \tcase S_IFGITLINK:\ndiff --git a/file-access.h b/file-access.h\nnew file mode 100644\nindex 0000000..ef5585e\n--- /dev/null\n+++ b/file-access.h\n@@ -0,0 +1,27 @@\n+#ifndef FILE_ACCESS_H\n+#define FILE_ACCESS_H\n+\n+#include <sys/stat.h>\n+\n+/* rwxr-xr-x (0755) */\n+#define DIRECTORY_RW_USER_R_ALL \\\n+\t(S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)\n+\n+/* rwxrwxrwx (0777) */\n+#define DIRECTORY_RW_ALL (S_IRWXU | S_IRWXG | S_IRWXO)\n+\n+/* rw------- (0600) */\n+#define FILE_RW_USER (S_IRUSR | S_IWUSR)\n+\n+/* rw-r--r-- (0644) */\n+#define FILE_RW_USER_R_ALL (FILE_RW_USER | S_IRGRP | S_IROTH)\n+\n+/* r--r--r-- (0444) */\n+#define FILE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH)\n+\n+/* rw-rw-rw- (0666) */\n+#define FILE_RW_ALL (FILE_RW_USER | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)\n+\n+#endif /* FILE_ACCESS_H */\n+\n+/* vim: set ts=8 sw=8 noet */\ndiff --git a/http.c b/http.c\nindex e9c6fdd..ef0dc2b 100644\n--- a/http.c\n+++ b/http.c\n@@ -9,6 +9,7 @@\n #include \"version.h\"\n #include \"pkt-line.h\"\n #include \"gettext.h\"\n+#include \"file-access.h\"\n \n int active_requests;\n int http_is_verbose;\n@@ -1643,7 +1644,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \tif (freq->localfile != -1)\n \t\terror(\"fd leakage in start: %d\", freq->localfile);\n \tfreq->localfile = open(freq->tmpfile,\n-\t\t\t       O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\t\t\t       O_WRONLY | O_CREAT | O_EXCL, FILE_RW_ALL);\n \t/*\n \t * This could have failed due to the \"lazy directory creation\";\n \t * try to mkdir the last path component.\n@@ -1652,11 +1653,12 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \t\tchar *dir = strrchr(freq->tmpfile, '/');\n \t\tif (dir) {\n \t\t\t*dir = 0;\n-\t\t\tmkdir(freq->tmpfile, 0777);\n+\t\t\tmkdir(freq->tmpfile, DIRECTORY_RW_ALL);\n \t\t\t*dir = '/';\n \t\t}\n \t\tfreq->localfile = open(freq->tmpfile,\n-\t\t\t\t       O_WRONLY | O_CREAT | O_EXCL, 0666);\n+\t\t\t\t\tO_WRONLY | O_CREAT | O_EXCL,\n+\t\t\t\t\tFILE_RW_ALL);\n \t}\n \n \tif (freq->localfile < 0) {\ndiff --git a/lockfile.c b/lockfile.c\nindex 993bb82..5abd046 100644\n--- a/lockfile.c\n+++ b/lockfile.c\n@@ -4,6 +4,7 @@\n #include \"cache.h\"\n #include \"lockfile.h\"\n #include \"sigchain.h\"\n+#include \"file-access.h\"\n \n static struct lock_file *volatile lock_file_list;\n \n@@ -140,7 +141,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)\n \t}\n \n \tstrbuf_addstr(&lk->filename, LOCK_SUFFIX);\n-\tlk->fd = open(lk->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);\n+\tlk->fd = open(lk->filename.buf, O_RDWR | O_CREAT | O_EXCL, FILE_RW_ALL);\n \tif (lk->fd < 0) {\n \t\tstrbuf_reset(&lk->filename);\n \t\treturn -1;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 44d85be..60e355e 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -22,6 +22,7 @@\n #include \"merge-recursive.h\"\n #include \"dir.h\"\n #include \"submodule.h\"\n+#include \"file-access.h\"\n \n static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \t\t\t\t      const char *subtree_shift)\n@@ -779,10 +780,10 @@ static void update_file_flags(struct merge_options *o,\n \t\t}\n \t\tif (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {\n \t\t\tint fd;\n-\t\t\tif (mode & 0100)\n-\t\t\t\tmode = 0777;\n+\t\t\tif (mode & S_IXUSR)\n+\t\t\t\tmode = DIRECTORY_RW_ALL;\n \t\t\telse\n-\t\t\t\tmode = 0666;\n+\t\t\t\tmode = FILE_RW_ALL;\n \t\t\tfd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);\n \t\t\tif (fd < 0)\n \t\t\t\tdie_errno(_(\"failed to open '%s'\"), path);\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 0b2b82c..014d14c 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -10,6 +10,7 @@\n #include \"notes-merge.h\"\n #include \"strbuf.h\"\n #include \"notes-utils.h\"\n+#include \"file-access.h\"\n \n struct notes_merge_pair {\n \tunsigned char obj[20], base[20], local[20], remote[20];\n@@ -301,7 +302,7 @@ static void write_buf_to_worktree(const unsigned char *obj,\n \tif (file_exists(path))\n \t\tdie(\"found existing file at '%s'\", path);\n \n-\tfd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0666);\n+\tfd = open(path, O_WRONLY | O_TRUNC | O_CREAT, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(\"failed to open '%s'\", path);\n \ndiff --git a/refs.c b/refs.c\nindex 2db2975..294d521 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -5,6 +5,7 @@\n #include \"tag.h\"\n #include \"dir.h\"\n #include \"string-list.h\"\n+#include \"file-access.h\"\n \n struct ref_lock {\n \tchar *ref_name;\n@@ -3163,7 +3164,7 @@ static int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct\n \t\toflags |= O_CREAT;\n \t}\n \n-\tlogfd = open(logfile, oflags, 0666);\n+\tlogfd = open(logfile, oflags, FILE_RW_ALL);\n \tif (logfd < 0) {\n \t\tif (!(oflags & O_CREAT) && (errno == ENOENT || errno == EISDIR))\n \t\t\treturn 0;\n@@ -3174,7 +3175,7 @@ static int log_ref_setup(const char *refname, struct strbuf *sb_logfile, struct\n \t\t\t\t\t    \"'%s'\", logfile);\n \t\t\t\treturn -1;\n \t\t\t}\n-\t\t\tlogfd = open(logfile, oflags, 0666);\n+\t\t\tlogfd = open(logfile, oflags, FILE_RW_ALL);\n \t\t}\n \n \t\tif (logfd < 0) {\n@@ -3406,7 +3407,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,\n \t\tgoto error_free_return;\n \t}\n \tlockpath = mkpath(\"%s.lock\", git_HEAD);\n-\tfd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);\n+\tfd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, FILE_RW_ALL);\n \tif (fd < 0) {\n \t\terror(\"Unable to open %s for writing\", lockpath);\n \t\tgoto error_free_return;\ndiff --git a/rerere.c b/rerere.c\nindex 94aea9a..af225c0 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -8,6 +8,7 @@\n #include \"ll-merge.h\"\n #include \"attr.h\"\n #include \"pathspec.h\"\n+#include \"file-access.h\"\n \n #define RESOLVED 0\n #define PUNTED 1\n@@ -559,7 +560,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)\n \t\t\tcontinue;\n \n \t\tfprintf(stderr, \"Recorded resolution for '%s'.\\n\", path);\n-\t\tcopy_file(rerere_path(name, \"postimage\"), path, 0666);\n+\t\tcopy_file(rerere_path(name, \"postimage\"), path, FILE_RW_ALL);\n \tmark_resolved:\n \t\trr->items[i].util = NULL;\n \t}\ndiff --git a/sequencer.c b/sequencer.c\nindex c4f4b7d..375c032 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -15,6 +15,7 @@\n #include \"merge-recursive.h\"\n #include \"refs.h\"\n #include \"argv-array.h\"\n+#include \"file-access.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \n@@ -167,7 +168,7 @@ static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)\n \tstrbuf_addf(&buf, \"%s\\n\", sha1_to_hex(commit->object.sha1));\n \n \tfilename = git_path(\"%s\", pseudoref);\n-\tfd = open(filename, O_WRONLY | O_CREAT, 0666);\n+\tfd = open(filename, O_WRONLY | O_CREAT, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tdie_errno(_(\"Could not open '%s' for writing\"), filename);\n \tif (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd))\n@@ -843,7 +844,7 @@ static int create_seq_dir(void)\n \t\tadvise(_(\"try \\\"git cherry-pick (--continue | --quit | --abort)\\\"\"));\n \t\treturn -1;\n \t}\n-\telse if (mkdir(seq_dir, 0777) < 0)\n+\telse if (mkdir(seq_dir, DIRECTORY_RW_ALL) < 0)\n \t\tdie_errno(_(\"Could not create sequencer directory %s\"), seq_dir);\n \treturn 0;\n }\ndiff --git a/server-info.c b/server-info.c\nindex c82e9ee..86d13bf 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -3,6 +3,7 @@\n #include \"object.h\"\n #include \"commit.h\"\n #include \"tag.h\"\n+#include \"file-access.h\"\n \n /*\n  * Create the file \"path\" by writing to a temporary file and renaming\n@@ -17,7 +18,7 @@ static int update_info_file(char *path, int (*generate)(FILE *))\n \tFILE *fp = NULL;\n \n \tsafe_create_leading_directories(path);\n-\tfd = git_mkstemp_mode(tmp, 0666);\n+\tfd = git_mkstemp_mode(tmp, FILE_RW_ALL);\n \tif (fd < 0)\n \t\tgoto out;\n \tfp = fdopen(fd, \"w\");\ndiff --git a/setup.c b/setup.c\nindex 5f9f07d..ac1c6ea 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n #include \"dir.h\"\n #include \"string-list.h\"\n+#include \"file-access.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\n@@ -915,7 +916,7 @@ int git_config_perm(const char *var, const char *value)\n \n \t/* A filemode value was given: 0xxx */\n \n-\tif ((i & 0600) != 0600)\n+\tif ((i & FILE_RW_USER) != FILE_RW_USER)\n \t\tdie(\"Problem with core.sharedRepository filemode value \"\n \t\t    \"(0%.3o).\\nThe owner of files must always have \"\n \t\t    \"read and write permissions.\", i);\n@@ -924,7 +925,7 @@ int git_config_perm(const char *var, const char *value)\n \t * Mask filemode value. Others can not get write permission.\n \t * x flags for directories are handled separately.\n \t */\n-\treturn -(i & 0666);\n+\treturn -(i & FILE_RW_ALL);\n }\n \n int check_repository_format_version(const char *var, const char *value, void *cb)\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 1cee438..db4052d 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -23,6 +23,7 @@\n #include \"bulk-checkin.h\"\n #include \"streaming.h\"\n #include \"dir.h\"\n+#include \"file-access.h\"\n \n #ifndef O_NOATIME\n #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))\n@@ -82,7 +83,7 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)\n \n int mkdir_in_gitdir(const char *path)\n {\n-\tif (mkdir(path, 0777)) {\n+\tif (mkdir(path, DIRECTORY_RW_ALL)) {\n \t\tint saved_errno = errno;\n \t\tstruct stat st;\n \t\tstruct strbuf sb = STRBUF_INIT;\n@@ -99,7 +100,7 @@ int mkdir_in_gitdir(const char *path)\n \t\tif (lstat(path, &st) || !S_ISLNK(st.st_mode) ||\n \t\t    strbuf_readlink(&sb, path, st.st_size) ||\n \t\t    !is_absolute_path(sb.buf) ||\n-\t\t    mkdir(sb.buf, 0777)) {\n+\t\t    mkdir(sb.buf, DIRECTORY_RW_ALL)) {\n \t\t\tstrbuf_release(&sb);\n \t\t\terrno = saved_errno;\n \t\t\treturn -1;\n@@ -136,7 +137,7 @@ enum scld_error safe_create_leading_directories(char *path)\n \t\t\t/* path exists */\n \t\t\tif (!S_ISDIR(st.st_mode))\n \t\t\t\tret = SCLD_EXISTS;\n-\t\t} else if (mkdir(path, 0777)) {\n+\t\t} else if (mkdir(path, DIRECTORY_RW_ALL)) {\n \t\t\tif (errno == EEXIST &&\n \t\t\t    !stat(path, &st) && S_ISDIR(st.st_mode))\n \t\t\t\t; /* somebody created it since we checked */\n@@ -3003,19 +3004,19 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)\n \t}\n \tmemcpy(buffer, filename, dirlen);\n \tstrcpy(buffer + dirlen, \"tmp_obj_XXXXXX\");\n-\tfd = git_mkstemp_mode(buffer, 0444);\n+\tfd = git_mkstemp_mode(buffer, FILE_R_ALL);\n \tif (fd < 0 && dirlen && errno == ENOENT) {\n \t\t/* Make sure the directory exists */\n \t\tmemcpy(buffer, filename, dirlen);\n \t\tbuffer[dirlen-1] = 0;\n-\t\tif (mkdir(buffer, 0777) && errno != EEXIST)\n+\t\tif (mkdir(buffer, DIRECTORY_RW_ALL) && errno != EEXIST)\n \t\t\treturn -1;\n \t\tif (adjust_shared_perm(buffer))\n \t\t\treturn -1;\n \n \t\t/* Try again */\n \t\tstrcpy(buffer + dirlen - 1, \"/tmp_obj_XXXXXX\");\n-\t\tfd = git_mkstemp_mode(buffer, 0444);\n+\t\tfd = git_mkstemp_mode(buffer, FILE_R_ALL);\n \t}\n \treturn fd;\n }\ndiff --git a/test-delta.c b/test-delta.c\nindex 4595cd6..faf1d67 100644\n--- a/test-delta.c\n+++ b/test-delta.c\n@@ -11,6 +11,7 @@\n #include \"git-compat-util.h\"\n #include \"delta.h\"\n #include \"cache.h\"\n+#include \"file-access.h\"\n \n static const char usage_str[] =\n \t\"test-delta (-d|-p) <from_file> <data_file> <out_file>\";\n@@ -68,7 +69,7 @@ int main(int argc, char *argv[])\n \t\treturn 1;\n \t}\n \n-\tfd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);\n+\tfd = open (argv[4], O_WRONLY | O_CREAT | O_TRUNC, FILE_RW_ALL);\n \tif (fd < 0 || write_in_full(fd, out_buf, out_size) != out_size) {\n \t\tperror(argv[4]);\n \t\treturn 1;\ndiff --git a/trace.c b/trace.c\nindex 7393926..da312a5 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -24,6 +24,7 @@\n \n #include \"cache.h\"\n #include \"quote.h\"\n+#include \"file-access.h\"\n \n /* Get a trace file descriptor from \"key\" env variable. */\n static int get_trace_fd(struct trace_key *key)\n@@ -49,7 +50,8 @@ static int get_trace_fd(struct trace_key *key)\n \telse if (strlen(trace) == 1 && isdigit(*trace))\n \t\tkey->fd = atoi(trace);\n \telse if (is_absolute_path(trace)) {\n-\t\tint fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);\n+\t\tint fd = open(trace, O_WRONLY | O_APPEND | O_CREAT,\n+\t\t\t\tFILE_RW_ALL);\n \t\tif (fd == -1) {\n \t\t\tfprintf(stderr,\n \t\t\t\t\"Could not open '%s' for tracing: %s\\n\"\ndiff --git a/wrapper.c b/wrapper.c\nindex e451463..33c394b 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -2,6 +2,7 @@\n  * Various trivial helper wrappers around standard functions\n  */\n #include \"cache.h\"\n+#include \"file-access.h\"\n \n static void do_nothing(size_t size)\n {\n@@ -625,7 +626,7 @@ int write_file(const char *path, int fatal, const char *fmt, ...)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n \tva_list params;\n-\tint fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);\n+\tint fd = open(path, O_RDWR | O_CREAT | O_TRUNC, FILE_RW_ALL);\n \tif (fd < 0) {\n \t\tif (fatal)\n \t\t\tdie_errno(_(\"could not open %s for writing\"), path);\n-- \n2.1.4\n"}]}