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

[PATCH v2 2/4] pathspec: strip multiple trailing slashes from submodules

From
John Keeping <john@keeping.me.uk>
Date
Sep 12, 2013, 19:24 UTC
Message-ID
<7c478c19da6ee3322ca87e77a90358a30178c286.1379013786.git.john@keeping.me.uk>
In-Reply-To
<cover.1379013786.git.john@keeping.me.uk>

This allows us to replace the submodule path trailing slash removal in builtin/rm.c with the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag to parse_pathspec() without changing the behaviour with respect to multiple trailing slashes.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 pathspec.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/pathspec.c b/pathspec.c
index 7c6963b..11b031a 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -251,12 +251,16 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 	item->len = strlen(item->match);
 	item->prefix = prefixlen;
 
-	if ((flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) &&
-	    (item->len >= 1 && is_dir_sep(item->match[item->len - 1])) &&
-	    (i = cache_name_pos(item->match, item->len - 1)) >= 0 &&
-	    S_ISGITLINK(active_cache[i]->ce_mode)) {
-		item->len--;
-		match[item->len] = '\0';
+	if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP) {
+		size_t pathlen = item->len;
+		while (pathlen > 0 && is_dir_sep(item->match[pathlen - 1]))
+			pathlen--;
+
+		if ((i = cache_name_pos(item->match, pathlen)) >= 0 &&
+		    S_ISGITLINK(active_cache[i]->ce_mode)) {
+			item->len = pathlen;
+			match[item->len] = '\0';
+		}
 	}
 
 	if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
@@ -271,11 +275,14 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 			    !is_dir_sep(match[ce_len]) ||
 			    memcmp(ce->name, match, ce_len))
 				continue;
-			if (item->len == ce_len + 1) {
-				/* strip trailing slash */
+
+			while (item->len > 0 && is_dir_sep(match[item->len - 1]))
 				item->len--;
-				match[item->len] = '\0';
-			} else
+
+			/* strip trailing slash */
+			match[item->len] = '\0';
+
+			if (item->len != ce_len)
 				die (_("Pathspec '%s' is in submodule '%.*s'"),
 				     elt, ce_len, ce->name);
 		}
-- 
1.8.4.277.gfbd6843.dirty
Previous: Johannes SixtNext: Junio C Hamano
Message 21 of 27 in “reset: handle submodule with trailing slash”
  1. 0/2 reset: handle submodule with trailing slashJohn Keeping, Sep 10, 2013
  2. 1/2 reset: handle submodule with trailing slashJohn Keeping, Sep 10, 2013
  3. Jens LehmannSep 10, 2013
  4. John KeepingSep 10, 2013
  5. Johannes SixtSep 11, 2013
  6. John KeepingSep 11, 2013
  7. Duy NguyenSep 11, 2013
  8. John KeepingSep 11, 2013
  9. Duy NguyenSep 11, 2013
  10. Junio C HamanoSep 11, 2013
  11. John KeepingSep 11, 2013
  12. Junio C HamanoSep 11, 2013
  13. John KeepingSep 11, 2013
  14. Junio C HamanoSep 11, 2013
  15. 2/2 rm: re-use parse_pathspec's trailing-slash removalJohn Keeping, Sep 10, 2013
  16. Duy NguyenSep 11, 2013
  17. John KeepingSep 11, 2013
  18. 0/4 submodule trailing slash improvementsJohn Keeping, Sep 12, 2013
  19. 1/4 pathspec: use is_dir_sep() to check for trailing slashesJohn Keeping, Sep 12, 2013
  20. Johannes SixtSep 12, 2013
  21. 2/4 pathspec: strip multiple trailing slashes from submodulesJohn Keeping, Sep 12, 2013
  22. Junio C HamanoSep 12, 2013
  23. John KeepingSep 12, 2013
  24. Duy NguyenSep 13, 2013
  25. John KeepingSep 13, 2013
  26. 3/4 rm: re-use parse_pathspec's trailing-slash removalJohn Keeping, Sep 12, 2013
  27. 4/4 reset: handle submodule with trailing slashJohn Keeping, Sep 12, 2013

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.