packaging: Add contrib installation
[platform/upstream/git.git] / read-cache.c
index 133f790..29144cf 100644 (file)
@@ -89,8 +89,10 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)
        else
                pool_ptr = &istate->ce_mem_pool;
 
-       if (!*pool_ptr)
-               mem_pool_init(pool_ptr, 0);
+       if (!*pool_ptr) {
+               *pool_ptr = xmalloc(sizeof(**pool_ptr));
+               mem_pool_init(*pool_ptr, 0);
+       }
 
        return *pool_ptr;
 }
@@ -959,11 +961,14 @@ static int verify_dotfile(const char *rest, unsigned mode)
 
 int verify_path(const char *path, unsigned mode)
 {
-       char c;
+       char c = 0;
 
        if (has_dos_drive_prefix(path))
                return 0;
 
+       if (!is_valid_path(path))
+               return 0;
+
        goto inside;
        for (;;) {
                if (!c)
@@ -971,6 +976,7 @@ int verify_path(const char *path, unsigned mode)
                if (is_dir_sep(c)) {
 inside:
                        if (protect_hfs) {
+
                                if (is_hfs_dotgit(path))
                                        return 0;
                                if (S_ISLNK(mode)) {
@@ -979,6 +985,10 @@ inside:
                                }
                        }
                        if (protect_ntfs) {
+#ifdef GIT_WINDOWS_NATIVE
+                               if (c == '\\')
+                                       return 0;
+#endif
                                if (is_ntfs_dotgit(path))
                                        return 0;
                                if (S_ISLNK(mode)) {
@@ -991,7 +1001,15 @@ inside:
                        if ((c == '.' && !verify_dotfile(path, mode)) ||
                            is_dir_sep(c) || c == '\0')
                                return 0;
+               } else if (c == '\\' && protect_ntfs) {
+                       if (is_ntfs_dotgit(path))
+                               return 0;
+                       if (S_ISLNK(mode)) {
+                               if (is_ntfs_dotgitmodules(path))
+                                       return 0;
+                       }
                }
+
                c = *path++;
        }
 }
@@ -1155,20 +1173,6 @@ static int has_dir_name(struct index_state *istate,
                                return retval;
                        }
 
-                       if (istate->cache_nr > 0 &&
-                               ce_namelen(istate->cache[istate->cache_nr - 1]) > len) {
-                               /*
-                                * The directory prefix lines up with part of
-                                * a longer file or directory name, but sorts
-                                * after it, so this sub-directory cannot
-                                * collide with a file.
-                                *
-                                * last: xxx/yy-file (because '-' sorts before '/')
-                                * this: xxx/yy/abc
-                                */
-                               return retval;
-                       }
-
                        /*
                         * This is a possible collision. Fall through and
                         * let the regular search code handle it.
@@ -1790,7 +1794,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
                const unsigned char *cp = (const unsigned char *)name;
                size_t strip_len, previous_len;
 
-               /* If we're at the begining of a block, ignore the previous name */
+               /* If we're at the beginning of a block, ignore the previous name */
                strip_len = decode_varint(&cp);
                if (previous_ce) {
                        previous_len = previous_ce->ce_namelen;
@@ -2004,11 +2008,12 @@ static unsigned long load_all_cache_entries(struct index_state *istate,
 {
        unsigned long consumed;
 
+       istate->ce_mem_pool = xmalloc(sizeof(*istate->ce_mem_pool));
        if (istate->version == 4) {
-               mem_pool_init(&istate->ce_mem_pool,
+               mem_pool_init(istate->ce_mem_pool,
                                estimate_cache_size_from_compressed(istate->cache_nr));
        } else {
-               mem_pool_init(&istate->ce_mem_pool,
+               mem_pool_init(istate->ce_mem_pool,
                                estimate_cache_size(mmap_size, istate->cache_nr));
        }
 
@@ -2068,7 +2073,8 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con
        if (istate->name_hash_initialized)
                BUG("the name hash isn't thread safe");
 
-       mem_pool_init(&istate->ce_mem_pool, 0);
+       istate->ce_mem_pool = xmalloc(sizeof(*istate->ce_mem_pool));
+       mem_pool_init(istate->ce_mem_pool, 0);
 
        /* ensure we have no more threads than we have blocks to process */
        if (nr_threads > ieot->nr)
@@ -2095,11 +2101,12 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con
                nr = 0;
                for (j = p->ieot_start; j < p->ieot_start + p->ieot_blocks; j++)
                        nr += p->ieot->entries[j].nr;
+               p->ce_mem_pool = xmalloc(sizeof(*istate->ce_mem_pool));
                if (istate->version == 4) {
-                       mem_pool_init(&p->ce_mem_pool,
+                       mem_pool_init(p->ce_mem_pool,
                                estimate_cache_size_from_compressed(nr));
                } else {
-                       mem_pool_init(&p->ce_mem_pool,
+                       mem_pool_init(p->ce_mem_pool,
                                estimate_cache_size(mmap_size, nr));
                }
 
@@ -2356,7 +2363,7 @@ int discard_index(struct index_state *istate)
 
        if (istate->ce_mem_pool) {
                mem_pool_discard(istate->ce_mem_pool, should_validate_cache_entries());
-               istate->ce_mem_pool = NULL;
+               FREE_AND_NULL(istate->ce_mem_pool);
        }
 
        return 0;
@@ -3007,10 +3014,10 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
        if (ce_flush(&c, newfd, istate->oid.hash))
                return -1;
        if (close_tempfile_gently(tempfile)) {
-               error(_("could not close '%s'"), tempfile->filename.buf);
+               error(_("could not close '%s'"), get_tempfile_path(tempfile));
                return -1;
        }
-       if (stat(tempfile->filename.buf, &st))
+       if (stat(get_tempfile_path(tempfile), &st))
                return -1;
        istate->timestamp.sec = (unsigned int)st.st_mtime;
        istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -3051,10 +3058,10 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
         * that is associated with the given "istate".
         */
        trace2_region_enter_printf("index", "do_write_index", the_repository,
-                                  "%s", lock->tempfile->filename.buf);
+                                  "%s", get_lock_file_path(lock));
        ret = do_write_index(istate, lock->tempfile, 0);
        trace2_region_leave_printf("index", "do_write_index", the_repository,
-                                  "%s", lock->tempfile->filename.buf);
+                                  "%s", get_lock_file_path(lock));
 
        if (ret)
                return ret;
@@ -3151,10 +3158,10 @@ static int write_shared_index(struct index_state *istate,
        move_cache_to_base_index(istate);
 
        trace2_region_enter_printf("index", "shared/do_write_index",
-                                  the_repository, "%s", (*temp)->filename.buf);
+                                  the_repository, "%s", get_tempfile_path(*temp));
        ret = do_write_index(si->base, *temp, 1);
        trace2_region_leave_printf("index", "shared/do_write_index",
-                                  the_repository, "%s", (*temp)->filename.buf);
+                                  the_repository, "%s", get_tempfile_path(*temp));
 
        if (ret)
                return ret;