From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18FA636E468 for ; Fri, 28 Aug 2026 19:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787944389; cv=none; b=crCrcXqGML3cOOwunP60s6WYt2oay1iElu1IyfKrDCQ+R3Qgksaaa/UqzVXGa2aDNrFBQwGl9cWU5oD0wvJ/aFpKZc+W/BGK7PhBPR/6eaPwacEPucsFCMC+F6MCXcxAyXUV2p4jM/4LLiQSitCQ4RtYbXKYaK0/KooOUUZp4qE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787944389; c=relaxed/simple; bh=FXO/wh/5OSv3x4KYSqEjB0j+C93MkTaR9rF30MfZsi8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=QJ0NSa61jo/9NA+qyvUWRuhjSJ+yrPCr2lTlzwRcQs0E7EvGkPenCGQP7Wm9SEg0LHtevG8zJ0ZUq3Hn12K3puAdOmHkK1TTX31xDUjFLsZ4chmFaDPDgw5qdm94jYJQ/JDgVC0K4A8sGiSRon0eQ+qd9YxVbYqtGMv+/uF50jQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=GZc+iaoX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Rse/vCHd; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="GZc+iaoX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Rse/vCHd" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 3C28D1D00077; Fri, 28 Aug 2026 15:13:06 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-12.internal (MEProxy); Fri, 28 Aug 2026 15:13:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1787944386; x=1788030786; bh=ZT4yUeubxf 5poDzI8dQdzoQzUbOaTweIosJA+dbodUw=; b=GZc+iaoX6LZSgjBIZpqoMX3x/0 +OgqJZw9qp2jM7QRird0denbaJbIgJBJz+Un/OF7GYFtzoDE2swJslI6Ybtq/KkK b9mxDpeGvRgqBgv5dz0kWMc/F71sWHg5pILQCYgwN+HwyviWaiuE1jN5ez1IrH+B tlmDI9GcwOD7DSUOxdV+3vUzI4qrGr5jKhpX1bCgl/NP2Bw/MMnTBVf+7xHqteAD 6pHYg3mysCRNjyQKsnqAlVlhfYnq6JULOZlQu2yJv5upUif0+zCvo8IhKApv1vYr 2T7L5l06/iYs9jq+AsUnfBaEW0aSxjZRhq4npsotnzJ1MdYu/n+ZLO1JVcJA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1787944386; x=1788030786; bh=ZT4yUeub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c5n9cv0MX+GWBxhkZhLlO60A X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 28 Aug 2026 15:13:05 -0400 (EDT) From: Junio C Hamano To: Patrick Steinhardt Cc: git@vger.kernel.org Subject: Re: [PATCH 6/8] odb/source: support writing alternates when creating the database In-Reply-To: <20260825-pks-odb-write-alternates-at-creation-time-v1-6-911513ba95c3@pks.im> (Patrick Steinhardt's message of "Tue, 25 Aug 2026 16:11:55 +0200") References: <20260825-pks-odb-write-alternates-at-creation-time-v1-0-911513ba95c3@pks.im> <20260825-pks-odb-write-alternates-at-creation-time-v1-6-911513ba95c3@pks.im> Date: Fri, 28 Aug 2026 12:13:04 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Patrick Steinhardt writes: > Add the ability to write alternates when creating the object database. > This change allows us to remove the `write_alternates()` callback in a > subsequent patch. > > Signed-off-by: Patrick Steinhardt > --- > diff --git a/odb/source-files.c b/odb/source-files.c > index b7b3a297bb..5e77b21d9f 100644 > --- a/odb/source-files.c > +++ b/odb/source-files.c > ... > @@ -64,8 +70,71 @@ static int odb_source_files_create_on_disk(struct odb_source *source) > + if (opts->alternates && opts->alternates->nr) { > + strbuf_reset(&path); > + strbuf_addf(&path, "%s/info/alternates", source->path); > + > + /* > + * The alternates file may already exist, e.g. when it has been > + * seeded from a template directory. Read any preexisting > + * entries so that we don't end up writing duplicates. > + */ > + f = fopen(path.buf, "r"); > + if (f) { > + while (strbuf_getline(&line, f) != EOF) > + strset_add(&seen, line.buf); > + > + if (ferror(f)) { > + ret = error_errno(_("unable to read alternates file")); > + goto out; > + } > + > + fclose(f); > + } else if (errno != ENOENT) { > + ret = error_errno(_("unable to read alternates file")); > + goto out; > + } > + > + f = fopen(path.buf, "a"); > + if (!f) { > + ret = error_errno(_("unable to open alternates file for writing")); > + goto out; > + } I understand that using 'a' instead of 'w' is an attempt to deal with the potential TOCTOU problem, but shouldn't we be using the standard lockfile API, which atomically adds (or fails to add) to avoid leaving a partially written file? Or does it not matter, since this is done only once upon repository creation when nobody should be looking at the files on the filesystem? Thanks.