]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/index-pack-lsan-false-positive-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Jan 2024 18:11:58 +0000 (10:11 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jan 2024 18:11:58 +0000 (10:11 -0800)
Fix false positive reported by leak sanitizer.

* jk/index-pack-lsan-false-positive-fix:
  index-pack: spawn threads atomically

1  2 
builtin/index-pack.c

diff --combined builtin/index-pack.c
index 0841b6940a3ddf5c71beba29d092881b3fd8b044,00c756df5d4b61950760594e575a7d35dec3dbc6..1ea87e01f2905ed70e3a17a847278ec2b7b68ec3
@@@ -1,27 -1,20 +1,27 @@@
  #include "builtin.h"
  #include "config.h"
  #include "delta.h"
 +#include "environment.h"
 +#include "gettext.h"
 +#include "hex.h"
  #include "pack.h"
  #include "csum-file.h"
  #include "blob.h"
  #include "commit.h"
 -#include "tag.h"
  #include "tree.h"
  #include "progress.h"
  #include "fsck.h"
 -#include "exec-cmd.h"
 +#include "strbuf.h"
  #include "streaming.h"
  #include "thread-utils.h"
  #include "packfile.h"
 -#include "object-store.h"
 +#include "pack-revindex.h"
 +#include "object-file.h"
 +#include "object-store-ll.h"
 +#include "oid-array.h"
 +#include "replace-object.h"
  #include "promisor-remote.h"
 +#include "setup.h"
  
  static const char index_pack_usage[] =
  "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
@@@ -219,8 -212,7 +219,8 @@@ static void cleanup_thread(void
  }
  
  static int mark_link(struct object *obj, enum object_type type,
 -                   void *data, struct fsck_options *options)
 +                   void *data UNUSED,
 +                   struct fsck_options *options UNUSED)
  {
        if (!obj)
                return -1;
@@@ -809,8 -801,7 +809,8 @@@ static void sha1_object(const void *dat
        if (startup_info->have_repository) {
                read_lock();
                collision_test_needed =
 -                      has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
 +                      repo_has_object_file_with_flags(the_repository, oid,
 +                                                      OBJECT_INFO_QUICK);
                read_unlock();
        }
  
                        die(_("cannot read existing object info %s"), oid_to_hex(oid));
                if (has_type != type || has_size != size)
                        die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
 -              has_data = read_object_file(oid, &has_type, &has_size);
 +              has_data = repo_read_object_file(the_repository, oid,
 +                                               &has_type, &has_size);
                read_unlock();
                if (!data)
                        data = new_data = get_data_from_pack(obj_entry);
@@@ -1164,7 -1154,6 +1164,7 @@@ static void parse_pack_objects(unsigne
        struct ofs_delta_entry *ofs_delta = ofs_deltas;
        struct object_id ref_delta_oid;
        struct stat st;
 +      git_hash_ctx tmp_ctx;
  
        if (verbose)
                progress = start_progress(
  
        /* Check pack integrity */
        flush();
 -      the_hash_algo->final_fn(hash, &input_ctx);
 +      the_hash_algo->init_fn(&tmp_ctx);
 +      the_hash_algo->clone_fn(&tmp_ctx, &input_ctx);
 +      the_hash_algo->final_fn(hash, &tmp_ctx);
        if (!hasheq(fill(the_hash_algo->rawsz), hash))
                die(_("pack is corrupted (SHA1 mismatch)"));
        use(the_hash_algo->rawsz);
@@@ -1255,6 -1242,7 +1255,7 @@@ static void resolve_deltas(void
        base_cache_limit = delta_base_cache_limit * nr_threads;
        if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
                init_thread();
+               work_lock();
                for (i = 0; i < nr_threads; i++) {
                        int ret = pthread_create(&thread_data[i].thread, NULL,
                                                 threaded_second_pass, thread_data + i);
                                die(_("unable to create thread: %s"),
                                    strerror(ret));
                }
+               work_unlock();
                for (i = 0; i < nr_threads; i++)
                        pthread_join(thread_data[i].thread, NULL);
                cleanup_thread();
@@@ -1401,7 -1390,7 +1403,7 @@@ static void fix_unresolved_deltas(struc
                sorted_by_pos[i] = &ref_deltas[i];
        QSORT(sorted_by_pos, nr_ref_deltas, delta_pos_compare);
  
 -      if (has_promisor_remote()) {
 +      if (repo_has_promisor_remote(the_repository)) {
                /*
                 * Prefetch the delta bases.
                 */
  
                if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
                        continue;
 -              data = read_object_file(&d->oid, &type, &size);
 +              data = repo_read_object_file(the_repository, &d->oid, &type,
 +                                           &size);
                if (!data)
                        continue;
  
@@@ -1582,19 -1570,18 +1584,19 @@@ static void final(const char *final_pac
        strbuf_release(&pack_name);
  }
  
 -static int git_index_pack_config(const char *k, const char *v, void *cb)
 +static int git_index_pack_config(const char *k, const char *v,
 +                               const struct config_context *ctx, void *cb)
  {
        struct pack_idx_option *opts = cb;
  
        if (!strcmp(k, "pack.indexversion")) {
 -              opts->version = git_config_int(k, v);
 +              opts->version = git_config_int(k, v, ctx->kvi);
                if (opts->version > 2)
                        die(_("bad pack.indexVersion=%"PRIu32), opts->version);
                return 0;
        }
        if (!strcmp(k, "pack.threads")) {
 -              nr_threads = git_config_int(k, v);
 +              nr_threads = git_config_int(k, v, ctx->kvi);
                if (nr_threads < 0)
                        die(_("invalid number of threads specified (%d)"),
                            nr_threads);
                else
                        opts->flags &= ~WRITE_REV;
        }
 -      return git_default_config(k, v, cb);
 +      return git_default_config(k, v, ctx, cb);
  }
  
  static int cmp_uint32(const void *a_, const void *b_)
@@@ -1754,17 -1741,16 +1756,17 @@@ int cmd_index_pack(int argc, const cha
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(index_pack_usage);
  
 -      read_replace_refs = 0;
 +      disable_replace_refs();
        fsck_options.walk = mark_link;
  
        reset_pack_idx_option(&opts);
 +      opts.flags |= WRITE_REV;
        git_config(git_index_pack_config, &opts);
        if (prefix && chdir(prefix))
                die(_("Cannot come back to cwd"));
  
 -      if (git_env_bool(GIT_TEST_WRITE_REV_INDEX, 0))
 -              rev_index = 1;
 +      if (git_env_bool(GIT_TEST_NO_WRITE_REV_INDEX, 0))
 +              rev_index = 0;
        else
                rev_index = !!(opts.flags & (WRITE_REV_VERIFY | WRITE_REV));