summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2007-12-03 05:30:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-12-03 07:35:46 (GMT)
commit69e7491835a0aa4e1a793a7c131783d8bb1cbb2b (patch)
treecfa2dbbec33eb2cfb6a2c0778e17d7b7089bcba4 /wt-status.c
parent2f02b25f36bce23e6b65c5112876796a56e084ca (diff)
downloadgit-69e7491835a0aa4e1a793a7c131783d8bb1cbb2b.zip
git-69e7491835a0aa4e1a793a7c131783d8bb1cbb2b.tar.gz
git-69e7491835a0aa4e1a793a7c131783d8bb1cbb2b.tar.bz2
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>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/wt-status.c b/wt-status.c
index 0e0439f..52ab41c 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) {