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=-3.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham 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 D6C341F404 for ; Sat, 24 Feb 2018 00:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752569AbeBXAsU (ORCPT ); Fri, 23 Feb 2018 19:48:20 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38057 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751674AbeBXAsE (ORCPT ); Fri, 23 Feb 2018 19:48:04 -0500 Received: by mail-pl0-f68.google.com with SMTP id d4so5848121pll.5 for ; Fri, 23 Feb 2018 16:48:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bAYdLJQ8l49dz8no43LbjCJLb8czsCQYyQkWv+GUzfQ=; b=UG5qs0c9DX7sJX6u1Guz54fGEKhjReC5PotWDNBjBxy9LHIo0iHnXPtgyOA7n8EbHK DCR4GYQaJRMqVQffCfQkdDsxudb+XP0yf96tCgMNIuF0OLYVAOLozXw8Qe+3eaCLPfsz 82XUsbAEtivSTFXKKwoN7TYGWw3t7xkJr6X1W1jR5I3mAOW5aMxlzCf5w9ApZnfZfWQ2 j8vymZ/FO1fdJTpJHrwMxb2I/05KQjIPlEw+T+UvnzhHbk0tOEG3GD7RzlbzSGCfN9Ot cTZU4DIXSR2QzrYPxTnlUZ7Xu/YGgZ30FlgAghWu5YN/3tEbqgVO+BReJ259w/miCHVR CXww== 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; bh=bAYdLJQ8l49dz8no43LbjCJLb8czsCQYyQkWv+GUzfQ=; b=MOFJJpvN3RlOaplP2XaR7qhFjwYOJDjjjNvTy2prHZkLZcGi+N6AAuslHLZuGm9VUW YgwGOYxTM2ggjBWkGzAF4I+CI0z/ETFNdv8NMaDCPjyoCrNph08KWhwqlrciB0+xH3+w t1IF0gMSX/Nqux+GDW9N4GbuOZE9ly+iDY0jHU6g9AbZW71kXoMNPQkKfQpZVNRE68hx j82wws5XArINItsxw7yA2Lj+UEMjtt5+1E61e5Vv5qodmicqU7UcUEX/V6ouBEe/1Z9Y sbcbbODo76Vd7J+udNztL/4vybpnUmVz0UO3oK7FuQWFB2AzUr2qRfmRcyfQ4CJ615KR PEeA== X-Gm-Message-State: APf1xPDpBJAu3boArjx7lZdrvNyC1FFreUPunKnN5SnazJmRnZh3o6jn H2q+qYg04wMO9UTIV0dwlwI/zQ== X-Google-Smtp-Source: AH8x225Otk2s+HmuQd0Rce6qYEjZ1bvw71svUqizjF/qgSmxofrhy3MdBCvCvs7Bzte+uXUp0qK85Q== X-Received: by 2002:a17:902:7509:: with SMTP id i9-v6mr3443033pll.220.1519433283217; Fri, 23 Feb 2018 16:48:03 -0800 (PST) Received: from localhost ([2620:0:100e:422:2d12:5719:3437:fdb7]) by smtp.gmail.com with ESMTPSA id e81sm6932240pfb.58.2018.02.23.16.48.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Feb 2018 16:48:02 -0800 (PST) From: Stefan Beller To: sbeller@google.com Cc: git@vger.kernel.org, gitster@pobox.com, jonathantanmy@google.com, pclouds@gmail.com, sunshine@sunshineco.com, bmwill@google.com, Jonathan Nieder Subject: [PATCHv4 03/27] object-store: move alt_odb_list and alt_odb_tail to object store Date: Fri, 23 Feb 2018 16:47:30 -0800 Message-Id: <20180224004754.129721-4-sbeller@google.com> X-Mailer: git-send-email 2.16.1.291.g4437f3f132-goog In-Reply-To: <20180224004754.129721-1-sbeller@google.com> References: <20180221015430.96054-1-sbeller@google.com> <20180224004754.129721-1-sbeller@google.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- builtin/fsck.c | 4 +++- object-store.h | 9 ++++++--- packfile.c | 3 ++- sha1_file.c | 25 ++++++++++++------------- sha1_name.c | 3 ++- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 9981db22637..78edcb75c45 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" @@ -722,7 +723,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 5678aa1136c..e78eea1dde3 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 *); @@ -58,8 +58,11 @@ struct raw_object_store { * Cannot be NULL after initialization. */ char *objectdir; + + struct alternate_object_database *alt_odb_list; + struct alternate_object_database **alt_odb_tail; }; -#define RAW_OBJECT_STORE_INIT { NULL } +#define RAW_OBJECT_STORE_INIT { NULL, NULL, NULL } void raw_object_store_clear(struct raw_object_store *o); diff --git a/packfile.c b/packfile.c index 7dbe8739d17..216ea836ee3 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 826d7a0ae37..ac25146076e 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" @@ -340,9 +341,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. */ @@ -362,7 +360,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; } @@ -422,8 +420,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 */ @@ -557,7 +555,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); @@ -655,7 +653,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,12 +665,13 @@ void prepare_alt_odb(void) { const char *alt; - if (alt_odb_tail) + if (the_repository->objects.alt_odb_tail) return; alt = getenv(ALTERNATE_DB_ENVIRONMENT); - alt_odb_tail = &alt_odb_list; + the_repository->objects.alt_odb_tail = + &the_repository->objects.alt_odb_list; link_alt_odb_entries(alt, PATH_SEP, NULL, 0); read_info_alternates(get_object_directory(), 0); @@ -716,7 +715,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; @@ -876,7 +875,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; @@ -906,7 +905,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 611c7d24dde..957ce25680b 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.291.g4437f3f132-goog