From: Jeff King Date: Mon, 3 Dec 2007 05:30:01 +0000 (-0500) Subject: quote_path: fix collapsing of relative paths X-Git-Tag: v1.5.4-rc0~78^2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=69e7491835a0aa4e1a793a7c131783d8bb1cbb2b;p=git.git quote_path: fix collapsing of relative paths The code tries to collapse identical leading components between the prefix and the path. So if we're in "dir1", the path "dir1/file" should become just "file". However, we were ending up with "../dir1/file". The included test expected the wrong output. The "len" parameter to quote_path can be negative to mean "this is a NUL terminated string". Simply count it so that the loop can rely on it being the length of the path. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/t/t7502-status.sh b/t/t7502-status.sh index 269b3341a..d6ae69d46 100755 --- a/t/t7502-status.sh +++ b/t/t7502-status.sh @@ -68,7 +68,7 @@ cat > expect << \EOF # Changed but not updated: # (use "git add ..." to update what will be committed) # -# modified: ../dir1/modified +# modified: modified # # Untracked files: # (use "git add ..." to include in what will be committed) diff --git a/wt-status.c b/wt-status.c index 0e0439f2c..52ab41ceb 100644 --- a/wt-status.c +++ b/wt-status.c @@ -82,12 +82,13 @@ static void wt_status_print_trailer(struct wt_status *s) } static char *quote_path(const char *in, int len, - struct strbuf *out, const char *prefix) + struct strbuf *out, const char *prefix) { - if (len > 0) - strbuf_grow(out, len); - strbuf_setlen(out, 0); + if (len < 0) + len = strlen(in); + strbuf_grow(out, len); + strbuf_setlen(out, 0); if (prefix) { int off = 0; while (prefix[off] && off < len && prefix[off] == in[off]) @@ -104,7 +105,7 @@ static char *quote_path(const char *in, int len, strbuf_addstr(out, "../"); } - for (; (len < 0 && *in) || len > 0; in++, len--) { + for ( ; len > 0; in++, len--) { int ch = *in; switch (ch) {