Article View: linux.kernel.git
Article #2708Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY
From: Derrick Stolee
Date: Mon, 09 Nov 2026 13:45
Date: Mon, 09 Nov 2026 13:45
100 lines
14445 bytes
14445 bytes
On 11/6/2026 8:26 PM, Junio C Hamano wrote:
> This file defines a set of fairly low level functions to implement
> merge and checkout behaviour, many of which depended on and can only
> work with the_repository.
>
> Two key data structures passed around in the code paths, "struct
> unpack_trees_options" and "struct index_state", both have a pointer
> to the repository instance, and we can use it to make it work on an
> arbitrary repository, not just the_repository.
>
> In any correctly written clients of this library file, the
> repository instance that is pointed at by these two structs MUST be
> the same one. For now, make sure that is the case (and otherwise
> BUG out) by introducing a unpack_repo() helper function that takes
> these two structures (when available) and returns the repository.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> * I wrote this change when I ranted in
>
> https://lore.kernel.org/git/xmqq33tdcuub.fsf@gitster.g/
>
> on 'seen', and "git checkout -m --detach master" was sufficient
> to build and start a new branch based on 'master' and there
> wasn't any need for adjustment. All tests seem to pass.
>
> unpack-trees.c | 94 ++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 76 insertions(+), 18 deletions(-)
>
> diff --git a/unpack-trees.c b/unpack-trees.c
> index d6a859420f..79341d7fa6 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1,4 +1,3 @@
> -#define USE_THE_REPOSITORY_VARIABLE
> #define DISABLE_SIGN_COMPARE_WARNINGS
>
> #include "git-compat-util.h"
> @@ -82,6 +81,56 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = {
> ? ((o)->internal.msgs[(type)]) \
> : (unpack_plumbing_errors[(type)]) )
>
> +
> +/*
> + * Some functions in these code paths get unpack_trees_options, which
> + * has up to two istates, and some get an istate. These istates can
> + * be used to find the repository to be used for this operation.
> + *
> + * As these are all working on the same repository, they must match.
> + * For now, with a super paranoid check, make sure all potential
> + * sources of the information match before using it.
> + *
> + * Once this proves working well, we could just use the first one we
> + * find in a production setting.
> + */
> +static struct repository *unpack_repo(struct index_state *istate,
> + struct unpack_trees_options *o)
> +{
> + struct repository *repo = NULL;
> + const char *camefrom = NULL;
Overall, this is a good helper implementation.
> + if (!repo)
> + BUG("no repository for unpack_trees()?");
> + return repo;
> +
> +}
nit: extra empty line.
> static const char *super_prefixed(const char *path, const char *super_prefix)
> {
> /*
> @@ -345,15 +394,16 @@ static void load_gitmodules_file(struct index_state *index,
> struct checkout *state)
> {
> int pos = index_name_pos(index, GITMODULES_FILE, strlen(GITMODULES_FILE));
> + struct repository *repo = unpack_repo(index, NULL);
>
> if (pos >= 0) {
> struct cache_entry *ce = index->cache[pos];
> if (!state && ce->ce_flags & CE_WT_REMOVE) {
> - repo_read_gitmodules(the_repository, 0);
> + repo_read_gitmodules(repo, 0);
> } else if (state && (ce->ce_flags & CE_UPDATE)) {
> - submodule_free(the_repository);
> + submodule_free(repo);
> checkout_entry(ce, state, NULL, NULL);
> - repo_read_gitmodules(the_repository, 0);
> + repo_read_gitmodules(repo, 0);
> }
> }
This sample of how it is used makes it clear how this is a
valuable abstraction.
Thanks,
-Stolee
Technical Details
Message-ID:
<784778b3-173d-4226-ae9e-4efcd4f556af@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74927-linux-kernel-git=dewy.ruReferences:
<xmqqtsltbfdv.fsf@gitster.g>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74927-linux-kernel-git=dewy.ru
From: stolee@gmail.com (Derrick Stolee)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH 1/2] unpack-trees: lose USE_THE_REPOSITORY
Date: Mon, 9 Nov 2026 08:45:19 -0500
Organization: Usenet Network
Message-ID: <784778b3-173d-4226-ae9e-4efcd4f556af@gmail.com>
References: <xmqqtsltbfdv.fsf@gitster.g>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="369828"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vhQWLmA8K85+FnPacj/CrfP0/eI= sha256:u7dZ8+H2FvKx+p3quJ7aMxcq+yc7B7E/DnyphVMjKTw=
sha1:IAhNvSm2V3j7i0NQU3vXbE+lFjw= sha256:BLkzeu9C4xZL4OkYbxFv/EN1XFFB9aX0I2T8e7+MUkA=
Content-Language: en-US
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 83C0B113808; Mon, 9 Nov 2026 16:51:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id RNnlotSGTTQS;
Mon, 9 Nov 2026 16:51:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-74927-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 9B4A1113807; Mon, 9 Nov 2026 16:50:51 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 33EDFC439C; Mon, 9 Nov 2026 13:45:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794231922;
b=MNVHBQ6Z3CO5MRhs4s+nuHO9k3yAC/q1Co6mXOm5Klpvcj1WzqtMX32GlKLvMSwdaiPq
zfnJlDN6leYqNn5u+aSi8+wFjbuoLtKJ4ZOTGDDYhO70U3gsYK4Y6kdABaIq0Bq1hSTbg
esaWlAgk/rNmx3cBRB1IWLZU7EGwFBbLu1Vo0L69IV/kIr3HCUJJh6qJHqzjZp8Fd3UHb
5n0MpcXkaSihJNhyDLnZfO9zx0yfVPXfvrRRq9Rzwql3+jb3GqXTdZEPrAlp8VjJ9oElO
dWmbvd/8XkaDxyQc8B1+wIp05CTZ0y6GgnW9/6t0iagcOFCiSDPZBHPK9SWg8/jli3A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794231922;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
User-Agent:Subject:To:References:Content-Language:From:In-Reply-To:
Content-Type:Content-Transfer-Encoding;
bh=YhtUaDld4uJp2++VSlK5eD3pRAdQ+oigC5aJ/UcMPc8=;
b=4RVL9I8WAPft+3f5kKwgBBFN/A1cjr5r9lJVBQqvRC1wI6i3PiG5EdqtQxQjNJtTFwPn
5yO4XaJdMLVNCFkb8cinPoSEYA8sponL4Qg8QgySXCENLzvG4y5X+dHDNivBM735D9fRY
B9C9eaGqnO3kw9WykunLTZe56Uer9dm/J/2RKP0yfKeo1CzoviinDSNoqONLAYRieESBl
5SJtn1zRxfHByreLsMCmG5Ca8/GHaqC9Os+o4jzUbVlaTrV3bfgsoIKuIFSpXjqQmCWYn
ANEVyWcp81AE2wth3n3dFZPxOErFBeijNYMpjvziFpf2Hrl5NS5xULuFzuGtNTo8/qw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pCAYKS1A;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 99D36606D809;
Mon, 9 Nov 2026 13:45:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pCAYKS1A
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794231921;
b=kMcy2Iz6T6uBBl1/cVlz13Ghye8NmfeJL/WD8UDwdYkup7AE7bEgEFhwrR8jfFPNVA4s
Y0ohOqJDjTb04WE2WpYS61nC4x+UsFlP56bpjm2ivieWGsTCyFd4rgEUw92/7gASmwiYR
2CRA0Qy/KnMRUP0+gnzfu57U5WOI2KiYNbdSRRZvsG7DcktXpUUJt4L/dkzjA71DzoXl/
cpVAAZ5+c92Hp5NJuP4hbf2IGy5ysT3gwzluZ6LxdA7JbbYUjLNuOG8nUT2r7BEVHP9aP
Uz/dCXkFkgi1tS9lAI/NbjO1Q4w0r6hwduLujuAL7bEV7tptzNFDY1K+gxZW/c0inoA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794231921;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-ID:Date:
MIME-Version:User-Agent:Subject:To:References:Content-Language:From:
In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=YhtUaDld4uJp2++VSlK5eD3pRAdQ+oigC5aJ/UcMPc8=;
b=xaJuebumfVJJdhuy9vtLP7C3VWuSAv6jShsnbb6eRaHq0Y9RNXYi0dx+0BK46ktIkUSJ
3XnhVd0bocumjzODrMa1JQSGw1ON653WZ2w3PWYs4UFkpPJ//87+VUcwY4EXdiQmvqAbm
xW1c+hEpuN0HsfatI0QyqAtG68xyst5g7lRWWPzrIhh+aP8qoE+gx5wLh+87h8n9qzjfV
EhnlR91CXt2ohOC45NmiO/zJ1H9OQsLew2kxUbd9oF1jLeOxPJAo6InkyDvwyk/5+srpd
f8gPxtOXcjZSk9R8Kfr5hioAAL/w6uH/2P/luOek/j3M/UEGagmselKh8xZp9TdwP0Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pCAYKS1A;
arc=none smtp.remote-ip=209.85.160.178
X-Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F40B606A31C
for <git@vger.kernel.org>; Mon, 9 Nov 2026 13:45:21 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F40B606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-536c8f958d7so6536921cf.1
for <git@vger.kernel.org>; Mon, 09 Nov 2026 05:45:21 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794231920; x=1794836720; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:to:subject:user-agent:mime-version:date
:message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=YhtUaDld4uJp2++VSlK5eD3pRAdQ+oigC5aJ/UcMPc8=;
b=pCAYKS1APIVnHm+gTLSFZ2XdqOyBgrNwkhWqz3hWUfElWNmtabE6F5cSyxStq/xPDI
8nGxlndjJ1Q8eiqH/zOhtqcDsWrCEdHEJd+7n4KXfUYtgwJcmQAzkOQ3A7YtOMCakFOf
Xb2ki2D8aKoYWVVgjBz126HbkIl//KCvfpY4GU8tYGPjYS/4yUiBX06AJe9s1HXh0a+9
uGyBviyhlvX8b6opQumrXDqzllCfrV83mCAxoGXuZq4PQordIVUXJYsu86Bn8yUBmaOF
evLr9cAtxcg66z6NqSg2e91oJf1nJHb3h27y4rUDaqAUAM4oahna/u1dHwR9PyCQyBvN
3WWw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794231920; x=1794836720;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:to:subject:user-agent:mime-version:date
:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=Yh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7p5SO/mpWtfBz9K8qNoqugViaMgG9BfRU59i/jjSFAQDMVlr7GgMCIYic77NQ04rw
52geoFdypIREcE8kJ9JqfSa/MbVw8t4I+9OHlILOzH6VQ9Q/dARVLNl7n3YMYy0OLlgheP1CjYL
JxAEAZSlJQrNq3CeUn8ZwJL3FMLQUc7uPWG7UROaQX4WW6OosnZuOjTP/ViACRyO8WhZrPmRGo/
REAEOXAXl5H6wRRSngpTaPs6E+bfW5BXhinjzj5GglUCQFgPM7XOfc8sMJwlteGY5yNXrm0LEwb
jwF
X-Received: by 2002:a05:622a:a6d4:b0:537:a19e:5561 with SMTP id d75a77b69052e-552a5b71444mr46346451cf.43.1794231920249;
Mon, 09 Nov 2026 05:45:20 -0800 (PST)
X-Received: from [192.168.1.109] ([136.61.86.144])
by smtp.gmail.com with ESMTPSA id d75a77b69052e-55264341ad0sm41124111cf.16.2026.11.09.05.45.19
for <git@vger.kernel.org>
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Mon, 09 Nov 2026 05:45:19 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-In-Reply-To: <xmqqtsltbfdv.fsf@gitster.g>