Skip to content

Commit 5155797

Browse files
shejialuogitster
authored andcommitted
packed-backend: check if header starts with "# pack-refs with: "
We always write a space after "# pack-refs with:" but we don't align with this rule in the "create_snapshot" method where we would check whether header starts with "# pack-refs with:". It might seem that we should undoubtedly tighten this rule, however, we don't have any technical documentation about this and there is a possibility that we would break the compatibility for other third-party libraries. By investigating influential third-party libraries, we could conclude how these libraries handle the header of "packed-refs" 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. As many third-party libraries expect a single space after "# pack-refs with:", if we forget to write the space after the colon, "create_snapshot" won't catch this. And we would break other re-implementations. So, we'd better tighten the rule by checking whether the header starts with "# pack-refs with: ". Mentored-by: Patrick Steinhardt <[email protected]> Mentored-by: Karthik Nayak <[email protected]> Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cfea2f2 commit 5155797

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

refs/packed-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
694694

695695
tmp = xmemdupz(snapshot->buf, eol - snapshot->buf);
696696

697-
if (!skip_prefix(tmp, "# pack-refs with:", (const char **)&p))
697+
if (!skip_prefix(tmp, "# pack-refs with: ", (const char **)&p))
698698
die_invalid_line(refs->path,
699699
snapshot->buf,
700700
snapshot->eof - snapshot->buf);

0 commit comments

Comments
 (0)