git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix quote_path when called with negative length.

From
Pierre Habouzit <madcoder@debian.org>
Date
Dec 3, 2007, 09:06 UTC
Message-ID
<20071203090652.GA25154@artemis.madism.org>
In-Reply-To
<ee77f5c20712021539r3075fc57ld6a4cec737e6043d@mail.gmail.com>

When the len passed was -1, relative paths shortening was broken, resulting in too long paths.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
    On Sun, Dec 02, 2007 at 11:39:59PM +0000, David Symonds wrote:
    > On Dec 3, 2007 9:04 AM, Junio C Hamano <gitster@pobox.com> wrote:
    > > Please do not take this as the final decision made by the Emperor, whose
    > > subjects now must follow.  This is a sanity-check to see if everybody is
    > > on the same page.
    > >
    > > I am not the Emperor anyway ;-)
    > >
    > 
    > > Topics not in 'master' yet but should be in v1.5.4
    > > --------------------------------------------------
    > >
    > > I think the following should go in, along with what we already have in
    > > 'master':
    > 
    > Can we add the git-status/git-checkout relative path stuff that's
    > currently been sitting in 'next'? It would be a good step forward for
    > usability.
    Speaking of which, there is this irritating bug in git status that
    let it show too long paths in the first chunk (the "tracked files"
    one).
    The previous version of the function was avoiding very hard to
    compute "in" length, and had quite convoluted code because of that.
    I now compute it at the beginning. The real issue was the:
 		while (prefix[off] && off < len && prefix[off] == in[off])
    line, when len is negative, the shortening never happens. I could
    have fixed it using ((len < 0 && in[off]) || off < len), but I
    disliked the resulting code, so I went for this.
    -- 
    ·O·  Pierre Habouzit
    ··O                                                madcoder@debian.org
    OOO                                                http://www.madism.org
 wt-status.c |   31 +++++++++++++------------------
 1 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index 0e0439f..eb2cbea 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -84,30 +84,25 @@ 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)
 {
-	if (len > 0)
-		strbuf_grow(out, len);
+	int pos = 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])
-			if (prefix[off] == '/') {
-				prefix += off + 1;
-				in += off + 1;
-				len -= off + 1;
-				off = 0;
-			} else
-				off++;
-
-		for (; *prefix; prefix++)
-			if (*prefix == '/')
+			if (prefix[off++] == '/')
+				pos = off;
+		while (prefix[off])
+			if (prefix[off++] == '/')
 				strbuf_addstr(out, "../");
 	}
 
-	for (; (len < 0 && *in) || len > 0; in++, len--) {
-		int ch = *in;
-
-		switch (ch) {
+	for (; pos < len; pos++) {
+		switch (in[pos]) {
 		case '\n':
 			strbuf_addstr(out, "\\n");
 			break;
@@ -115,8 +110,8 @@ static char *quote_path(const char *in, int len,
 			strbuf_addstr(out, "\\r");
 			break;
 		default:
-			strbuf_addch(out, ch);
-			continue;
+			strbuf_addch(out, in[pos]);
+			break;
 		}
 	}
 
-- 
1.5.3.7.2065.g3d18-dirty
Previous: Johannes SchindelinNext: Jeff King
Message 13 of 64 in “v1.5.4 plans”
  1. Junio C HamanoDec 2, 2007
  2. Jakub NarebskiDec 2, 2007
  3. Junio C HamanoDec 2, 2007
  4. David SymondsDec 2, 2007
  5. Junio C HamanoDec 3, 2007
  6. Many things pushed out to 'master'Junio C Hamano, Dec 3, 2007
  7. Johannes SchindelinDec 3, 2007
  8. Junio C HamanoDec 3, 2007
  9. Johannes SchindelinDec 3, 2007
  10. Junio C HamanoDec 3, 2007
  11. fast-export: rename the signed tag mode 'ignore' to 'verbatim'Johannes Schindelin, Dec 3, 2007
  12. Johannes SchindelinDec 3, 2007
  13. Fix quote_path when called with negative length.Pierre Habouzit, Dec 3, 2007
  14. Jeff KingDec 3, 2007
  15. Nicolas PitreDec 3, 2007
  16. Junio C HamanoDec 3, 2007
  17. provide advance warning of some future pack default changesNicolas Pitre, Dec 14, 2007
  18. Junio C HamanoDec 14, 2007
  19. Nicolas PitreDec 14, 2007
  20. Jakub NarebskiDec 14, 2007
  21. Nicolas PitreDec 14, 2007
  22. Joel BeckerDec 14, 2007
  23. Nicolas PitreDec 14, 2007
  24. Joel BeckerDec 14, 2007
  25. Nicolas PitreDec 14, 2007
  26. Joel BeckerDec 15, 2007
  27. Nicolas PitreDec 15, 2007
  28. Johannes SchindelinDec 15, 2007
  29. Junio C HamanoDec 15, 2007
  30. Nicolas PitreDec 15, 2007
  31. Joel BeckerDec 17, 2007
  32. Nicolas PitreDec 17, 2007
  33. Joel BeckerDec 17, 2007
  34. J. Bruce FieldsDec 17, 2007
  35. Nicolas PitreDec 17, 2007
  36. J. Bruce FieldsDec 17, 2007
  37. Nicolas PitreDec 17, 2007
  38. Junio C HamanoDec 17, 2007
  39. J. Bruce FieldsDec 17, 2007
  40. Junio C HamanoDec 17, 2007
  41. J. Bruce FieldsDec 18, 2007
  42. Nicolas PitreDec 17, 2007
  43. Junio C HamanoDec 17, 2007
  44. Nicolas PitreDec 17, 2007
  45. Junio C HamanoDec 18, 2007
  46. Mark FashehDec 18, 2007
  47. Nicolas PitreDec 18, 2007
  48. Martin LanghoffDec 18, 2007
  49. Nicolas PitreDec 18, 2007
  50. Junio C HamanoDec 18, 2007
  51. Jakub NarebskiDec 18, 2007
  52. Johannes SchindelinDec 18, 2007
  53. Nicolas PitreDec 18, 2007
  54. Jeff KingDec 18, 2007
  55. Johannes SchindelinDec 18, 2007
  56. Jeff KingDec 18, 2007
  57. Johannes SchindelinDec 18, 2007
  58. Jeff KingDec 18, 2007
  59. Nicolas PitreDec 18, 2007
  60. Jakub NarebskiDec 18, 2007
  61. Junio C HamanoDec 18, 2007
  62. Mark FashehDec 18, 2007
  63. Nicolas PitreDec 18, 2007
  64. RussellDec 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.