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

[PATCH] ls-tree: remove trailing slashes properly.

From
Junio C Hamano <junkio@cox.net>
Date
May 31, 2005, 21:49 UTC
Message-ID
<7vvf4zvzfw.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.58.0505310827330.1876@ppc970.osdl.org>
A typo prevented trailing slashes from being removed properly.

This fixes the problem that "drivers/char" which is a tree was not shown when "drivers/char/" is given.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 t/t3100-ls-tree-restrict.sh |   32 +++++++++++++++++++++++++++-----
 ls-tree.c                   |    2 +-
 2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/t/t3100-ls-tree-restrict.sh b/t/t3100-ls-tree-restrict.sh
--- a/t/t3100-ls-tree-restrict.sh
+++ b/t/t3100-ls-tree-restrict.sh
@@ -14,7 +14,7 @@ This test runs git-ls-tree with the foll
     path2/baz/b - a file in a directory in a directory
 
 The new path restriction code should do the right thing for path2 and
-path2/baz
+path2/baz.  Also path0/ should snow nothing.
 '
 . ./test-lib.sh
 
@@ -63,7 +63,7 @@ EOF
      test_output'
 
 test_expect_success \
-    'ls-tree filtered' \
+    'ls-tree filtered with path' \
     'git-ls-tree $tree path >current &&
      cat >expected <<\EOF &&
 EOF
@@ -71,7 +71,7 @@ EOF
 
 
 test_expect_success \
-    'ls-tree filtered' \
+    'ls-tree filtered with path1 path0' \
     'git-ls-tree $tree path1 path0 >current &&
      cat >expected <<\EOF &&
 120000 blob X	path1
@@ -80,7 +80,7 @@ EOF
      test_output'
 
 test_expect_success \
-    'ls-tree filtered' \
+    'ls-tree filtered with path2' \
     'git-ls-tree $tree path2 >current &&
      cat >expected <<\EOF &&
 040000 tree X	path2
@@ -91,7 +91,7 @@ EOF
      test_output'
 
 test_expect_success \
-    'ls-tree filtered' \
+    'ls-tree filtered with path2/baz' \
     'git-ls-tree $tree path2/baz >current &&
      cat >expected <<\EOF &&
 040000 tree X	path2/baz
@@ -99,4 +99,26 @@ test_expect_success \
 EOF
      test_output'
 
+test_expect_success \
+    'ls-tree filtered with path2' \
+    'git-ls-tree $tree path2 >current &&
+     cat >expected <<\EOF &&
+040000 tree X	path2
+040000 tree X	path2/baz
+120000 blob X	path2/bazbo
+100644 blob X	path2/foo
+EOF
+     test_output'
+
+test_expect_success \
+    'ls-tree filtered with path2/' \
+    'git-ls-tree $tree path2/ >current &&
+     cat >expected <<\EOF &&
+040000 tree X	path2
+040000 tree X	path2/baz
+120000 blob X	path2/bazbo
+100644 blob X	path2/foo
+EOF
+     test_output'
+
 test_done
diff --git a/ls-tree.c b/ls-tree.c
--- a/ls-tree.c
+++ b/ls-tree.c
@@ -201,7 +201,7 @@ static int list(char **path)
 	int err = 0;
 	for (i = 0; path[i]; i++) {
 		int len = strlen(path[i]);
-		while (0 <= len && path[i][len] == '/')
+		while (0 < len && path[i][len-1] == '/')
 			len--;
 		err = err | list_one(path[i], path[i] + len);
 	}
------------
Previous: Junio C HamanoNext: Linus Torvalds
Message 5 of 12 in “Re: [PATCH] allow pathspec to end with a slash”
  1. Linus TorvaldsMay 31, 2005
  2. Junio C HamanoMay 31, 2005
  3. 1/2 diff: consolidate test helper script pieces.Junio C Hamano, May 31, 2005
  4. 2/2 diff: Fix trailing slash handling.Junio C Hamano, May 31, 2005
  5. ls-tree: remove trailing slashes properly.Junio C Hamano, May 31, 2005
  6. Linus TorvaldsMay 31, 2005
  7. Junio C HamanoMay 31, 2005
  8. ls-tree: handle trailing slashes in the pathspec properly.Junio C Hamano, May 31, 2005
  9. Linus TorvaldsMay 31, 2005
  10. ls-tree: handle trailing slashes in the pathspec properly.Junio C Hamano, Jun 1, 2005
  11. Linus TorvaldsJun 1, 2005
  12. Junio C HamanoMay 31, 2005

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.