Skip to content

Commit

Permalink
quote_path: fix collapsing of relative paths
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 3, 2007
1 parent 2f02b25 commit 69e7491
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion t/t7502-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cat > expect << \EOF
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: ../dir1/modified
# modified: modified
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
Expand Down
11 changes: 6 additions & 5 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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) {
Expand Down

0 comments on commit 69e7491

Please sign in to comment.