Re: [PATCH 2/2] [GSOC] ref-filter: add %(header) atom
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 28, 2021, 04:36 UTC
- Message-ID
- <xmqqpmxb79v8.fsf@gitster.g>
- In-Reply-To
- <aa6d73f3e526f416ee1e4e332e9ca3119efba0e8.1622126603.git.gitgitgadget@gmail.com>
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> struct {
> enum { RAW_BARE, RAW_LENGTH } option;
> } raw_data;
> + struct {
> + enum { H_BARE, H_LENGTH } option;
> + } header;Raw does not use R_{BARE,LENGTH} and uses raw_data member. Header should follow suit unless there is a compelling reason not to, no?
struct {
enum { HEADER_BARE, HEADER_LENGTH } option;
} header_data;perhaps?
Show 6 quoted lines
> @@ -1372,6 +1389,15 @@ static void grab_raw_data(struct atom_value *val, int deref, void *buf, unsigned
> &bodypos, &bodylen, &nonsiglen,
> &sigpos, &siglen);
>
> + if (starts_with(name, "header")) {
> + size_t header_len = subpos - (const char *)buf - 1;Hmph, is this correct? I would expect that the "header" part of a commit or a tag object excludes the blank line after the header fields. In other words, the "header" would be separated by a blank line from the "body", and that separating blank line is not part of "header" or "body".
Otherwise, if there is a user of %(header), it needs to be coded to ignore the last blank line but has to diagnose it as an error if there is a blank line before that.
Show 10 quoted lines
> + if (atom->u.header.option == H_BARE) {
> + v->s = xmemdupz(buf, header_len);
> + } else if (atom->u.header.option == H_LENGTH)
> + v->s = xstrfmt("%"PRIuMAX, (uintmax_t)header_len);
> + continue;
> + }
> +
> if (atom->u.contents.option == C_SUB)
> v->s = copy_subject(subpos, sublen);
> else if (atom->u.contents.option == C_SUB_SANITIZE) {