Subject: [PATCH v2 0/5] [GSOC] ref-filter: add %(raw) and %(rest) atoms

From: "ZheNing Hu via GitGitGadget" <[email-masked]>
Date: Fri, 23 Jul 2021 09:03:58 +0000

This patch series is split from my main patch series zh/ref-filter-raw-data,
to make things easier for reviewers to read. It's last version is here:
https://lore.kernel.org/git/[email-masked]/

This patch series provided %(raw) and %(rest) for ref-filter, which will be
used by zh/cat-file-reuse-ref-filter-logic later.

Change from last version:

 1. Define ATOM_VALUE_INIT used to initialize struct atom_value and delete
    ATOM_VALUE_S_SIZE_INIT macro.
 2. Provide more complete commit message.

ZheNing Hu (5):
  [GSOC] ref-filter: add obj-type check in grab contents
  [GSOC] ref-filter: add %(raw) atom
  [GSOC] ref-filter: --format=%(raw) re-support --perl
  [GSOC] ref-filter: use non-const ref_format in *_atom_parser()
  [GSOC] ref-filter: add %(rest) atom

 Documentation/git-for-each-ref.txt |   9 ++
 builtin/tag.c                      |   2 +-
 quote.c                            |  17 ++
 quote.h                            |   1 +
 ref-filter.c                       | 242 ++++++++++++++++++++++-------
 ref-filter.h                       |   9 +-
 t/t3203-branch-output.sh           |   4 +
 t/t6300-for-each-ref.sh            | 235 ++++++++++++++++++++++++++++
 t/t7004-tag.sh                     |   4 +
 t/t7030-verify-tag.sh              |   4 +
 10 files changed, 464 insertions(+), 63 deletions(-)

base-commit: daab8a564f8bbac55f70f8bf86c070e001a9b006
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1000%2Fadlternative%2Fref-filter-raw-data-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1000/adlternative/ref-filter-raw-data-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1000

Range-diff vs v1:

 1:  a7b4e45f14a ! 1:  d77268bb188 [GSOC] ref-filter: add obj-type check in grab contents
     @@ Commit message
          object contents in the current codebase.  We want to teach the
          function to also handle blobs and trees to get their raw data,
          without parsing a blob (whose contents looks like a commit or a tag)
     -    incorrectly as a commit or a tag.
     +    incorrectly as a commit or a tag. So it's needed to pass a
     +    `struct expand_data *data` instread of only `void *buf` to both
     +    `grab_sub_body_contents()` and `grab_values()` to be able to check
     +    the object type.
      
          Skip the block of code that is specific to handling commits and tags
          early when the given object is of a wrong type to help later
 2:  ecd41b370e6 ! 2:  eafb79bad62 [GSOC] ref-filter: add %(raw) atom
     @@ ref-filter.c: struct ref_formatting_state {
       	struct used_atom *atom;
       };
       
     -+#define ATOM_VALUE_S_SIZE_INIT (-1)
     ++#define ATOM_VALUE_INIT { \
     ++	.s_size = -1 \
     ++}
      +
       /*
        * Used to parse format string and sort specifiers
     @@ ref-filter.c: static int parse_ref_filter_atom(const struct ref_format *format,
       	switch (quote_style) {
       	case QUOTE_NONE:
      -		strbuf_addstr(s, str);
     -+		if (len != ATOM_VALUE_S_SIZE_INIT)
     ++		if (len != -1)
      +			strbuf_add(s, str, len);
      +		else
      +			strbuf_addstr(s, str);
     @@ ref-filter.c: static int append_atom(struct atom_value *v, struct ref_formatting
      +		quote_formatting(&state->stack->output, v->s, v->s_size, state->quote_style);
       	else
      -		strbuf_addstr(&state->stack->output, v->s);
     -+		if (v->s_size != ATOM_VALUE_S_SIZE_INIT)
     ++		if (v->s_size != -1)
      +			strbuf_add(&state->stack->output, v->s, v->s_size);
      +		else
      +			strbuf_addstr(&state->stack->output, v->s);
     @@ ref-filter.c: static int populate_value(struct ref_array_item *ref, struct strbu
       		const char *refname;
       		struct branch *branch = NULL;
       
     -+		v->s_size = ATOM_VALUE_S_SIZE_INIT;
     ++		v->s_size = -1;
       		v->handler = append_atom;
       		v->atom = atom;
       
     @@ ref-filter.c: static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array
      -		cmp_fn = s->sort_flags & REF_SORTING_ICASE
      -			? strcasecmp : strcmp;
      -		cmp = cmp_fn(va->s, vb->s);
     -+		if (va->s_size == ATOM_VALUE_S_SIZE_INIT &&
     -+		    vb->s_size == ATOM_VALUE_S_SIZE_INIT) {
     ++		if (va->s_size == -1 && vb->s_size == -1) {
      +			int (*cmp_fn)(const char *, const char *);
      +			cmp_fn = s->sort_flags & REF_SORTING_ICASE
      +				? strcasecmp : strcmp;
      +			cmp = cmp_fn(va->s, vb->s);
      +		} else {
     -+			size_t a_size = va->s_size == ATOM_VALUE_S_SIZE_INIT ?
     ++			size_t a_size = va->s_size == -1 ?
      +					strlen(va->s) : va->s_size;
     -+			size_t b_size = vb->s_size == ATOM_VALUE_S_SIZE_INIT ?
     ++			size_t b_size = vb->s_size == -1 ?
      +					strlen(vb->s) : vb->s_size;
      +			int (*cmp_fn)(const void *, const void *, size_t);
      +			cmp_fn = s->sort_flags & REF_SORTING_ICASE
     @@ ref-filter.c: static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array
       		if (va->value < vb->value)
       			cmp = -1;
      @@ ref-filter.c: int format_ref_array_item(struct ref_array_item *info,
     + 		append_literal(cp, sp, &state);
       	}
       	if (format->need_color_reset_at_eol) {
     - 		struct atom_value resetv;
     -+		resetv.s_size = ATOM_VALUE_S_SIZE_INIT;
     +-		struct atom_value resetv;
     ++		struct atom_value resetv = ATOM_VALUE_INIT;
       		resetv.s = GIT_COLOR_RESET;
       		if (append_atom(&resetv, &state, error_buf)) {
       			pop_stack_element(&state.stack);
 3:  b6438fd4308 ! 3:  00a29dd16d7 [GSOC] ref-filter: --format=%(raw) re-support --perl
     @@ ref-filter.c: static void quote_formatting(struct strbuf *s, const char *str, si
       		break;
       	case QUOTE_PERL:
      -		perl_quote_buf(s, str);
     -+		if (len != ATOM_VALUE_S_SIZE_INIT)
     ++		if (len != -1)
      +			perl_quote_buf_with_len(s, str, len);
      +		else
      +			perl_quote_buf(s, str);
 4:  33d332c664e = 4:  3a8173b42ed [GSOC] ref-filter: use non-const ref_format in *_atom_parser()
 5:  75eb2f6740e = 5:  71249dfd4e0 [GSOC] ref-filter: add %(rest) atom

-- 
gitgitgadget