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

[PATCH 4/3] sha1_name: use bsearch_pack() in unique_in_pack()

From
René Scharfe <l.s.r@web.de>
Date
Mar 24, 2018, 16:41 UTC
Message-ID
<71b5cef0-abad-001f-6a23-3f2d874b9709@web.de>
In-Reply-To
<20180322174010.120117-1-dstolee@microsoft.com>

Replace the custom binary search in unique_in_pack() with a call to bsearch_pack(). This reduces code duplication and makes use of the fan-out table of packs.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
This is basically the same replacement as done by patch 3.  Speed is
less of a concern here -- at least I don't know a commonly used
command that needs to resolve lots of short hashes.
 sha1_name.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 24894b3dbe..0185c6081a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -150,31 +150,14 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
 static void unique_in_pack(struct packed_git *p,
 			   struct disambiguate_state *ds)
 {
-	uint32_t num, last, i, first = 0;
+	uint32_t num, i, first = 0;
 	const struct object_id *current = NULL;
 
 	if (open_pack_index(p) || !p->num_objects)
 		return;
 
 	num = p->num_objects;
-	last = num;
-	while (first < last) {
-		uint32_t mid = first + (last - first) / 2;
-		const unsigned char *current;
-		int cmp;
-
-		current = nth_packed_object_sha1(p, mid);
-		cmp = hashcmp(ds->bin_pfx.hash, current);
-		if (!cmp) {
-			first = mid;
-			break;
-		}
-		if (cmp > 0) {
-			first = mid+1;
-			continue;
-		}
-		last = mid;
-	}
+	bsearch_pack(&ds->bin_pfx, p, &first);
 
 	/*
 	 * At this point, "first" is the location of the lowest object
-- 
2.16.3
Previous: Derrick StoleeNext: Junio C Hamano
Message 9 of 12 in “sha1_name: use bsearch_hash() for abbreviations”
  1. sha1_name: use bsearch_hash() for abbreviationsDerrick Stolee, Mar 20, 2018
  2. Jonathan TanMar 20, 2018
  3. Derrick StoleeMar 21, 2018
  4. brian m. carlsonMar 21, 2018
  5. 0/3 Use bsearch_hash() for abbreviationsDerrick Stolee, Mar 22, 2018
  6. 2/3 packfile: define and use bsearch_pack()Derrick Stolee, Mar 22, 2018
  7. 1/3 sha1_name: convert struct min_abbrev_data to object_idDerrick Stolee, Mar 22, 2018
  8. 3/3 sha1_name: use bsearch_pack() for abbreviationsDerrick Stolee, Mar 22, 2018
  9. 4/3 sha1_name: use bsearch_pack() in unique_in_pack()René Scharfe, Mar 24, 2018
  10. Junio C HamanoMar 25, 2018
  11. René ScharfeMar 25, 2018
  12. Derrick StoleeMar 25, 2018

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.