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-Status: No, score=-3.8 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_HI, 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 D8FE01FA01 for ; Fri, 12 Mar 2021 20:20:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234615AbhCLUUT (ORCPT ); Fri, 12 Mar 2021 15:20:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234682AbhCLUUB (ORCPT ); Fri, 12 Mar 2021 15:20:01 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01642C061761 for ; Fri, 12 Mar 2021 12:20:00 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id y16so5504475wrw.3 for ; Fri, 12 Mar 2021 12:20:00 -0800 (PST) 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=ROXeQyOVRgVKS0s5296KQ8eIHVrbXdXWgu65MvPeWGE=; b=QSqDAus2t1NdGA7OEA/ujrnbw8PNDbbTzzEie6dpZ132d2na6qj1MNPWl+dTPR4AAJ hZGlDpDYdlNvRKM0Hc1RnXCOBaVU+MiuRa7TGEa6RSFS0ih3GJMSHmnzO9u4L2QEV31a /gheNYwi+C4fddm6wiN6/FBQCV5+QvxPvYafxD27czAeEB3DmmY1bmKLpyxzRiSX4w7I nxTU0Vr/g2/L35Df22tpNgmguCXxAERtuHY63hWGS1IwiskshUi+LfE7v8Hw/9EAayAD 9Qv7FD1oywqPF73iPgxpFcveQV0Vgh3raKhGnf6qjHf2lPXh5pfijQ6U5RHwpynivFMa za0A== 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=ROXeQyOVRgVKS0s5296KQ8eIHVrbXdXWgu65MvPeWGE=; b=K8xevd8Itw2xZ6pVQalIBy9eQgw89+POY9X2qc0ag4T8mcXMoRO3e4ipl7y++BUR5n rnVFaUJnK5N23EPW5/x4HnQSBN0cS3G3DsAwYs39FqmPXyBxSqz/ZjR0YeTikxYoVXDo 6i022Wr0SCWfwCkGsGi9YovTM1/2kZmVWOa8M6CaFR/DqbPj7pYT2MymZMZEFnzD/nat jU/Ht+utocGHWls09aMg1+pAKQRGeAudYtPBP1vk/jC1z6w+IlaPR5+R9ImdXNZvhzKq bWy76wlSdUH11zeJ7sxXXoCLM1iZitFVHvxtuKlsciiY2crpE3qM2paeFi+gXsyoQ5bH rxqg== X-Gm-Message-State: AOAM532rm3BYQll5dyDqsKpudkqXW2onbFHJI0oSze6zCgB4Ni8Xd3GU caq/88urAkAYKjoCmoEZQaNGx+7CtW4= X-Google-Smtp-Source: ABdhPJxdZoA2deJ7RjNvmTRmm44sF3fu3oeXYgwM8TFpapyVg/yiPluUwYe22t5yqZaMntxMnMBozg== X-Received: by 2002:adf:ed46:: with SMTP id u6mr15538296wro.350.1615580399729; Fri, 12 Mar 2021 12:19:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n6sm3894551wmd.27.2021.03.12.12.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 12:19:59 -0800 (PST) Message-Id: In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Fri, 12 Mar 2021 20:19:42 +0000 Subject: [PATCH v5 01/15] 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 , Jeff King , Ramsay Jones , Jonathan Nieder , Johannes Schindelin , Jonathan Tan , Josh Steadmon , Emily Shaffer , Patrick Steinhardt , =?UTF-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0?= Bjarmason , Felipe Contreras , 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 dcc45bef5148..7766661a4755 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -438,6 +438,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