MCPcopy Create free account
hub / github.com/git/git / sq_quote_buf

Function sq_quote_buf

quote.c:28–48  ·  view source on GitHub ↗

Help to copy the thing properly quoted for the shell safety. * any single quote is replaced with '\'', any exclamation point * is replaced with '\!', and the whole thing is enclosed in a * single quote pair. * * E.g. * original sq_quote result * name ==> name ==> 'name' * a b ==> a b ==> 'a b' * a'b ==> a'\''b ==> 'a'\''b' * a!b ==> a'\!'b

Source from the content-addressed store, hash-verified

26 * a!b ==> a'\!'b ==> 'a'\!'b'
27 */
28void sq_quote_buf(struct strbuf *dst, const char *src)
29{
30 char *to_free = NULL;
31
32 if (dst->buf == src)
33 to_free = strbuf_detach(dst, NULL);
34
35 strbuf_addch(dst, '\'');
36 while (*src) {
37 size_t len = strcspn(src, "'!");
38 strbuf_add(dst, src, len);
39 src += len;
40 while (need_bs_quote(*src)) {
41 strbuf_addstr(dst, "'\\");
42 strbuf_addch(dst, *src++);
43 strbuf_addch(dst, '\'');
44 }
45 }
46 strbuf_addch(dst, '\'');
47 free(to_free);
48}
49
50void sq_quote_buf_pretty(struct strbuf *dst, const char *src)
51{

Callers 11

quote_formattingFunction · 0.85
git_connectFunction · 0.85
ll_ext_mergeFunction · 0.85
sq_quote_buf_prettyFunction · 0.85
sq_quotefFunction · 0.85
sq_quote_argvFunction · 0.85
filter_buffer_or_fdFunction · 0.85
write_author_scriptFunction · 0.85
parseopt_dumpFunction · 0.85

Calls 5

strbuf_detachFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_addFunction · 0.85
need_bs_quoteFunction · 0.85
strbuf_addstrFunction · 0.85

Tested by

no test coverage detected