[PATCH v6 4/9] packed-backend: check if header starts with "# pack-refs with: "
- From
shejialuo <shejialuo@gmail.com>
- Date
- Feb 25, 2025, 13:21 UTC
- Message-ID
- <Z73D5XLzzg-OPmdT@ArchLinux>
- In-Reply-To
- <Z73DTwr9RicKMINe@ArchLinux>
We always write a space after "# pack-refs with:". However, when creating the packed-ref snapshot, we only check whether the header starts with "# pack-refs with:". However, we need to make sure that we would not break compatibility by tightening the rule. The following is how some third-party libraries handle the header of "packed-ref" file.
1. libgit2 is fine and always writes the space. It also expects the whitespace to exist. 2. JGit does not expect th header to have a trailing space, but expects the "peeled" capability to have a leading space, which is mostly equivalent because that capability is typically the first one we write. It always writes the space. 3. gitoxide expects the space t exist and writes it. 4. go-git doesn't create the header by default.
So, we are safe to tighten the rule by checking whether the header starts with "# pack-refs with: ".
Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: shejialuo <shejialuo@gmail.com> --- refs/packed-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 6c118119a0..9dabb5e556 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -694,7 +694,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs) tmp = xmemdupz(snapshot->buf, eol - snapshot->buf); - if (!skip_prefix(tmp, "# pack-refs with:", (const char **)&p)) + if (!skip_prefix(tmp, "# pack-refs with: ", (const char **)&p)) die_invalid_line(refs->path, snapshot->buf, snapshot->eof - snapshot->buf);
-- 2.48.1