From 7121c4d4e2877115fb372b3f147fad4cd1306751 Mon Sep 17 00:00:00 2001 From: ZheNing Hu Date: Mon, 26 Jul 2021 03:26:48 +0000 Subject: ref-filter: --format=%(raw) support --perl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: ZheNing Hu Signed-off-by: Junio C Hamano --- quote.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'quote.c') diff --git a/quote.c b/quote.c index 8a3a5e39eb..26719d21d1 100644 --- a/quote.c +++ b/quote.c @@ -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 = '\''; -- cgit v1.2.3