From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054737; b=h0OpN3P7y7NgRqVLzBVm54THRu4Ram1TQ5wQLOTyt6nRI4hGT3ccLK7O8s3Zck2Ki2Y7 1N7odpngTfOdSkJfy5PdM6rsfJGn2LHq9LARcpOcG2CmtSPcnRIIN0Hp7Lwhk9pLhSpVI QRquCHdI/fCkmK6u4D2Zs1F7JYsMi4/r44CER+Fbiqmzy8Q501bRR+tQazdfcLA8F1pqw HT62Vdy5sta+w5ChxZgMsMKyORwUscbI3+wz3dgzGuMzRVIkQgtNBRi35HXxaDjsWoFN9 THCdX7TkSvVMGLn6uvhaaJLHyey66XCAEfea4sBfHuCqXaW3Cv5KMLFVt/wUDyr741w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054737; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=dPpZZUN7pI3CeH0XDLRq/XTXEEASzdvEm4DU3oLpP+o=; b=R8QGnpwfO7OX25g+6/DUdRbTaFZ/3bpa0SaIZZ9Z0H8L3OlvpGIrcxQ5ymDJGi4e3z/V bE3bq9aG0eeYQC6Ue5ivwunRTxPXbOpfVqqO6Z1wuTCuTo6x7sp0x9EHIyDZZEgf+4SH7 zwle54XZCUAwZgxun47Wpv62JWLWrdB5lB8Av2xw3Rqp+9LPcJYSmlFSCkPQ148ssbmqN 5wKUqTWEyffEwxiDDuhhq0ZZX0cZIjEuCTN5UdIVe+P24Tn6vy/KutFcnldh+5xTzzq1a J9ZpjJdvZ2l1qvPJmZpSm0ZR8xujsTHi/zWFw4sc2zfCCVTm+Bx6PbB56eiZwlv77VQ== 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=bII6e4Ki; arc=none smtp.remote-ip=209.85.215.177 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 0CDD0606A31C for ; Mon, 30 Nov 2026 16:05:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0CDD0606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=bII6e4Ki Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-cd60c5da24cso6098702a12.0 for ; Mon, 30 Nov 2026 08:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796054736; x=1796659536; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dPpZZUN7pI3CeH0XDLRq/XTXEEASzdvEm4DU3oLpP+o=; b=bII6e4Ki3T7C8e7BIMRzLBU1Bp2fM4Qs+r3r0HxM1P/KdDBQC4EtcVsGodhl8HPC3D G0BIMISiR+NZA0ZC70OYrxRRQQTuOHPQT1Nbo646Uc0+0Q9PVJ/KVY1Ql2J5q9HzI1WO I+rC0QhU4kTWqSoHYUKpeSAQfPXiZIaViddWCzjKfk7OGa6a3zBG627c+TIRGBzT4d6M JINf7SBvOyu2fzKILz94iK/5rsleRzUAZ56uGYl09xAufTFNGuL4mjpGgTQJm5m/oa2U G/Ahb/eYctUSkOHa2rn+tFo/OThOCcg+blfV0jJHyLd7w5a5aUQpk9uQ280DpYqNKHcR 3ltA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054736; x=1796659536; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc: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=dPpZZUN7pI3CeH0XDLRq/XTXEEASzdvEm4DU3oLpP+o=; b=jn/8cQFeo9oxWSzt1TtZK3xs/MXZrYI/Zqgn9ZZbkdhMDauUODRu3LZzWJ9/eIY17M 6Bq+IXhoX+FL51L4L18oe1d2wb7lGeC1qBb3T7DU7+4MZHEWO/3xQTulWQhJI+VEmSUm 7D8B8DWjC00C8lEj1S4nQ2bOg3JhMmrIjcAmLIi06oW2ts/kfi6ADNwZD4dyLNMZYkk5 6JVR3UJR1vej8cKDOsRSpJkIVfd5nwYng3KXzEL2yGhsvBNs6Pc27iuWSOovauXXT1g9 a0nw90rXnw2h3gBO3qZKMJOH2a+wvnIKxj8m3SS8ejAmuYW6MrgDJBwmOnSDk5Uae8BU 5E8Q== X-Forwarded-Encrypted: i=1; AL+hErG03RShMrU7K7ayrZu+dGM+W+19A4gZi0S3uyVtmDsrNvXaM/WyWGJ4qIvLoI+Y9oTo4zY=@vger.kernel.org X-Gm-Message-State: APuU4Z+PYEPcujNSQ2MfqdCdcRGRxGQKVR7yZ35vcyp+0HTxwNcLzOTr 4BS13O1u8uI6AM3Zbt7ZRn5AoHEk+CivMLPRIdIspQw5BOy5p6D3aAwb X-Gm-Gg: AZFdTZe+UkgX1l3pfn7ExQgfIPmaKVjQ0dBNE67Xpa5EQOHLjpYJ19ZIeHQh3EGJuTE YdE27z9hnBridOvMV/PspIiIWdzpfmQ7tPPNwBcKzU+vcI4IriFg00UDTDEoKGGBtXep7tlrH/S jTnfMh1fRZy3I2s/FI8cplVx666gKYYfwDqhmO3+xCJxhga/Gt9KDBVsxm4ylwFuO76TUWmZOBQ sq1Xt5zUC6I3RAbNfOeVr551pI6HNdNlZA16TCR+51CQoUHy0F/46sLdQ0goPFXcnYQ6zZ0b4F5 XONcBmDNCNtSd0zEgI71JJSLRznM8mMSGKxM5oc46scZiglNtwBzW5EkdzPkgcgItOz4CvTtpuN mrnP2wDCJeZYt2+P91XZT1hL9ar9u9I2i9kZpwfArbK6u+V+Vzo2sa+s943BWA/qUWDPk1uVmKR K8sXWNppDSwq6wteiF4DAWQgbxTf76ckgs0VFx2qq0qhn0M1xlYw+JIoqF/BmkKHS2XD259E+DJ VowGbx/oSoDuV7VFEn7euiIDNMw+YQCCxY/IV4t3IwGnCum0WeSTb6Xd0wCpvhRqEt9x9Bd1HDi eQljZoL+Mar4qe5gCmtK4II22LI5DxnmDJH+tvh/Omo= X-Received: by 2002:a17:90b:5109:b0:3b1:82fb:7e03 with SMTP id 98e67ed59e1d1-3b41c9b25a2mr36499362a91.11.1796054734608; Mon, 30 Nov 2026 08:05:34 -0800 (PST) Received: from [192.168.1.34] ([103.215.237.185]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6cea770asm18680549a12.3.2026.11.30.08.05.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 08:05:34 -0800 (PST) Message-ID: <54a6e8aa-e112-4686-b34b-5857f5060e27@gmail.com> Date: Mon, 30 Nov 2026 21:35:29 +0530 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 06/13] pack-write: add support for pack index v3 To: Christian Couder , git@vger.kernel.org Cc: Junio C Hamano , "brian m . carlson" , Patrick Steinhardt , Elijah Newren , Jeff King , Johannes Schindelin References: <20261023072559.3204273-1-christian.couder@gmail.com> <20261023072559.3204273-7-christian.couder@gmail.com> Content-Language: en-US From: Kaartic Sivaraam In-Reply-To: <20261023072559.3204273-7-christian.couder@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit With the caveat that I'm not an expert in index formats, I thought I'll leave some comments to the best of my understanding. On 10/23/26 12:55, Christian Couder wrote: > > We choose to always write the main hash algorithm first in the pack. > This optimizes for the case when we're interacting natively with the > remote side by permitting us to use the CRC32 entries. > > Note that we never write index v3, since we cannot read it yet, and > doing so will break the tests. In a future commit, once we can read it, > we'll enable it by default when a compatibility algorithm is enabled. > Could we be more explicit about when we polan to enable v3 by default? For instance, do we plan to do it in this series or in a later series? > diff --git a/pack-write.c b/pack-write.c > index 85674e4b72..1834394a77 100644 > --- a/pack-write.c > +++ b/pack-write.c > @@ -22,13 +22,20 @@ void reset_pack_idx_option(struct pack_idx_option *opts) > opts->delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT; > } > > -static int sha1_compare(const void *_a, const void *_b) > +static int oid_compare(const void *_a, const void *_b) > { > struct pack_idx_entry *a = *(struct pack_idx_entry **)_a; > struct pack_idx_entry *b = *(struct pack_idx_entry **)_b; > return oidcmp(&a->oid, &b->oid); > } > > +static int oid_compare_compat(const void *_a, const void *_b) > +{ > + struct pack_idx_entry *a = *(struct pack_idx_entry **)_a; > + struct pack_idx_entry *b = *(struct pack_idx_entry **)_b; > + return oidcmp(&a->compat_oid, &b->compat_oid); > +} > + I wonder if we could've split the rename and the introduction of the helper function into its own commit for the sake of better readability. I don't feel strongly, though. I'm just suggesting it as a way to possibly simplify this otherwise dense patch. > static int cmp_uint32(const void *a_, const void *b_) > { > uint32_t a = *((uint32_t *)a_); > @@ -50,30 +57,156 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts) > sizeof(ofsval), cmp_uint32); > } > > +static inline int last_matching_offset(const struct object_id *a, const struct object_id *b, > + const struct git_hash_algo *algop) > +{ > + size_t i; > + for (i = 0; i < algop->rawsz; i++) > + if (a->hash[i] != b->hash[i]) > + return i; > + /* We should never hit this case. */ > + return i; > +} This returns the index of the first byte that *differs*, so the name says the opposite of what it does. Something like first_differing_byte() would read better at the call site. It also returns an int computed from a size_t, and the caller stores it back in a size_t. > + > +struct pack_idx_format_header { > + uint32_t id; > + uint32_t short_name_len; > + uint64_t offset; > +}; > + > [ ... snip ...] > > + hdr.hdr_len = htonl(hdrlen); > + hdr.nr_objects = htonl(nr_objects); > + hdr.nr_formats = htonl(nformats); > + hashwrite(f, &hdr, sizeof(hdr)); > + Given the struct is essentially a set of uint32_t and uint64_t, is there a specific reason that we prefer packing data into a struct and writing it using hashwrite rather than just writing them directly using hashwrite_be32() / hashwrite_be64()? +static void write_v3_header(struct repository *repo, + int nr_objects, int nr_large_offset, + uint32_t short_name_len[2], int padding[2], + struct hashfile *f) +{ Shall we define nr_large_offset as an unsigned int to be consistent with the caller? > + uint64_t short_table = short_name_len[0] * nr_objects; Can we cast to uint64_t before doing the arithmetic similar to how it is done below? > + /* padding */ > + if (short_table & 3) { > + padding[0] = 4 - (short_table & 3); > + offset += padding[0]; > + } > + > + format[0].id = htonl(repo->hash_algo->format_id); > + format[0].offset = htonll(offset); > + format[0].short_name_len = htonl(short_name_len[0]); > + hashwrite(f, &format[0], sizeof(format[0])); > + offset += (uint64_t)(short_name_len[0] + repo->hash_algo->rawsz + 4 + 4 + 4) * nr_objects + > + 8 * nr_large_offset; > + "8 * nr_large_offset" is int arithmetic, Can we make it "(uint64_t)8 * nr_large_offset" to keep the arithmetic uint64_t? > + if (compat) { > + short_table = short_name_len[1] * nr_objects; > + /* padding */ > + if (short_table & 3) { > + padding[1] = 4 - (short_table & 3); > + offset += padding[1]; > + } > + > + format[1].id = htonl(compat->format_id); > + format[1].offset = htonll(offset); > + format[1].short_name_len = htonl(short_name_len[1]); > + hashwrite(f, &format[1], sizeof(format[1])); > + offset += (uint64_t)(short_name_len[1] + compat->rawsz + 4) * nr_objects; > + } > + > + offset = htonll(offset); > + hashwrite(f, &offset, sizeof(offset)); > +} > + > /* > - * The *sha1 contains the pack content SHA1 hash. > - * The objects array passed in will be sorted by SHA1 on exit. > + * The *hash contains the pack content hash. > + * The objects array passed in should be in pack order and will be sorted by > + * object ID on return. > */ "Should be in pack order" is a new requirement on existing callers. Have we verified that all callers give us the array in pack order? Shall we try to enforce the order in write_idx_file rather than expecting that callers would've already verified it? > > if (nr_objects) { > sorted_by_sha = objects; > list = sorted_by_sha; > last = sorted_by_sha + nr_objects; > for (i = 0; i < nr_objects; ++i) { > - if (objects[i]->offset > last_obj_offset) > - last_obj_offset = objects[i]->offset; > + objects[i]->idx = i; > + if (need_large_offset(objects[i]->offset, opts)) > + nr_large_offset++; > } > [... snip ...] > > @@ -95,7 +228,8 @@ const char *write_idx_file(struct repository *repo, > } > > /* if last object's offset is >= 2^31 we should use index V2 */ > - index_version = need_large_offset(last_obj_offset, opts) ? 2 : opts->version; > + if (index_version == 1 && nr_large_offset) > + index_version = 2; It seems like we're changing the specific object in which we were calling needs_large_offset. I'm not very sure why. I suppose it may be worth a mention in the commit message, though. Also, I suppose the comment above became stale. > + if (index_version >= 3) { > + /* write the sorted-to-pack index */ > + list = sorted_by_sha; > + for (i = 0; i < nr_objects; i++) { > + struct pack_idx_entry *obj = *list++; > + uint32_t index = htonl(obj->idx); > + hashwrite(f, &index, 4); > + } > + } > + > if (index_version >= 2) { > unsigned int nr_large_offset = 0; > Can we avoiding redefining nr_large_offset here now that it is defined at the function level? > > diff --git a/pack.h b/pack.h > index ada506b5c5..86b2a8ba7b 100644 > --- a/pack.h > +++ b/pack.h > @@ -79,7 +79,9 @@ struct pack_idx_header { > */ > struct pack_idx_entry { > struct object_id oid; > + struct object_id compat_oid; > uint32_t crc32; > + uint32_t idx; > off_t offset; > }; > I suppose this would increase the pack_idx_entry size by roughly 40 bytes even for those users who don't use the compat algo. Is this additional memory increase acceptable? Or shall we think of a better alternative where only users who use a compat algo pay with additional memory? -- Sivaraam