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

[PATCH v3 17/31] parse_pathspec: support stripping/checking submodule paths

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 13, 2013, 12:35 UTC
Message-ID
<1358080539-17436-18-git-send-email-pclouds@gmail.com>
In-Reply-To
<1358080539-17436-1-git-send-email-pclouds@gmail.com>

PATHSPEC_SYMLINK_LEADING_PATH and _STRIP_SUBMODULE_SLASH_EXPENSIVE are respectively the alternate implementation of builtin/add.c:validate_pathspec() and builtin/add.c:treat_gitlinks(). They are intended to replace those functions when builtin/add.c is converted to use parse_pathspec.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h |  2 ++
 setup.c | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
diff --git a/cache.h b/cache.h
index 611a410..a49496e 100644
--- a/cache.h
+++ b/cache.h
@@ -506,6 +506,8 @@ struct pathspec {
 /* parse_pathspec flags */
 #define PATHSPEC_EMPTY_MATCH_ALL (1<<0) /* No args means match everything */
 #define PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP (1<<1)
+#define PATHSPEC_SYMLINK_LEADING_PATH (1<<2) /* has_symlink_leading_path */
+#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<3)
 
 extern int init_pathspec(struct pathspec *, const char **);
 extern void parse_pathspec(struct pathspec *pathspec, unsigned magic_mask,
diff --git a/setup.c b/setup.c
index a1aabc2..b6f419d 100644
--- a/setup.c
+++ b/setup.c
@@ -259,6 +259,26 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
 		match[item->len] = '\0';
 	}
 
+	if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
+		for (i = 0; i < active_nr; i++) {
+			struct cache_entry *ce = active_cache[i];
+			int ce_len = ce_namelen(ce);
+
+			if (!S_ISGITLINK(ce->ce_mode))
+				continue;
+
+			if (item->len <= ce_len || match[ce_len] != '/' ||
+			    memcmp(ce->name, match, ce_len))
+				continue;
+			if (item->len == ce_len + 1) {
+				/* strip trailing slash */
+				item->len--;
+				match[item->len] = '\0';
+			} else
+				die (_("Pathspec '%s' is in submodule '%.*s'"),
+				     elt, ce_len, ce->name);
+		}
+
 	item->flags = 0;
 	if (limit_pathspec_to_literal())
 		item->nowildcard_len = item->len;
@@ -333,6 +353,12 @@ void parse_pathspec(struct pathspec *pathspec,
 		if (item[i].magic & ~magic_mask)
 			die(_("pathspec magic in '%s' is not supported"
 			      " by this command"), arg);
+
+		if ((flags & PATHSPEC_SYMLINK_LEADING_PATH) &&
+		    has_symlink_leading_path(item[i].match, item[i].len)) {
+			die(_("pathspec '%s' is beyond a symbolic link"), arg);
+		}
+
 		if (item[i].nowildcard_len < item[i].len)
 			pathspec->has_wildcard = 1;
 		pathspec->magic |= item[i].magic;
-- 
1.8.0.rc2.23.g1fb49df
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 22 of 37 in “nd/parse-pathspec”
  1. 00/31 nd/parse-pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  2. 01/31 clean: remove unused variable "seen"Nguyễn Thái Ngọc Duy, Jan 13, 2013
  3. 02/31 Add copy_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  4. 03/31 Add parse_pathspec() that converts cmdline args to struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  5. Martin von ZweigbergkJan 14, 2013
  6. Duy NguyenJan 14, 2013
  7. 04/31 parse_pathspec: save original pathspec for reportingNguyễn Thái Ngọc Duy, Jan 13, 2013
  8. 05/31 Export parse_pathspec() and convert some get_pathspec() callsNguyễn Thái Ngọc Duy, Jan 13, 2013
  9. 06/31 Guard against new pathspec magic in pathspec matching codeNguyễn Thái Ngọc Duy, Jan 13, 2013
  10. 07/31 clean: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  11. 08/31 parse_pathspec: add PATHSPEC_EMPTY_MATCH_ALLNguyễn Thái Ngọc Duy, Jan 13, 2013
  12. Martin von ZweigbergkJan 21, 2013
  13. Duy NguyenJan 22, 2013
  14. 09/31 commit: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  15. 10/31 status: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  16. 11/31 rerere: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  17. 12/31 checkout: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  18. 13/31 rm: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  19. 14/31 parse_pathspec: support stripping submodule trailing slashesNguyễn Thái Ngọc Duy, Jan 13, 2013
  20. 15/31 ls-files: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  21. 16/31 archive: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  22. 17/31 parse_pathspec: support stripping/checking submodule pathsNguyễn Thái Ngọc Duy, Jan 13, 2013
  23. 18/31 add: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  24. 19/31 Convert read_cache_preload() to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  25. 20/31 Convert unmerge_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  26. 21/31 checkout: convert read_tree_some to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  27. 22/31 Convert report_path_error to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  28. 23/31 Convert refresh_index to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  29. 24/31 Convert {read,fill}_directory to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  30. 25/31 Convert add_files_to_cache to take struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  31. 26/31 Convert common_prefix() to use struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  32. 27/31 Remove diff_tree_{setup,release}_pathsNguyễn Thái Ngọc Duy, Jan 13, 2013
  33. 28/31 Remove init_pathspec() in favor of parse_pathspec()Nguyễn Thái Ngọc Duy, Jan 13, 2013
  34. 29/31 Remove match_pathspec() in favor of match_pathspec_depth()Nguyễn Thái Ngọc Duy, Jan 13, 2013
  35. 30/31 tree-diff: remove the use of pathspec's raw[] in follow-rename codepathNguyễn Thái Ngọc Duy, Jan 13, 2013
  36. 31/31 Rename field "raw" to "_raw" in struct pathspecNguyễn Thái Ngọc Duy, Jan 13, 2013
  37. Junio C HamanoJan 13, 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.