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

[PATCH 3/3] unpack-trees: simplify via strnncmp()

From
Jeremiah Mahler <jmmahler@gmail.com>
Date
Jun 16, 2014, 19:13 UTC
Message-ID
<ee1716e209794a66eb9677e798164a356276700e.1402945507.git.jmmahler@gmail.com>
In-Reply-To
<cover.1402945507.git.jmmahler@gmail.com>

Simplify unpack-trees.c using the strnncmp() function and remove the name_compare() function.

Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
 unpack-trees.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/unpack-trees.c b/unpack-trees.c
index 4a9cdf2..9a71b5a 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -629,17 +629,6 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)
 	return -1;
 }
 
-/* NEEDSWORK: give this a better name and share with tree-walk.c */
-static int name_compare(const char *a, int a_len,
-			const char *b, int b_len)
-{
-	int len = (a_len < b_len) ? a_len : b_len;
-	int cmp = memcmp(a, b, len);
-	if (cmp)
-		return cmp;
-	return (a_len - b_len);
-}
-
 /*
  * The tree traversal is looking at name p.  If we have a matching entry,
  * return it.  If name p is a directory in the index, do not return
@@ -678,7 +667,7 @@ static int find_cache_pos(struct traverse_info *info,
 			ce_len = ce_slash - ce_name;
 		else
 			ce_len = ce_namelen(ce) - pfxlen;
-		cmp = name_compare(p->path, p_len, ce_name, ce_len);
+		cmp = strnncmp(p->path, p_len, ce_name, ce_len);
 		/*
 		 * Exact match; if we have a directory we need to
 		 * delay returning it.
-- 
2.0.0
Previous: Jeremiah MahlerNext: Jonathan Nieder
Message 7 of 8 in “add strnncmp() function”
  1. 0/3 add strnncmp() functionJeremiah Mahler, Jun 16, 2014
  2. 1/3 add strnncmp() functionJeremiah Mahler, Jun 16, 2014
  3. Jonathan NiederJun 16, 2014
  4. 2/3 tree-walk: simplify via strnncmp()Jeremiah Mahler, Jun 16, 2014
  5. Jonathan NiederJun 16, 2014
  6. Jeremiah MahlerJun 17, 2014
  7. 3/3 unpack-trees: simplify via strnncmp()Jeremiah Mahler, Jun 16, 2014
  8. Jonathan NiederJun 16, 2014

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.