mbox series

[v3,0/5,GSOC] ref-filter: add %(raw) and %(rest) atoms

Message ID pull.1000.v3.git.1627136061.gitgitgadget@gmail.com (mailing list archive)
Headers show
Series ref-filter: add %(raw) and %(rest) atoms | expand

Message

Lessley Dennington via GitGitGadget July 24, 2021, 2:14 p.m. UTC
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/pull.993.v2.git.1626363626.gitgitgadget@gmail.com/

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

v2--->v3:

 1. Add macro ATOM_SIZE_UNSPECIFIED to represent the initial value of
    atom_value->s_size.
 2. Add a description about %(rest) in the commit message. (copy from
    https://git-scm.com/docs/git-cat-file)

v2:
https://lore.kernel.org/git/CAP8UFD3ENBZdm8yQn6J-yb4PvUsrzTA3KGxes42dE3bTrYbr9Q@mail.gmail.com/

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                       | 244 ++++++++++++++++++++++-------
 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, 466 insertions(+), 63 deletions(-)


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

Range-diff vs v2:

 1:  d77268bb188 = 1:  d77268bb188 [GSOC] ref-filter: add obj-type check in grab contents
 2:  eafb79bad62 ! 2:  0ffa549da6e [GSOC] ref-filter: add %(raw) atom
     @@ ref-filter.c: struct ref_formatting_state {
       	struct used_atom *atom;
       };
       
     ++#define ATOM_SIZE_UNSPECIFIED (-1)
     ++
      +#define ATOM_VALUE_INIT { \
     -+	.s_size = -1 \
     ++	.s_size = ATOM_SIZE_UNSPECIFIED \
      +}
      +
       /*
     @@ 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 != -1)
     ++		if (v->s_size != ATOM_SIZE_UNSPECIFIED)
      +			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 = -1;
     ++		v->s_size = ATOM_SIZE_UNSPECIFIED;
       		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 == -1 && vb->s_size == -1) {
     ++		if (va->s_size == ATOM_SIZE_UNSPECIFIED && vb->s_size == ATOM_SIZE_UNSPECIFIED) {
      +			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 == -1 ?
     ++			size_t a_size = va->s_size == ATOM_SIZE_UNSPECIFIED ?
      +					strlen(va->s) : va->s_size;
     -+			size_t b_size = vb->s_size == -1 ?
     ++			size_t b_size = vb->s_size == ATOM_SIZE_UNSPECIFIED ?
      +					strlen(vb->s) : vb->s_size;
      +			int (*cmp_fn)(const void *, const void *, size_t);
      +			cmp_fn = s->sort_flags & REF_SORTING_ICASE
 3:  00a29dd16d7 = 3:  ac5d98647da [GSOC] ref-filter: --format=%(raw) re-support --perl
 4:  3a8173b42ed = 4:  0722f546df9 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()
 5:  71249dfd4e0 ! 5:  2300b0463f2 [GSOC] ref-filter: add %(rest) atom
     @@ Metadata
       ## Commit message ##
          [GSOC] ref-filter: add %(rest) atom
      
     +    %(rest) is a atom used for cat-file batch mode, which can split
     +    the input lines at the first whitespace boundary, all characters
     +    before that whitespace are considered to be the object name;
     +    characters after that first run of whitespace (i.e., the "rest"
     +    of the line) are output in place of the %(rest) atom.
     +
          In order to let "cat-file --batch=%(rest)" use the ref-filter
     -    interface, add %(rest) atom for ref-filter. Introduce the
     -    reject_atom() to reject the atom %(rest) for "git for-each-ref",
     -    "git branch", "git tag" and "git verify-tag".
     +    interface, add %(rest) atom for ref-filter.
     +
     +    Introduce the reject_atom() to reject the atom %(rest) for
     +    "git for-each-ref", "git branch", "git tag" and "git verify-tag".
      
     +    Suggected-by: Jacob Keller <jacob.keller@gmail.com>
          Mentored-by: Christian Couder <christian.couder@gmail.com>
          Mentored-by: Hariom Verma <hariom18599@gmail.com>
          Signed-off-by: ZheNing Hu <adlternative@gmail.com>