🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #962

Re: [PATCH v2 1/2] worktree: add --reflink for copy-on-write worktree creation

#962
From: "brian m. carlson"
Date: Tue, 20 Oct 2026 21:20
80 lines
12903 bytes
--Fn0gfu8UUmmz4hMy
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2026-10-20 at 16:04:08, Jason Newton via GitGitGadget wrote:
> Creating many worktrees from the same base -- for example to run a
> fleet of automated agents in parallel -- is expensive today: every
> "git worktree add" materializes the entire working tree by writing
> each tracked file out from the object store. The objects are shared
> via the common directory, but the working tree is not: N worktrees
> mean N full checkouts on disk and N times the file I/O.
>=20
> Add a "--reflink" option that, on a copy-on-write filesystem, populates
> the new worktree by reflinking the current worktree's files and index
> instead. The subsequent "git reset --hard" then only rewrites the
> paths that actually differ between the current worktree and
> <commit-ish>; everything else (including untracked files such as build
> outputs) keeps sharing storage with the source until modified.
>=20
> A new reflink_file() helper in copy.c clones every regular file. There
> is no size cutoff.
>=20
> On Linux it uses the FICLONE ioctl. That is the primitive btrfs, XFS
> and bcachefs implement, and the one overlayfs forwards when the lower
> filesystem can clone. This path has been tested on btrfs.
>=20
> On macOS it uses clonefile(), the APFS primitive. That path is
> implemented and has not been run here.
>=20
> On Windows it uses ReFS block cloning,
> FSCTL_DUPLICATE_EXTENTS_TO_FILE, as Git LFS does. The destination is
> sized to the source, extents are cloned in chunks of at most 1GiB, and
> the tail is rounded up to a cluster (64K, then 4K) and cloned; Windows
> ignores the range past EOF. The tail is not byte-copied, and small
> files are not skipped. That path is implemented and has not been run
> on ReFS. A volume that rejects the control code, including NTFS, fails
> the probe.

That functionality is defective; see
https://github.com/git-lfs/git-lfs/issues/6312.  We should not implement
this on Windows because there's no reasonable way to avoid corruption.
It's quite shocking that that bug exists, but it does.  Unless we can
guarantee a fixed version of Windows (which does not exist yet), we
should skip reflinking there.

I'd also like to see us limit this to platforms where it _has_ been
manually tested or is guaranteed to be automatically tested in CI.  That
means we should make sure this runs in CI on APFS for macOS (see below).

> +# Reflinks are only available on copy-on-write filesystems (btrfs, XFS,
> +# bcachefs, APFS, ...). Where they are unavailable, --reflink transparen=
tly
> +# falls back to a regular checkout, which the test above already covers.
> +test_lazy_prereq REFLINK '
> +	echo probe >reflink-src &&
> +	cp --reflink=3Dalways reflink-src reflink-dst 2>/dev/null
> +'

Does this work properly on macOS?  That is, does the macOS `cp` binary
contain support for `--reflink=3Dalways`?  If not, we won't be testing
this case properly on macOS.
--=20
brian m. carlson (they/them)
Toronto, Ontario, CA

--Fn0gfu8UUmmz4hMy
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

wr0EABYKAG8FgmrX2w0JEHwMSWKIh6KBRxQAAAAAAB4AIHNhbHRAbm90YXRpb25z
LnNlcXVvaWEtcGdwLm9yZ8cQa/Bvv5ugbkGKAruOMyz04tYtkB0ft+tAKVoSE1yZ
FiEECCzmip28ZfuD0cORfAxJYoiHooEAAFnZAQDZJOGcsCD7FjX1sC8yspbBPcLL
SBCMig0TJg1U95T23wD+M3M9IbZbdpFJWkuvlhgYJ17ZXffh55m/UzgNFldfWw0=
=Kl9P
-----END PGP SIGNATURE-----

--Fn0gfu8UUmmz4hMy--
Technical Details
Message-ID: <atfbDXhTUmPtv5pE@fruit.crustytoothpaste.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72614-linux-kernel-git=dewy.ru
References: <pull.2317.git.git.1780685368.gitgitgadget@gmail.com> <pull.2317.v2.git.git.1792512249.gitgitgadget@gmail.com> <83841020f43f9f8989371117075ebf089888d619.1792512249.git.gitgitgadget@gmail.com>

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-72614-linux-kernel-git=dewy.ru
From: sandals@crustytoothpaste.net ("brian m. carlson")
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2 1/2] worktree: add --reflink for copy-on-write
 worktree creation
Date: Tue, 20 Oct 2026 21:20:14 +0000
Organization: Usenet Network
Message-ID: <atfbDXhTUmPtv5pE@fruit.crustytoothpaste.net>
References: <pull.2317.git.git.1780685368.gitgitgadget@gmail.com>
 <pull.2317.v2.git.git.1792512249.gitgitgadget@gmail.com>
 <83841020f43f9f8989371117075ebf089888d619.1792512249.git.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
	protocol="application/pgp-signature"; boundary="Fn0gfu8UUmmz4hMy"
Injection-Info: usenet.network;
	logging-data="3966915"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:odWi/YVb72luUKZyb+xkuMpZ+pQ= sha256:HVF/3doabuk0qwg5yWGmByZTkckSjH65kXNwTeo16PM=
	sha1:ecWI3WDtF4wficGVD8x9euxjpqk= sha256:SO8L3lFbNk5XbHFxTi17jP68+IZ+o1mcsIj1jx3wmIk=
Content-Disposition: inline
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 B2998110E61; Wed, 21 Oct 2026 00:21:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (3072-bit key)
	header.d=crustytoothpaste.net
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 pjoy25DhP0a6;
	Wed, 21 Oct 2026 00:21:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72614-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=crustytoothpaste.net
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 3622A110E4E; Wed, 21 Oct 2026 00:21:17 +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 8C32039FC9; Tue, 20 Oct 2026 21:20:22 +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=1792531218;
	b=sj9zrUpSE8c9lz54BWaf+9FvxWs8c02ZZjHieDAqKTunu55FUGs+tRp5L9D6joJ8w6lw
	 f7w7eHvhl+atjOsUdGdno/QUS740bhQH0E0sIbZZ4PD/pYrSHdYpZu0JTkxUm2E5lttrG
	 x4XVKR1AOjPYYJmOErG6L5mO/ANYTjkl9MxNOOMya9G4XIhimkk9Y1KBzfwQJsCMKtIzW
	 MCHwtN1HyCquFkeUbqH6kNHAIYbcHa+rdluWOestQ86g1Zwt4CBJikcy6kV9qdYCHlqSF
	 tHzvP7R1uhk2f8K/eoyie2CXs01Ov8HDZc9gsp+KxM6EIhpnJjwK9jlZC98R0eurw4g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792531218;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date:
	 From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Disposition:In-Reply-To:User-Agent;
	bh=Ju8pmB3VAs1H5Q7BXIAJwkkE6TM2eI9WKXffITyuqKU=;
	b=v+UFvrF4AeVFdYeMlf9Vb/VjuzVl533F5HX4s0PW++g2ScYUz6SWlF9yBJUMKweX9GO4
	 OEZNAg+CqHP20V3Z8/Wm1PSXkd6tfoUauVpVSM5iqBYVHHY9Aom980O1am5dNBjhzuf1T
	 gqUrXJkuswCXWCt0Ku7bODKo05OCY1+Mw/gGbskv1iK+hX3mT/vp8BbB3IrFOQu5yw7KO
	 PaVgijGL4YXYmMxKYFXUmQzBVn2l3DAprkf++uLIWwxPB5XmBMISSEpxb2ndnYHrQmsWw
	 HE2Ib1lNhu7Z9QoR/x7FcrHw3N1HkZC1YNqeVWpQX7/uejN8fNDkn5mC0mwj9cuv0XQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.a=rsa-sha256 header.s=default header.b=KUhoSKyM;
	dmarc=none header.from=crustytoothpaste.net;
	spf=pass smtp.mailfrom=crustytoothpaste.net;
	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 A4536606A33D;
	Tue, 20 Oct 2026 21:20:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (3072-bit key, unprotected) header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.a=rsa-sha256 header.s=default header.b=KUhoSKyM
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=172.105.7.114
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792531217;
	b=poyq4+6+A74YzFoyZGj+YFt8UH9Y2Ut+MCiZ0HqmmLRtyv+T4vqmfGxeyVfsdXeaz4bF
	 lbi6oEPMcsWK7yODEsiB3/ynAVve0Fy/GzgRPXuPnXOAiwBeg9czyZU9zAKzrHdi0klPH
	 +xgMtjcUc9JHkzmgvd4lCOJxopj2Qorlye61x0BjrroQ8kxJnR5fTJZrGaLgbeJFIwvrF
	 hR64OlDfyCzjaIIVwhgj0BPSday+eZUbcpGyvmvSLWXcpwfgHZCvVLgpLxsgg7+Z96Mrm
	 7Is7ChqKUlqK7TdDX2P4BvxDs3JpVWFP9+EeMjbOaKfh27QnysaRAhXSmnhJCV8eNEg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792531217;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:
	 Content-Disposition:In-Reply-To:User-Agent;
	bh=Ju8pmB3VAs1H5Q7BXIAJwkkE6TM2eI9WKXffITyuqKU=;
	b=MliDc/dQQ5TF30rdUIQ+SU/x1YBYFMO2tImDyAM4meEXGytAHNQFWY6fCwIxJiwsT9kg
	 AcVwNHye2uKz98P/f4Bb58bHr+WGIdoAppIXCZvX+KlPoAWoqz3v+zt8MmXI//fZMED27
	 m/mOgq/kR6cQ1smfXAweNGG0koj68mwyylRJ+1wtPuwfbbPwaKebQB0JML3/r+0C61Hcd
	 wNFQGRzNleffO/NILm3tuPjgFjF9R9U5FZANzTzA/GaeDEusasAYQrQpM3d7074fmYQbe
	 I4VwNzIjocb2sF+t9DRo3/uCZ13nptmzNdHEqtv+yyV7AeGnONn5/stJnVFHU8ZUiMA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=crustytoothpaste.net;
	spf=pass smtp.mailfrom=crustytoothpaste.net;
	dkim=pass header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.a=rsa-sha256 header.s=default header.b=KUhoSKyM;
	arc=none smtp.remote-ip=172.105.7.114
X-Received: from complex.crustytoothpaste.net (complex.crustytoothpaste.net [172.105.7.114])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1299606A323
	for <git@vger.kernel.org>; Tue, 20 Oct 2026 21:20:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1299606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=crustytoothpaste.net
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crustytoothpaste.net
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net;
	s=default; t=1792531215;
	bh=wgvrtRNoYpbDQ14ZjTE9Of6EsJggdcDyytkCX96fmmk=;
	h=Date:From:To:Cc:Subject:References:Content-Type:
	 Content-Disposition:In-Reply-To:From:Reply-To:Subject:Date:To:CC:
	 Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To:References:
	 Content-Type:Content-Disposition;
	b=KUhoSKyMX4ixTr7U46mRwj1aybPPE0aNtiHQxnf/DbWUrc3wRQ3lABXg0OBHqgt7p
	 TVdHDZsR9OL869soAxvl2HIlQ90i76avHirrSrYVw5IzTdvDKVY6Lse53om/8hbFUO
	 WHK09XQXCVkVgMRHsKgsUw7em1MWohMQamdoVWWFnb5XVYdBrOgPkOSiGDAaBLU2Be
	 swgsE6D+041NuJBswy/5Kn32qggGORUoZlQDJJDb0+IMEQlbSWNFnnNNjYgrQMqs9x
	 vHWkXrCOWMDpHnH399EYOTsnu05h5hGfiFmAGfu7grCauRKJs1iO/ofnttqgE1N4D+
	 VYl5EgdSbBNbAKBJExte8wLHjbiXmixePRzPWSg5YbJkZKqx0vdzQMnL5tnxcofyI9
	 /RUG9VGZ/pmPX4IO8znSX8yiCZ8SwOjdmIVU9WzdgrIVrTEpwWBmNXAgVBayV+IqHX
	 JxlbFnVOlCkgr6Nmy/dJVWOk2WPoD6X6Lh/aaSKocQDJNRRW9q+
X-Received: from fruit.crustytoothpaste.net (unknown [IPv6:2607:f2c0:f00f:f901:9d74:90e2:669b:59fd])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by complex.crustytoothpaste.net (Postfix) with ESMTPSA id 9A8952006B;
	Tue, 20 Oct 2026 21:20:15 +0000 (UTC)
X-Cc: git@vger.kernel.org, Jason Newton <nevion@gmail.com>
X-Mail-Followup-To: "brian m. carlson" <sandals@crustytoothpaste.net>,
	Jason Newton via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Jason Newton <nevion@gmail.com>
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-In-Reply-To: <83841020f43f9f8989371117075ebf089888d619.1792512249.git.gitgitgadget@gmail.com>
X-User-Agent: Mutt/2.4.1 (2026-07-04)