diff options
| author | ZheNing Hu <adlternative@gmail.com> | 2021-07-26 03:26:48 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2021-07-26 12:01:25 -0700 |
| commit | 7121c4d4e2877115fb372b3f147fad4cd1306751 (patch) | |
| tree | 99eba552be05773ac3b9e14a5358dafc72df2507 /quote.c | |
| parent | bd0708c7eb8be43242180a1ea2a0f0acda7a4fbc (diff) | |
| download | git-7121c4d4e2877115fb372b3f147fad4cd1306751.tar.xz | |
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)"` support `--perl`.
Reviewed-by: Jacob Keller <jacob.keller@gmail.com>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'quote.c')
| -rw-r--r-- | quote.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -471,6 +471,23 @@ void perl_quote_buf(struct strbuf *sb, const char *src) strbuf_addch(sb, sq); } +void perl_quote_buf_with_len(struct strbuf *sb, const char *src, size_t len) +{ + const char sq = '\''; + const char bq = '\\'; + const char *c = src; + const char *end = src + len; + + strbuf_addch(sb, sq); + while (c != end) { + if (*c == sq || *c == bq) + strbuf_addch(sb, bq); + strbuf_addch(sb, *c); + c++; + } + strbuf_addch(sb, sq); +} + void python_quote_buf(struct strbuf *sb, const char *src) { const char sq = '\''; |
