git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: David Symonds <dsymonds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH] Fix quote_path when called with negative length.
Date: Mon, 03 Dec 2007 10:06:52 +0100	[thread overview]
Message-ID: <20071203090652.GA25154@artemis.madism.org> (raw)
In-Reply-To: <ee77f5c20712021539r3075fc57ld6a4cec737e6043d@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3238 bytes --]

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


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2007-12-03  9:07 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-02 22:04 v1.5.4 plans Junio C Hamano
2007-12-02 22:33 ` Jakub Narebski
2007-12-02 22:41   ` Junio C Hamano
2007-12-02 23:39 ` David Symonds
2007-12-03  2:32   ` Junio C Hamano
2007-12-03 10:00     ` Many things pushed out to 'master' Junio C Hamano
2007-12-03 11:12       ` Johannes Schindelin
2007-12-03 18:19         ` Junio C Hamano
2007-12-03 18:39           ` Johannes Schindelin
2007-12-03 20:58             ` Junio C Hamano
2007-12-03 22:44               ` [PATCH] fast-export: rename the signed tag mode 'ignore' to 'verbatim' Johannes Schindelin
2007-12-03 22:56                 ` Johannes Schindelin
2007-12-03  9:06   ` Pierre Habouzit [this message]
2007-12-03 17:18     ` [PATCH] Fix quote_path when called with negative length Jeff King
2007-12-03 18:06 ` v1.5.4 plans Nicolas Pitre
2007-12-03 21:23   ` Junio C Hamano
2007-12-14  3:32     ` [PATCH] provide advance warning of some future pack default changes Nicolas Pitre
2007-12-14  5:19       ` Junio C Hamano
2007-12-14 13:14         ` Nicolas Pitre
2007-12-14 12:45       ` Jakub Narebski
2007-12-14 13:38         ` Nicolas Pitre
2007-12-14 21:52           ` Joel Becker
2007-12-14 22:34             ` Nicolas Pitre
2007-12-14 22:39               ` Joel Becker
2007-12-14 22:46                 ` Nicolas Pitre
2007-12-15  0:42                   ` Joel Becker
2007-12-15  1:08                     ` Nicolas Pitre
2007-12-15  1:21                       ` Johannes Schindelin
2007-12-15  1:43                       ` Junio C Hamano
2007-12-15  2:23                     ` Nicolas Pitre
2007-12-17 20:09                       ` Joel Becker
2007-12-17 20:41                         ` Nicolas Pitre
2007-12-17 21:13                           ` Joel Becker
2007-12-17 21:30                             ` J. Bruce Fields
2007-12-17 21:52                               ` Nicolas Pitre
2007-12-17 21:57                                 ` J. Bruce Fields
2007-12-17 22:15                                   ` Nicolas Pitre
2007-12-17 22:17                                   ` Junio C Hamano
2007-12-17 22:30                                     ` J. Bruce Fields
2007-12-17 22:55                                       ` Junio C Hamano
2007-12-18  0:04                                         ` J. Bruce Fields
2007-12-17 23:13                                     ` Nicolas Pitre
2007-12-17 21:16                           ` Junio C Hamano
2007-12-17 21:45                             ` Nicolas Pitre
2007-12-18  0:41                               ` Junio C Hamano
2007-12-18  2:23                                 ` Mark Fasheh
2007-12-18  3:23                                 ` Nicolas Pitre
2007-12-18  3:52                                   ` Martin Langhoff
2007-12-18  4:09                                     ` Nicolas Pitre
2007-12-18  5:01                                     ` Junio C Hamano
2007-12-18  9:24                                       ` Jakub Narebski
2007-12-18 12:03                                         ` Johannes Schindelin
2007-12-18 14:16                                         ` Nicolas Pitre
2007-12-18 11:11                                       ` Jeff King
2007-12-18 12:06                                         ` Johannes Schindelin
2007-12-18 12:48                                           ` Jeff King
2007-12-18 13:30                                             ` Johannes Schindelin
2007-12-18 19:30                                               ` Jeff King
2007-12-18 20:12                                                 ` Nicolas Pitre
2007-12-18 13:47                                           ` Jakub Narebski
2007-12-18 20:24                                         ` Junio C Hamano
2007-12-18  2:15                           ` Mark Fasheh
2007-12-18  3:34                             ` Nicolas Pitre
2007-12-04  0:48 ` v1.5.4 plans Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071203090652.GA25154@artemis.madism.org \
    --to=madcoder@debian.org \
    --cc=dsymonds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).