Merge branch 'cc/shared-index-permfix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 5 Jul 2017 20:32:57 +0000 (13:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Jul 2017 20:32:57 +0000 (13:32 -0700)
The split index code did not honor core.sharedrepository setting
correctly.

* cc/shared-index-permfix:
t1700: make sure split-index respects core.sharedrepository
t1301: move modebits() to test-lib-functions.sh
read-cache: use shared perms when writing shared index

1  2 
read-cache.c
diff --combined read-cache.c
index 3c4354ee21c898813e3fdbecf82a5e703e3f1b5e,6238df448f8d7954b28630749336eceab70c67f3..2121b6e7bba5f310825e0b1f2eccd524cc8658ce
@@@ -5,7 -5,6 +5,7 @@@
   */
  #define NO_THE_INDEX_COMPATIBILITY_MACROS
  #include "cache.h"
 +#include "config.h"
  #include "tempfile.h"
  #include "lockfile.h"
  #include "cache-tree.h"
@@@ -1895,7 -1894,8 +1895,7 @@@ int discard_index(struct index_state *i
        free_name_hash(istate);
        cache_tree_free(&(istate->cache_tree));
        istate->initialized = 0;
 -      free(istate->cache);
 -      istate->cache = NULL;
 +      FREE_AND_NULL(istate->cache);
        istate->cache_alloc = 0;
        discard_split_index(istate);
        free_untracked_cache(istate->untracked);
@@@ -2198,7 -2198,6 +2198,7 @@@ static int do_write_index(struct index_
        int entries = istate->cache_nr;
        struct stat st;
        struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
 +      int drop_cache_tree = 0;
  
        for (i = removed = extended = 0; i < entries; i++) {
                if (cache[i]->ce_flags & CE_REMOVE)
                                warning(msg, ce->name);
                        else
                                return error(msg, ce->name);
 +
 +                      drop_cache_tree = 1;
                }
                if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
                        return -1;
                if (err)
                        return -1;
        }
 -      if (!strip_extensions && istate->cache_tree) {
 +      if (!strip_extensions && !drop_cache_tree && istate->cache_tree) {
                struct strbuf sb = STRBUF_INIT;
  
                cache_tree_write(&sb, istate->cache_tree);
@@@ -2431,6 -2428,14 +2431,14 @@@ static int write_shared_index(struct in
                delete_tempfile(&temporary_sharedindex);
                return ret;
        }
+       ret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));
+       if (ret) {
+               int save_errno = errno;
+               error("cannot fix permission bits on %s", get_tempfile_path(&temporary_sharedindex));
+               delete_tempfile(&temporary_sharedindex);
+               errno = save_errno;
+               return ret;
+       }
        ret = rename_tempfile(&temporary_sharedindex,
                              git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
        if (!ret) {
@@@ -2609,7 -2614,8 +2617,7 @@@ void *read_blob_data_from_index(const s
  
  void stat_validity_clear(struct stat_validity *sv)
  {
 -      free(sv->sd);
 -      sv->sd = NULL;
 +      FREE_AND_NULL(sv->sd);
  }
  
  int stat_validity_check(struct stat_validity *sv, const char *path)
@@@ -2635,9 -2641,3 +2643,9 @@@ void stat_validity_update(struct stat_v
                fill_stat_data(sv->sd, &st);
        }
  }
 +
 +void move_index_extensions(struct index_state *dst, struct index_state *src)
 +{
 +      dst->untracked = src->untracked;
 +      src->untracked = NULL;
 +}