From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 79ED51F9E5 for ; Tue, 20 Jul 2021 17:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229921AbhGTQZM (ORCPT ); Tue, 20 Jul 2021 12:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbhGTQYN (ORCPT ); Tue, 20 Jul 2021 12:24:13 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2020C061766 for ; Tue, 20 Jul 2021 10:04:50 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c12so8763039wrt.3 for ; Tue, 20 Jul 2021 10:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=M66o8jlMvL4PeeUtekVFtRg/hRORM9wxMnGQIcXA8eM=; b=Arz4Fd5yHi5jHIijws3ptHHK85Dd/hr+aFhZYWv2rEMEE0ng3RcxO3hOqm8OUbpUvS dh8ZuqQpRM7SQ5xp3946Z4VFWyPPR2PWv2cFYLzzwX1tMKjvkG57LRyx36hPCQNwqqZs KKj7Quj+MN95fsdJAP19c76Hvxu9yDrbdE3hy9O4wpKINaZV1he9fX3Y0+4l+LQ0zHtp vUSpfGmwvEPkgV6xxYb73psgAJ9EEAE1dAMZMW+DeM3sUQr8V8NewAMPy15N3RkkxdAX eMglOkJyjiJPbvpkP58QmieJ1+gndR8q5ogU/rAHCmOq9eVRj9DeVOZXDvlhzmJsWa9G nI8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=M66o8jlMvL4PeeUtekVFtRg/hRORM9wxMnGQIcXA8eM=; b=mooFkXxlteFBZoIysPC2pfa3oL++ypBSiTzkpDEedvHnA56+ToI6nq0lKTaqUH/xqX R+1Y59Qrn1mE20SephPnbGwo7H1AJckS0VbhuEvPyKvdExZPk4Uim/cT/tUHi+9pvUU2 5zLQa/QMVch/wFKMyrep61dsT9uXZqfuSS7W/8q8yo0hpCNESGY8FkQby6HuE1yMtxBc xNCe3IpfeNvLb68O+tCI9+XYOtf++9EzOR0zaK/FKW2NBA25V/cC0nFxOwK3SIpPZ1Eq w5s0kwAMXj03//V3d6frspV/5voPlfDG6hJ6kWh7gvb98fjIvmoJE9dD50uqs9uoYDmF N7Rw== X-Gm-Message-State: AOAM530XQK/bmMUNoQl/57tfRolrgkH+vJLfYN22Twscu3i/7qURtp0Q whn6FxV9c3CjwHl0XRrCOhiXAsMkhfk= X-Google-Smtp-Source: ABdhPJxrYmEmh/IcZ1k6JBAA2NKCmHgQ3m72Volgs21uhjitUI7YHi77S9D2h4nyccgacWyef0kYFg== X-Received: by 2002:adf:de92:: with SMTP id w18mr37475763wrl.42.1626800689429; Tue, 20 Jul 2021 10:04:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a8sm24349522wrt.61.2021.07.20.10.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 10:04:49 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Tue, 20 Jul 2021 17:04:22 +0000 Subject: [PATCH 02/26] init-db: set the_repository->hash_algo early on Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys The reftable backend needs to know the hash algorithm for writing the initialization hash table. The initial reftable contains a symref HEAD => "main" (or "master"), which is agnostic to the size of hash value, but this is an exceptional circumstance, and the reftable library does not cater to this exception. It insists that all tables in the stack have a consistent format ID for the hash algorithm. Call set_repo_hash_algo directly after calling validate_hash_algorithm() (which reads $GIT_DEFAULT_HASH). Helped-by: Junio C Hamano Signed-off-by: Han-Wen Nienhuys --- builtin/init-db.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/builtin/init-db.c b/builtin/init-db.c index 2167796ff2a..c2f03f6018e 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -425,6 +425,27 @@ int init_db(const char *git_dir, const char *real_git_dir, validate_hash_algorithm(&repo_fmt, hash); + /* + * At this point, the_repository we have in-core does not look + * anything like one that we would see initialized in an already + * working repository after calling setup_git_directory(). + * + * Calling repository.c::initialize_the_repository() may have + * prepared the .index .objects and .parsed_objects members, but + * other members like .gitdir, .commondir, etc. have not been + * initialized. + * + * Many API functions assume they are working with the_repository + * that has sensibly been initialized, but because we haven't + * really read from an existing repository, we need to hand-craft + * the necessary members of the structure to get out of this + * chicken-and-egg situation. + * + * For now, we update the hash algorithm member to what the + * validate_hash_algorithm() call decided for us. + */ + repo_set_hash_algo(the_repository, repo_fmt.hash_algo); + reinit = create_default_files(template_dir, original_git_dir, initial_branch, &repo_fmt, flags & INIT_DB_QUIET); -- gitgitgadget