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

Re: Why are ref_lists sorted?

From
Junio C Hamano <junkio@cox.net>
Date
Mar 19, 2007, 04:50 UTC
Message-ID
<7vodmpltvb.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0703190321370.28570@beast.quantumfyre.co.uk>
Julian Phillips <julian@quantumfyre.co.uk> writes:
> So my questions are:
>
> 1) what have I broken by removing the sort?

See do_for_each_ref(). We walk packed and loose refs in parallel, preferring loose ref if exists (so that after packing, updating a ref does not have to remove entry from packed-refs file).

> 2) is it worth trying to optimise the sort?

If you have 9,000 entries, it probably is worth doing. Also you might want to use an expanding array of pointers instead of linked list.

Currently add_ref() is shared between packed and loose refs, and the order loose refs are discovered depends on readdir() order, so we cannot do without sorting on that side. But I suspect reading them in in the order they are discovered and then sorting at the end just once might be a good thing to do.

If we write packed refs _after_ sorting, we should be able to optimize on the side that reads packed-refs even better. As you read one new line from the file, you make sure that it sorts later than the last entry you saw, and append to the end of list; if you find an unorderd entry, remember that the list is not sorted, and sort at the very end after reading all the refs.

Or something like that...
Previous: Julian PhillipsNext: Shawn O. Pearce
Message 2 of 7 in “Why are ref_lists sorted?”
  1. Julian PhillipsMar 19, 2007
  2. Junio C HamanoMar 19, 2007
  3. Shawn O. PearceMar 19, 2007
  4. Julian PhillipsMar 19, 2007
  5. Shawn O. PearceMar 19, 2007
  6. Junio C HamanoMar 19, 2007
  7. Linus TorvaldsMar 19, 2007

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.