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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 3, 2007 at 00:30 UTC
69e7491835a0aa4e1a793a7c131783d8bb1cbb2b
2 files changed
+7
-6
t/t7502-status.sh
+1
-1
@@ -68,7 +68,7 @@ cat > expect << \EOF
68
# Changed but not updated:
69
# (use "git add <file>..." to update what will be committed)
70
#
71
-# modified: ../dir1/modified
71
+# modified: modified
72
#
73
# Untracked files:
74
# (use "git add <file>..." to include in what will be committed)
wt-status.c
+6
-5
@@ -82,12 +82,13 @@ static void wt_status_print_trailer(struct wt_status *s)
82
}
83
84
static char *quote_path(const char *in, int len,
85
- struct strbuf *out, const char *prefix)
85
+ struct strbuf *out, const char *prefix)
86
{
87
- if (len > 0)
88
- strbuf_grow(out, len);
89
- strbuf_setlen(out, 0);
87
+ if (len < 0)
88
+ len = strlen(in);
89
90
+ strbuf_grow(out, len);
91
+ strbuf_setlen(out, 0);
92
if (prefix) {
93
int off = 0;
94
while (prefix[off] && off < len && prefix[off] == in[off])
@@ -104,7 +105,7 @@ static char *quote_path(const char *in, int len,
105
strbuf_addstr(out, "../");
106
}
107
107
- for (; (len < 0 && *in) || len > 0; in++, len--) {
108
+ for ( ; len > 0; in++, len--) {
109
int ch = *in;
110
111
switch (ch) {