From: Junio C Hamano Date: Sun, 9 Mar 2008 05:29:56 +0000 (-0800) Subject: Merge branch 'dp/clean-fix' X-Git-Tag: v1.5.5-rc0~41 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/175f5595511b047a320e5c6163c642ac1fc34681?hp=-c Merge branch 'dp/clean-fix' * dp/clean-fix: git-clean: add tests for relative path git-clean: correct printing relative path Make private quote_path() in wt-status.c available as quote_path_relative() Revert part of d089eba (setup: sanitize absolute and funny paths in get_pathspec()) Revert part of 1abf095 (git-add: adjust to the get_pathspec() changes) Revert part of 744dacd (builtin-mv: minimum fix to avoid losing files) get_pathspec(): die when an out-of-tree path is given --- 175f5595511b047a320e5c6163c642ac1fc34681 diff --combined quote.c index 40702f6b72,e38ba39b64..d5cf9d8f94 --- a/quote.c +++ b/quote.c @@@ -260,6 -260,48 +260,48 @@@ extern void write_name_quotedpfx(const fputc(terminator, fp); } + /* quote path as relative to the given prefix */ + char *quote_path_relative(const char *in, int len, + struct strbuf *out, const char *prefix) + { + int needquote; + + if (len < 0) + len = strlen(in); + + /* "../" prefix itself does not need quoting, but "in" might. */ + needquote = next_quote_pos(in, len) < len; + strbuf_setlen(out, 0); + strbuf_grow(out, len); + + if (needquote) + strbuf_addch(out, '"'); + if (prefix) { + int off = 0; + while (prefix[off] && off < len && prefix[off] == in[off]) + if (prefix[off] == '/') { + prefix += off + 1; + in += off + 1; + len -= off + 1; + off = 0; + } else + off++; + + for (; *prefix; prefix++) + if (*prefix == '/') + strbuf_addstr(out, "../"); + } + + quote_c_style_counted (in, len, out, NULL, 1); + + if (needquote) + strbuf_addch(out, '"'); + if (!out->len) + strbuf_addstr(out, "./"); + + return out->buf; + } + /* * C-style name unquoting. * @@@ -288,7 -330,7 +330,7 @@@ int unquote_c_style(struct strbuf *sb, switch (*quoted++) { case '"': if (endp) - *endp = quoted + 1; + *endp = quoted; return 0; case '\\': break;