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

[PATCH 5/6] tree_entry_interesting(): remove dependency on struct diff_options

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 19, 2010, 23:21 UTC
Message-ID
<1284938514-16663-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1284938514-16663-1-git-send-email-pclouds@gmail.com>

This function can be potentially used in more places than just tree-diff.c. "struct diff_options" does not make much sense outside diff_tree_sha1().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 tree-diff.c |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/tree-diff.c b/tree-diff.c
index 986c0f4..822d45e 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -91,25 +91,20 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
  *  - zero for no
  *  - negative for "no, and no subsequent entries will be either"
  */
-static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
+static int tree_entry_interesting(const struct name_entry *entry, const char *base, int baselen, const struct pathspec *ps)
 {
-	const char *path;
-	const unsigned char *sha1;
-	unsigned mode;
 	int i;
 	int pathlen;
 	int never_interesting = -1;
 
-	if (!opt->pathspec.nr)
+	if (!ps || !ps->nr)
 		return 1;
 
-	sha1 = tree_entry_extract(desc, &path, &mode);
-
-	pathlen = tree_entry_len(path, sha1);
+	pathlen = tree_entry_len(entry->path, entry->sha1);
 
-	for (i = 0; i < opt->pathspec.nr; i++) {
-		const char *match = opt->pathspec.raw[i];
-		int matchlen = opt->pathspec.items[i].len;
+	for (i = 0; i < ps->nr; i++) {
+		const char *match = ps->raw[i];
+		int matchlen = ps->items[i].len;
 		int m = -1; /* signals that we haven't called strncmp() */
 
 		if (baselen >= matchlen) {
@@ -147,7 +142,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 			 * Does match sort strictly earlier than path
 			 * with their common parts?
 			 */
-			m = strncmp(match, path,
+			m = strncmp(match, entry->path,
 				    (matchlen < pathlen) ? matchlen : pathlen);
 			if (m < 0)
 				continue;
@@ -174,7 +169,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 		if (matchlen > pathlen) {
 			if (match[pathlen] != '/')
 				continue;
-			if (!S_ISDIR(mode))
+			if (!S_ISDIR(entry->mode))
 				continue;
 		}
 
@@ -183,7 +178,7 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
 			 * we cheated and did not do strncmp(), so we do
 			 * that here.
 			 */
-			m = strncmp(match, path, pathlen);
+			m = strncmp(match, entry->path, pathlen);
 
 		/*
 		 * If common part matched earlier then it is a hit,
@@ -206,8 +201,7 @@ static void show_tree(struct diff_options *opt, const char *prefix, struct tree_
 		if (all_interesting)
 			show = 1;
 		else {
-			show = tree_entry_interesting(desc, base, baselen,
-						      opt);
+			show = tree_entry_interesting(&desc->entry, base, baselen, &opt->pathspec);
 			if (show == 2)
 				all_interesting = 1;
 		}
@@ -266,7 +260,7 @@ static void skip_uninteresting(struct tree_desc *t, const char *base, int basele
 		if (all_interesting)
 			show = 1;
 		else {
-			show = tree_entry_interesting(t, base, baselen, opt);
+			show = tree_entry_interesting(&t->entry, base, baselen, &opt->pathspec);
 			if (show == 2)
 				all_interesting = 1;
 		}
-- 
1.7.1.rc1.70.g788ca
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 22 in “Introduce pathspec struct”
  1. 0/6 Introduce pathspec structNguyễn Thái Ngọc Duy, Sep 19, 2010
  2. 1/6 Add struct pathspecNguyễn Thái Ngọc Duy, Sep 19, 2010
  3. Junio C HamanoSep 27, 2010
  4. yj2133011Sep 29, 2010
  5. 2/6 diff-no-index: use diff_tree_setup_paths()Nguyễn Thái Ngọc Duy, Sep 19, 2010
  6. 3/6 pathspec: cache string length when initialize pathspecNguyễn Thái Ngọc Duy, Sep 19, 2010
  7. Junio C HamanoSep 27, 2010
  8. Nguyen Thai Ngoc DuySep 28, 2010
  9. 4/6 Convert struct diff_options to use struct pathspecNguyễn Thái Ngọc Duy, Sep 19, 2010
  10. Junio C HamanoSep 27, 2010
  11. 5/6 tree_entry_interesting(): remove dependency on struct diff_optionsNguyễn Thái Ngọc Duy, Sep 19, 2010
  12. Junio C HamanoSep 27, 2010
  13. Nguyen Thai Ngoc DuySep 28, 2010
  14. 6/6 Move tree_entry_interesting() to tree-walk.c and export itNguyễn Thái Ngọc Duy, Sep 19, 2010
  15. Elijah NewrenSep 20, 2010
  16. Nguyen Thai Ngoc DuySep 20, 2010
  17. Junio C HamanoSep 28, 2010
  18. Bo YangSep 28, 2010
  19. Nguyen Thai Ngoc DuySep 28, 2010
  20. Junio C HamanoSep 29, 2010
  21. David RiptonSep 28, 2010
  22. Junio C HamanoSep 29, 2010

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.