Skip to content

ref-filter: add %(raw) and %(rest) atoms

ZheNing Hu via GitGitGadget git 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 2 repliesIn review
  2. v35 patches 5 repliesSuperseded
  3. v25 patches 4 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v15 patches10 repliesSuperseded

v3 from the cover letter

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5ref-filter: add obj-type check in grab contentsref-filter.c+15 -92 replies
2/5ref-filter: add %(raw) atomDocumentation/git-for-each-ref.txt ref-filter.c t/t6300-for-each-ref.sh+340 -280 replies
3/5ref-filter: --format=%(raw) support --perlDocumentation/git-for-each-ref.txt quote.c quote.h +2 more+48 -80 replies
4/5ref-filter: use non-const ref_format in *_atom_parser()builtin/tag.c ref-filter.c ref-filter.h+25 -250 replies
5/5ref-filter: add %(rest) atomref-filter.c ref-filter.h t/t3203-branch-output.sh +3 more+45 -10 replies

Reviews trailers per patch

4 of 5 patches have a Reviewed-by or Acked-by.

PatchJacob KellerChristian CouderHariom VermaJunio C HamanoÆvar Arnfjörð BjarmasonBagas SanjayaFelipe ContrerasPhillip WoodOlga Telezhnaya
SeriesSuggected-by Mentored-by Mentored-by Mentored-by Mentored-by Helped-by Helped-by
1/5R-b Mentored-by Mentored-by Helped-by
2/5R-b Mentored-by Mentored-by Helped-by Helped-by Helped-by Helped-by Helped-by Based-on-patch-by
3/5R-b Helped-by
4/5Mentored-by Mentored-by
5/5R-b Suggected-by Mentored-by Mentored-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/5] [GSOC] ref-filter: add %(raw) and %(rest) atoms

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 protected]/

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

v3--->v4:

1. Change the type of atom_value->s_size from size_t to ssize_t, and change the type of quote_formatting() parameters len from size_t to ssize_t at the same time. All of if (v->s_size == -1) change to if (v->s_size < 0).
2. Correct the commit subject of "[GSOC] ref-filter: --format=%(raw) re-support --perl" to "[GSOC] ref-filter: --format=%(raw) support --perl" and its commit messages.

v3:
https://lore.kernel.org/git/[email protected]/

ZheNing Hu (5):
[GSOC] ref-filter: add obj-type check in grab contents [GSOC] ref-filter: add %(raw) atom
[GSOC] ref-filter: --format=%(raw) 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                       | 243 ++++++++++++++++++++++-------
 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, 465 insertions(+), 63 deletions(-)

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

Range-diff vs v3:

1: d77268bb188 ! 1: 0e294ff1626 [GSOC] ref-filter: add obj-type check in grab contents
@@ Commit message
early when the given object is of a wrong type to help later addition to handle other types of objects in this function.

+ Reviewed-by: Jacob Keller <[email protected]>

2: 0ffa549da6e ! 2: 96d79a3d16b [GSOC] ref-filter: add %(raw) atom

     @@ Commit message
          variable in such languages, these may not support arbitrary binary data
          in their string variable type.
      
     +    Reviewed-by: Jacob Keller <[email protected]>
          Mentored-by: Christian Couder <[email protected]>
          Mentored-by: Hariom Verma <[email protected]>
          Helped-by: Bagas Sanjaya <[email protected]>
     @@ ref-filter.c: struct ref_formatting_state {
       
       struct atom_value {
       	const char *s;
     -+	size_t s_size;
     ++	ssize_t s_size;
       	int (*handler)(struct atom_value *atomv, struct ref_formatting_state *state,
       		       struct strbuf *err);
       	uintmax_t value; /* used for sorting when not FIELD_STR */
     @@ ref-filter.c: static int parse_ref_filter_atom(const struct ref_format *format,
       }
       
      -static void quote_formatting(struct strbuf *s, const char *str, int quote_style)
     -+static void quote_formatting(struct strbuf *s, const char *str, size_t len, int quote_style)
     ++static void quote_formatting(struct strbuf *s, const char *str, ssize_t len, int quote_style)
       {
       	switch (quote_style) {
       	case QUOTE_NONE:
      -		strbuf_addstr(s, str);
     -+		if (len != -1)
     -+			strbuf_add(s, str, len);
     -+		else
     ++		if (len < 0)
      +			strbuf_addstr(s, str);
     ++		else
     ++			strbuf_add(s, str, len);
       		break;
       	case QUOTE_SHELL:
       		sq_quote_buf(s, str);
     @@ ref-filter.c: static int append_atom(struct atom_value *v, struct ref_formatting
       	 */
       	if (!state->stack->prev)
      -		quote_formatting(&state->stack->output, v->s, state->quote_style);
     +-	else
      +		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_SIZE_UNSPECIFIED)
     -+			strbuf_add(&state->stack->output, v->s, v->s_size);
     -+		else
     -+			strbuf_addstr(&state->stack->output, v->s);
     ++	else if (v->s_size < 0)
     + 		strbuf_addstr(&state->stack->output, v->s);
     ++	else
     ++		strbuf_add(&state->stack->output, v->s, v->s_size);
       	return 0;
       }
       
     @@ 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_SIZE_UNSPECIFIED && vb->s_size == ATOM_SIZE_UNSPECIFIED) {
     ++		if (va->s_size < 0 && vb->s_size < 0) {
      +			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_SIZE_UNSPECIFIED ?
     ++			size_t a_size = va->s_size < 0 ?
      +					strlen(va->s) : va->s_size;
     -+			size_t b_size = vb->s_size == ATOM_SIZE_UNSPECIFIED ?
     ++			size_t b_size = vb->s_size < 0 ?
      +					strlen(vb->s) : vb->s_size;
      +			int (*cmp_fn)(const void *, const void *, size_t);
      +			cmp_fn = s->sort_flags & REF_SORTING_ICASE

3: ac5d98647da ! 3: d14fae52080 [GSOC] ref-filter: --format=%(raw) re-support --perl
@@ Metadata
Author: ZheNing Hu <[email protected]>

## Commit message ##
- [GSOC] ref-filter: --format=%(raw) re-support --perl
+ [GSOC] ref-filter: --format=%(raw) support --perl

Because the perl language can handle binary data correctly, add the function perl_quote_buf_with_len(), which can specify the length of the data and prevent the data from being truncated
- at '\0' to help --format="%(raw)" re-support --perl.
+ at '\0' to help --format="%(raw)" support --perl.

+ Reviewed-by: Jacob Keller <[email protected]>

@@ quote.h: char *quote_path(const char *in, const char *prefix, struct strbuf *out
void basic_regex_quote_buf(struct strbuf *sb, const char *src);

## ref-filter.c ##
-@@ ref-filter.c: static void quote_formatting(struct strbuf *s, const char *str, size_t len, int +@@ ref-filter.c: static void quote_formatting(struct strbuf *s, const char *str, ssize_t len, int
sq_quote_buf(s, str);
break;
case QUOTE_PERL:
- perl_quote_buf(s, str);
-+ if (len != -1)
-+ perl_quote_buf_with_len(s, str, len);
-+ else
++ if (len < 0)
+ perl_quote_buf(s, str);
++ else
++ perl_quote_buf_with_len(s, str, len);
break;
case QUOTE_PYTHON:
python_quote_buf(s, str);

 4:  0722f546df9 = 4:  0aa398e8a8f [GSOC] ref-filter: use non-const ref_format in *_atom_parser()
 5:  2300b0463f2 ! 5:  207cc512964 [GSOC] ref-filter: add %(rest) atom

@@ Commit message
Introduce the reject_atom() to reject the atom %(rest) for "git for-each-ref", "git branch", "git tag" and "git verify-tag".

+ Reviewed-by: Jacob Keller <[email protected]>

Signature · 1 line
gitgitgadget