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@xxxxxxxxx/ 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/pull.1000.v3.git.1627136061.gitgitgadget@xxxxxxxxx/ 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 <jacob.keller@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Hariom Verma <hariom18599@xxxxxxxxx> Helped-by: Junio C Hamano <gitster@xxxxxxxxx> 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 <jacob.keller@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Hariom Verma <hariom18599@xxxxxxxxx> Helped-by: Bagas Sanjaya <bagasdotme@xxxxxxxxx> @@ 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 <adlternative@xxxxxxxxx> ## 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 <jacob.keller@xxxxxxxxx> Helped-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx> @@ 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 <jacob.keller@xxxxxxxxx> Suggected-by: Jacob Keller <jacob.keller@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Hariom Verma <hariom18599@xxxxxxxxx> -- gitgitgadget