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

[PATCH v2 3/7] prune_remote(): sort delete_refs_list references en masse

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 25, 2014, 08:02 UTC
Message-ID
<1416902555-10748-4-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1416902555-10748-1-git-send-email-mhagger@alum.mit.edu>

Inserting items into a list in sorted order is O(N^2) whereas appending them unsorted and then sorting the list all at once is O(N lg N).

string_list_insert() also removes duplicates, and this change loses that functionality. But the strings in this list, which ultimately come from a for_each_ref() iteration, cannot contain duplicates.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/remote.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index d5a5a16..7d5c8d2 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1341,8 +1341,9 @@ static int prune_remote(const char *remote, int dry_run)
 		const char *refname = states.stale.items[i].util;
 
 		delete_refs[i] = refname;
-		string_list_insert(&delete_refs_list, refname);
+		string_list_append(&delete_refs_list, refname);
 	}
+	sort_string_list(&delete_refs_list);
 
 	if (!dry_run) {
 		struct strbuf err = STRBUF_INIT;
-- 
2.1.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 5 of 12 in “repack_without_refs(): convert to string_list”
  1. 0/7 repack_without_refs(): convert to string_listMichael Haggerty, Nov 25, 2014
  2. 1/7 prune_remote(): exit early if there are no stale referencesMichael Haggerty, Nov 25, 2014
  3. Junio C HamanoNov 25, 2014
  4. 2/7 prune_remote(): initialize both delete_refs lists in a single loopMichael Haggerty, Nov 25, 2014
  5. 3/7 prune_remote(): sort delete_refs_list references en masseMichael Haggerty, Nov 25, 2014
  6. 4/7 repack_without_refs(): make the refnames argument a string_listMichael Haggerty, Nov 25, 2014
  7. 5/7 prune_remote(): rename local variableMichael Haggerty, Nov 25, 2014
  8. 6/7 prune_remote(): iterate using for_each_string_list_item()Michael Haggerty, Nov 25, 2014
  9. 7/7 Rename sort_string_list() to string_list_sort()Michael Haggerty, Nov 25, 2014
  10. Junio C HamanoNov 25, 2014
  11. Stefan BellerNov 26, 2014
  12. Junio C HamanoNov 26, 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.