From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 225181F576 for ; Sat, 3 Mar 2018 11:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbeCCLh1 (ORCPT ); Sat, 3 Mar 2018 06:37:27 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:41973 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbeCCLh0 (ORCPT ); Sat, 3 Mar 2018 06:37:26 -0500 Received: by mail-pf0-f193.google.com with SMTP id f80so5137336pfa.8 for ; Sat, 03 Mar 2018 03:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hTVySUJAIc/pfGwgp88OuPGr2oAsycTuBYplpcZXrn0=; b=nef8xyNU00oDqAWjSrlZofw6L8iYPgwwMfpgRpQrw2jtwecvgykNyqYZyH4wQtu/in j4xWXsUZ1J7nMAzGQJmGOEvqHePkZ8LY1Z7wmqosllX5/+JW+8bRhCmEsH+vDl0mo6Gb gWpCyHQ1x8hX1sY3+9kh6rPCcPeLy1h1s89obyq4B2H/xDNPgxDNYg7z8N/vh3/cRtRV c7zkn7JTToSkErpA7YxL4JUCspLzrZEEsCGyxYT6z2pBJivkfmB3KwcS5HWP+5dPe++c fzcGzMjblN9T5tr6hMUamkP/vVyyKM0JSOnyyCA7EKUf42vI4MDGcCHlhrWnxC/kwswa ANaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hTVySUJAIc/pfGwgp88OuPGr2oAsycTuBYplpcZXrn0=; b=Fpx5N76A2JqSdU3MDZyruy4I3FRrvLJ/EoJXTW9cLpfM6xfRClwb49KsNeFjAnCAK3 kGBSWrmJwvMGtvxxAAE9LjgGShwTfCIVfIbyPp3SYlLomb1uAvxiFUi+jLh/Z8A5JhoD Fqbo541GX+BqmNGsz+4cLPkvQVB/vmpnz3wVfcSe6OSuiO9EMB6xWB/8k9tOA/XLc7oa 4NkB4qrJ4Ht8skaJ/W2atCf/WbQeo01FtExyZeUsH4vwlX6SaHs5rX4pFR/MekGZ+4Qz SfD6pfu+yK8XfQPnB+c8qNczdmBYkGXusOPinLBpbAHY+YhzPL1ZBXiDs3ln6JMAzkbW IbOQ== X-Gm-Message-State: APf1xPC6CDpgAStvZy7wOw9tisPvEX9Kl3nMuaczF4ZU0URJ6j1XH6qq ecd0nT9NFqFBPrBeAd3PYWzjEw== X-Google-Smtp-Source: AG47ELts0KkkjQT6l+7LbA5Bx137SwS3jIHhGrlrnxoisKX0tMF29D16IWvrHN4X68Y0wjP4Uhpqww== X-Received: by 10.98.96.70 with SMTP id u67mr8899802pfb.66.1520077045531; Sat, 03 Mar 2018 03:37:25 -0800 (PST) Received: from ash ([171.232.93.137]) by smtp.gmail.com with ESMTPSA id a13sm15165274pgd.1.2018.03.03.03.37.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Mar 2018 03:37:24 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Sat, 03 Mar 2018 18:37:20 +0700 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org Cc: Junio C Hamano , Stefan Beller , Jonathan Nieder , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH 08/44] object-store: move alt_odb_list and alt_odb_tail to object store Date: Sat, 3 Mar 2018 18:36:01 +0700 Message-Id: <20180303113637.26518-9-pclouds@gmail.com> X-Mailer: git-send-email 2.16.1.435.g8f24da2e1a In-Reply-To: <20180303113637.26518-1-pclouds@gmail.com> References: <20180303113637.26518-1-pclouds@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Stefan Beller In a process with multiple repositories open, alternates should be associated to a single repository and not shared globally. Move alt_odb_list and alt_odb_tail into the_repository and adjust callers to reflect this. Now that the alternative object data base is per repository, we're leaking its memory upon freeing a repository. The next patch plugs this hole. No functional change intended. Signed-off-by: Stefan Beller Signed-off-by: Jonathan Nieder Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/fsck.c | 4 +++- object-store.h | 7 +++++-- packfile.c | 3 ++- sha1_file.c | 25 ++++++++++++------------- sha1_name.c | 3 ++- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 7a8a679d4f..b284a3a74e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "cache.h" +#include "repository.h" #include "config.h" #include "commit.h" #include "tree.h" @@ -716,7 +717,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) fsck_object_dir(get_object_directory()); prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) + for (alt = the_repository->objects.alt_odb_list; + alt; alt = alt->next) fsck_object_dir(alt->path); if (check_full) { diff --git a/object-store.h b/object-store.h index 505f123976..0ca9233a85 100644 --- a/object-store.h +++ b/object-store.h @@ -1,7 +1,7 @@ #ifndef OBJECT_STORE_H #define OBJECT_STORE_H -extern struct alternate_object_database { +struct alternate_object_database { struct alternate_object_database *next; /* see alt_scratch_buf() */ @@ -19,7 +19,7 @@ extern struct alternate_object_database { struct oid_array loose_objects_cache; char path[FLEX_ARRAY]; -} *alt_odb_list; +}; void prepare_alt_odb(void); char *compute_alternate_path(const char *path, struct strbuf *err); typedef int alt_odb_fn(struct alternate_object_database *, void *); @@ -61,6 +61,9 @@ struct raw_object_store { /* Path to extra alternate object database if not NULL */ char *alternate_db; + + struct alternate_object_database *alt_odb_list; + struct alternate_object_database **alt_odb_tail; }; void raw_object_store_init(struct raw_object_store *o); diff --git a/packfile.c b/packfile.c index 7dbe8739d1..216ea836ee 100644 --- a/packfile.c +++ b/packfile.c @@ -1,6 +1,7 @@ #include "cache.h" #include "list.h" #include "pack.h" +#include "repository.h" #include "dir.h" #include "mergesort.h" #include "packfile.h" @@ -891,7 +892,7 @@ void prepare_packed_git(void) return; prepare_packed_git_one(get_object_directory(), 1); prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) + for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) prepare_packed_git_one(alt->path, 0); rearrange_packed_git(); prepare_packed_git_mru(); diff --git a/sha1_file.c b/sha1_file.c index 792bb21c15..4c9635dada 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -22,6 +22,7 @@ #include "pack-revindex.h" #include "sha1-lookup.h" #include "bulk-checkin.h" +#include "repository.h" #include "streaming.h" #include "dir.h" #include "list.h" @@ -342,9 +343,6 @@ static const char *alt_sha1_path(struct alternate_object_database *alt, return buf->buf; } -struct alternate_object_database *alt_odb_list; -static struct alternate_object_database **alt_odb_tail; - /* * Return non-zero iff the path is usable as an alternate object database. */ @@ -364,7 +362,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir) * Prevent the common mistake of listing the same * thing twice, or object directory itself. */ - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) { if (!fspathcmp(path->buf, alt->path)) return 0; } @@ -424,8 +422,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, ent = alloc_alt_odb(pathbuf.buf); /* add the alternate entry */ - *alt_odb_tail = ent; - alt_odb_tail = &(ent->next); + *the_repository->objects.alt_odb_tail = ent; + the_repository->objects.alt_odb_tail = &(ent->next); ent->next = NULL; /* recursively add alternates */ @@ -559,7 +557,7 @@ void add_to_alternates_file(const char *reference) fprintf_or_die(out, "%s\n", reference); if (commit_lock_file(&lock)) die_errno("unable to move new alternates file into place"); - if (alt_odb_tail) + if (the_repository->objects.alt_odb_tail) link_alt_odb_entries(reference, '\n', NULL, 0); } free(alts); @@ -657,7 +655,7 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb) int r = 0; prepare_alt_odb(); - for (ent = alt_odb_list; ent; ent = ent->next) { + for (ent = the_repository->objects.alt_odb_list; ent; ent = ent->next) { r = fn(ent, cb); if (r) break; @@ -667,10 +665,11 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb) void prepare_alt_odb(void) { - if (alt_odb_tail) + if (the_repository->objects.alt_odb_tail) return; - alt_odb_tail = &alt_odb_list; + the_repository->objects.alt_odb_tail = + &the_repository->objects.alt_odb_list; link_alt_odb_entries(the_repository->objects.alternate_db, PATH_SEP, NULL, 0); @@ -715,7 +714,7 @@ static int check_and_freshen_nonlocal(const unsigned char *sha1, int freshen) { struct alternate_object_database *alt; prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) { const char *path = alt_sha1_path(alt, sha1); if (check_and_freshen_file(path, freshen)) return 1; @@ -875,7 +874,7 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st, prepare_alt_odb(); errno = ENOENT; - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) { *path = alt_sha1_path(alt, sha1); if (!lstat(*path, st)) return 0; @@ -905,7 +904,7 @@ static int open_sha1_file(const unsigned char *sha1, const char **path) most_interesting_errno = errno; prepare_alt_odb(); - for (alt = alt_odb_list; alt; alt = alt->next) { + for (alt = the_repository->objects.alt_odb_list; alt; alt = alt->next) { *path = alt_sha1_path(alt, sha1); fd = git_open(*path); if (fd >= 0) diff --git a/sha1_name.c b/sha1_name.c index 611c7d24dd..957ce25680 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -10,6 +10,7 @@ #include "dir.h" #include "sha1-array.h" #include "packfile.h" +#include "repository.h" static int get_oid_oneline(const char *, struct object_id *, struct commit_list *); @@ -104,7 +105,7 @@ static void find_short_object_filename(struct disambiguate_state *ds) */ fakeent = alloc_alt_odb(get_object_directory()); } - fakeent->next = alt_odb_list; + fakeent->next = the_repository->objects.alt_odb_list; for (alt = fakeent; alt && !ds->ambiguous; alt = alt->next) { int pos; -- 2.16.1.435.g8f24da2e1a