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

[PATCH v1 36/45] Remove init_pathspec() in favor of parse_pathspec()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 15, 2013, 06:06 UTC
Message-ID
<1363327620-29017-37-git-send-email-pclouds@gmail.com>
In-Reply-To
<1363327620-29017-1-git-send-email-pclouds@gmail.com>
While at there, move free_pathspec() to pathspec.c
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/blame.c    |  8 +-------
 builtin/log.c      |  2 +-
 builtin/ls-files.c | 11 +++++------
 diff-lib.c         |  2 +-
 dir.c              | 58 ------------------------------------------------------
 merge-recursive.c  |  2 +-
 pathspec.c         |  6 ++++++
 pathspec.h         |  1 -
 revision.c         |  2 +-
 tree-diff.c        | 10 +++++-----
 10 files changed, 21 insertions(+), 81 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index da2dc4c..5b91e94 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -407,7 +407,7 @@ static struct origin *find_origin(struct scoreboard *sb,
 	paths[0] = origin->path;
 	paths[1] = NULL;
 
-	init_pathspec(&diff_opts.pathspec, paths);
+	parse_pathspec(&diff_opts.pathspec, PATHSPEC_ALL_MAGIC, 0, "", paths);
 	diff_setup_done(&diff_opts);
 
 	if (is_null_sha1(origin->commit->object.sha1))
@@ -485,15 +485,12 @@ static struct origin *find_rename(struct scoreboard *sb,
 	struct origin *porigin = NULL;
 	struct diff_options diff_opts;
 	int i;
-	const char *paths[2];
 
 	diff_setup(&diff_opts);
 	DIFF_OPT_SET(&diff_opts, RECURSIVE);
 	diff_opts.detect_rename = DIFF_DETECT_RENAME;
 	diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 	diff_opts.single_follow = origin->path;
-	paths[0] = NULL;
-	init_pathspec(&diff_opts.pathspec, paths);
 	diff_setup_done(&diff_opts);
 
 	if (is_null_sha1(origin->commit->object.sha1))
@@ -1058,7 +1055,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
 			       int opt)
 {
 	struct diff_options diff_opts;
-	const char *paths[1];
 	int i, j;
 	int retval;
 	struct blame_list *blame_list;
@@ -1072,8 +1068,6 @@ static int find_copy_in_parent(struct scoreboard *sb,
 	DIFF_OPT_SET(&diff_opts, RECURSIVE);
 	diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
 
-	paths[0] = NULL;
-	init_pathspec(&diff_opts.pathspec, paths);
 	diff_setup_done(&diff_opts);
 
 	/* Try "find copies harder" on new path if requested;
diff --git a/builtin/log.c b/builtin/log.c
index 8f0b2e8..812bcb9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -469,7 +469,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 	init_grep_defaults();
 	git_config(git_log_config, NULL);
 
-	init_pathspec(&match_all, NULL);
+	memset(&match_all, 0, sizeof(match_all));
 	init_revisions(&rev, prefix);
 	rev.diff = 1;
 	rev.always_show_header = 1;
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index f211539..50842ba 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -320,13 +320,12 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
 	}
 
 	if (prefix) {
-		static const char *(matchbuf[2]);
-		matchbuf[0] = prefix;
-		matchbuf[1] = NULL;
-		init_pathspec(&pathspec, matchbuf);
-		pathspec.items[0].nowildcard_len = pathspec.items[0].len;
+		static const char *(matchbuf[1]);
+		matchbuf[0] = NULL;
+		parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC,
+			       PATHSPEC_PREFER_CWD, prefix, matchbuf);
 	} else
-		init_pathspec(&pathspec, NULL);
+		memset(&pathspec, 0, sizeof(pathspec));
 	if (read_tree(tree, 1, &pathspec))
 		die("unable to read tree entries %s", tree_name);
 
diff --git a/diff-lib.c b/diff-lib.c
index 4729157..68fc991 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -499,7 +499,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
 	struct rev_info revs;
 
 	init_revisions(&revs, NULL);
-	init_pathspec(&revs.prune_data, opt->pathspec.raw);
+	copy_pathspec(&revs.prune_data, &opt->pathspec);
 	revs.diffopt = *opt;
 
 	if (diff_cache(&revs, tree_sha1, NULL, 1))
diff --git a/dir.c b/dir.c
index a646e55..e354abb 100644
--- a/dir.c
+++ b/dir.c
@@ -1630,64 +1630,6 @@ int remove_path(const char *name)
 	return 0;
 }
 
-static int pathspec_item_cmp(const void *a_, const void *b_)
-{
-	struct pathspec_item *a, *b;
-
-	a = (struct pathspec_item *)a_;
-	b = (struct pathspec_item *)b_;
-	return strcmp(a->match, b->match);
-}
-
-int init_pathspec(struct pathspec *pathspec, const char **paths)
-{
-	const char **p = paths;
-	int i;
-
-	memset(pathspec, 0, sizeof(*pathspec));
-	if (!p)
-		return 0;
-	while (*p)
-		p++;
-	pathspec->raw = paths;
-	pathspec->nr = p - paths;
-	if (!pathspec->nr)
-		return 0;
-
-	pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
-	for (i = 0; i < pathspec->nr; i++) {
-		struct pathspec_item *item = pathspec->items+i;
-		const char *path = paths[i];
-
-		item->match = path;
-		item->original = path;
-		item->len = strlen(path);
-		item->flags = 0;
-		if (limit_pathspec_to_literal()) {
-			item->nowildcard_len = item->len;
-		} else {
-			item->nowildcard_len = simple_length(path);
-			if (item->nowildcard_len < item->len) {
-				pathspec->has_wildcard = 1;
-				if (path[item->nowildcard_len] == '*' &&
-				    no_wildcard(path + item->nowildcard_len + 1))
-					item->flags |= PATHSPEC_ONESTAR;
-			}
-		}
-	}
-
-	qsort(pathspec->items, pathspec->nr,
-	      sizeof(struct pathspec_item), pathspec_item_cmp);
-
-	return 0;
-}
-
-void free_pathspec(struct pathspec *pathspec)
-{
-	free(pathspec->items);
-	pathspec->items = NULL;
-}
-
 int limit_pathspec_to_literal(void)
 {
 	static int flag = -1;
diff --git a/merge-recursive.c b/merge-recursive.c
index ea9dbd3..8395b9b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -297,7 +297,7 @@ static int get_files_dirs(struct merge_options *o, struct tree *tree)
 {
 	int n;
 	struct pathspec match_all;
-	init_pathspec(&match_all, NULL);
+	memset(&match_all, 0, sizeof(match_all));
 	if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
 		return 0;
 	n = o->current_file_set.nr + o->current_directory_set.nr;
diff --git a/pathspec.c b/pathspec.c
index 0b658cb..767ce65 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -370,3 +370,9 @@ void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
 	memcpy(dst->items, src->items,
 	       sizeof(struct pathspec_item) * dst->nr);
 }
+
+void free_pathspec(struct pathspec *pathspec)
+{
+	free(pathspec->items);
+	pathspec->items = NULL;
+}
diff --git a/pathspec.h b/pathspec.h
index 44253c8..9e9e442 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -44,7 +44,6 @@ struct pathspec {
 #define PATHSPEC_PREFIX_ORIGIN (1<<6)
 #define PATHSPEC_KEEP_ORDER (1<<7)
 
-extern int init_pathspec(struct pathspec *, const char **);
 extern void parse_pathspec(struct pathspec *pathspec,
 			   unsigned magic_mask,
 			   unsigned flags,
diff --git a/revision.c b/revision.c
index c0ced84..56ada54 100644
--- a/revision.c
+++ b/revision.c
@@ -1113,7 +1113,7 @@ static void prepare_show_merge(struct rev_info *revs)
 			i++;
 	}
 	free_pathspec(&revs->prune_data);
-	init_pathspec(&revs->prune_data, prune);
+	parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC, 0, "", prune);
 	revs->limited = 1;
 }
 
diff --git a/tree-diff.c b/tree-diff.c
index f4c92f6..e1145c6 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -195,7 +195,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
 	struct diff_options diff_opts;
 	struct diff_queue_struct *q = &diff_queued_diff;
 	struct diff_filepair *choice;
-	const char *paths[1];
 	int i;
 
 	/*
@@ -228,8 +227,6 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
 	diff_opts.single_follow = opt->pathspec.raw[0];
 	diff_opts.break_opt = opt->break_opt;
 	diff_opts.rename_score = opt->rename_score;
-	paths[0] = NULL;
-	init_pathspec(&diff_opts.pathspec, paths);
 	diff_setup_done(&diff_opts);
 	diff_tree(t1, t2, base, &diff_opts);
 	diffcore_std(&diff_opts);
@@ -247,14 +244,17 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
 		 */
 		if ((p->status == 'R' || p->status == 'C') &&
 		    !strcmp(p->two->path, opt->pathspec.raw[0])) {
+			const char *path[2];
+
 			/* Switch the file-pairs around */
 			q->queue[i] = choice;
 			choice = p;
 
 			/* Update the path we use from now on.. */
+			path[0] = p->one->path;
+			path[1] = NULL;
 			free_pathspec(&opt->pathspec);
-			opt->pathspec.raw[0] = xstrdup(p->one->path);
-			init_pathspec(&opt->pathspec, opt->pathspec.raw);
+			parse_pathspec(&opt->pathspec, PATHSPEC_ALL_MAGIC, 0, "", path);
 
 			/*
 			 * The caller expects us to return a set of vanilla
-- 
1.8.0.rc0.19.g7bbb31d
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 54 of 88 in “nd/parse-pathspec and :(glob) pathspec magic”
  1. 00/45 nd/parse-pathspec and :(glob) pathspec magicNguyễn Thái Ngọc Duy, Mar 15, 2013
  2. 01/45 setup.c: check that the pathspec magic ends with ")"Nguyễn Thái Ngọc Duy, Mar 15, 2013
  3. 02/45 clean: remove unused variable "seen"Nguyễn Thái Ngọc Duy, Mar 15, 2013
  4. 03/45 Move struct pathspec and related functions to pathspec.[ch]Nguyễn Thái Ngọc Duy, Mar 15, 2013
  5. 04/45 pathspec: i18n-ize error strings in pathspec parsing codeNguyễn Thái Ngọc Duy, Mar 15, 2013
  6. 05/45 pathspec: add copy_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  7. 06/45 Add parse_pathspec() that converts cmdline args to struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  8. 07/45 parse_pathspec: save original pathspec for reportingNguyễn Thái Ngọc Duy, Mar 15, 2013
  9. 08/45 parse_pathspec: add PATHSPEC_PREFER_{CWD,FULL}Nguyễn Thái Ngọc Duy, Mar 15, 2013
  10. 09/45 Convert some get_pathspec() calls to parse_pathspec()Nguyễn Thái Ngọc Duy, Mar 15, 2013
  11. 10/45 parse_pathspec: a special flag for max_depth featureNguyễn Thái Ngọc Duy, Mar 15, 2013
  12. Eric SunshineMar 15, 2013
  13. 11/45 parse_pathspec: support stripping submodule trailing slashesNguyễn Thái Ngọc Duy, Mar 15, 2013
  14. Junio C HamanoMar 17, 2013
  15. Duy NguyenMar 18, 2013
  16. 12/45 parse_pathspec: support stripping/checking submodule pathsNguyễn Thái Ngọc Duy, Mar 15, 2013
  17. 13/45 parse_pathspec: support prefixing original patternsNguyễn Thái Ngọc Duy, Mar 15, 2013
  18. 14/45 Guard against new pathspec magic in pathspec matching codeNguyễn Thái Ngọc Duy, Mar 15, 2013
  19. Junio C HamanoMar 17, 2013
  20. 15/45 clean: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  21. 16/45 commit: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  22. 17/45 status: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  23. 18/45 rerere: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  24. 19/45 checkout: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  25. 20/45 rm: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  26. 21/45 ls-files: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  27. 22/45 archive: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  28. Junio C HamanoMar 15, 2013
  29. Duy NguyenMar 16, 2013
  30. Junio C HamanoMar 17, 2013
  31. Duy NguyenMar 17, 2013
  32. Junio C HamanoMar 17, 2013
  33. 23/45 check-ignore: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  34. Adam SpiersApr 12, 2013
  35. Duy NguyenApr 12, 2013
  36. Adam SpiersApr 14, 2013
  37. Duy NguyenApr 14, 2013
  38. Adam SpiersApr 15, 2013
  39. 24/45 add: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  40. 25/45 reset: convert to use parse_pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  41. 26/45 Convert read_cache_preload() to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  42. 27/45 Convert run_add_interactive to use struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  43. John KeepingMar 18, 2013
  44. Duy NguyenMar 19, 2013
  45. John KeepingMar 19, 2013
  46. 28/45 Convert unmerge_cache to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  47. 29/45 checkout: convert read_tree_some to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  48. 30/45 Convert report_path_error to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  49. 31/45 Convert refresh_index to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  50. 32/45 Convert {read,fill}_directory to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  51. 33/45 Convert add_files_to_cache to take struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  52. 34/45 Convert common_prefix() to use struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  53. 35/45 Remove diff_tree_{setup,release}_pathsNguyễn Thái Ngọc Duy, Mar 15, 2013
  54. 36/45 Remove init_pathspec() in favor of parse_pathspec()Nguyễn Thái Ngọc Duy, Mar 15, 2013
  55. 37/45 Remove match_pathspec() in favor of match_pathspec_depth()Nguyễn Thái Ngọc Duy, Mar 15, 2013
  56. 38/45 tree-diff: remove the use of pathspec's raw[] in follow-rename codepathNguyễn Thái Ngọc Duy, Mar 15, 2013
  57. 39/45 parse_pathspec: make sure the prefix part is wildcard-freeNguyễn Thái Ngọc Duy, Mar 15, 2013
  58. Junio C HamanoMar 19, 2013
  59. Duy NguyenMar 20, 2013
  60. Duy NguyenMar 20, 2013
  61. 40/45 parse_pathspec: preserve prefix length via PATHSPEC_PREFIX_ORIGINNguyễn Thái Ngọc Duy, Mar 15, 2013
  62. Eric SunshineMar 15, 2013
  63. 41/45 Kill limit_pathspec_to_literal() as it's only used by parse_pathspec()Nguyễn Thái Ngọc Duy, Mar 15, 2013
  64. 42/45 pathspec: support :(literal) syntax for noglob pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  65. 43/45 pathspec: make --literal-pathspecs disable pathspec magicNguyễn Thái Ngọc Duy, Mar 15, 2013
  66. 44/45 pathspec: support :(glob) syntaxNguyễn Thái Ngọc Duy, Mar 15, 2013
  67. Eric SunshineMar 15, 2013
  68. 45/45 Rename field "raw" to "_raw" in struct pathspecNguyễn Thái Ngọc Duy, Mar 15, 2013
  69. Junio C HamanoMar 15, 2013
  70. 00/45 parse_pathspec and :(glob) magicNguyễn Thái Ngọc Duy, Mar 20, 2013
  71. 06/45 Add parse_pathspec() that converts cmdline args to struct pathspecNguyễn Thái Ngọc Duy, Mar 20, 2013
  72. Eric SunshineMar 20, 2013
  73. Junio C HamanoMar 22, 2013
  74. 11/45 parse_pathspec: support stripping submodule trailing slashesNguyễn Thái Ngọc Duy, Mar 20, 2013
  75. 12/45 parse_pathspec: support stripping/checking submodule pathsNguyễn Thái Ngọc Duy, Mar 20, 2013
  76. 14/45 Guard against new pathspec magic in pathspec matching codeNguyễn Thái Ngọc Duy, Mar 20, 2013
  77. Eric SunshineMar 20, 2013
  78. 27/45 Convert run_add_interactive to use struct pathspecNguyễn Thái Ngọc Duy, Mar 20, 2013
  79. 39/45 parse_pathspec: make sure the prefix part is wildcard-freeNguyễn Thái Ngọc Duy, Mar 20, 2013
  80. Junio C HamanoMar 20, 2013
  81. Duy NguyenMar 21, 2013
  82. Duy NguyenMar 21, 2013
  83. Junio C HamanoMar 21, 2013
  84. Junio C HamanoMar 21, 2013
  85. Duy NguyenMar 23, 2013
  86. Duy NguyenMar 23, 2013
  87. Junio C HamanoMar 27, 2013
  88. Eric SunshineMar 24, 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.