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

Re: [PATCH] Remove duplicate pathspecs from ls-files command line

From
David Kastrup <dak@gnu.org>
Date
Aug 30, 2007, 05:52 UTC
Message-ID
<85myw9d0x6.fsf@lola.goethe.zz>
In-Reply-To
<7vr6llak4h.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> David Kastrup <dak@gnu.org> writes:
>
>> Does anything speak against sorting the pathspecs?  That is an O(n log
>> n) operation,
>
> Not sorting is O(0) operation without losing cycles for the
> normal case.  I think you can sort first in that error handling
> path to avoid O(n^2) but sorting upfront to remove duplicates
> for every case is unnecessary bloat that penalizes sane callers.

Not if you need to sort the file list anyway in order to merge it with the index. Of course, sorting patterns will not in all cases establish the order of their expansions.

In any case, uniqueness should be establishable when matching to the index, regardless of whether this matching is done by sort&merge (probably the most efficient variant) or by binary search as it is done now if I understand correctly. I am just not happy with the ensuing binary _insertion_ as this is an O(nm) operation when inserting n elements into an m element data structure. A list merge is O(n+m), in contrast, and we can access the index sequentially.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Previous: Junio C HamanoNext: martin f krafft
Message 8 of 9 in “double occurrence of filenames on command lines”
  1. martin f krafftAug 29, 2007
  2. Remove duplicate pathspecs from ls-files command lineAlex Riesen, Aug 29, 2007
  3. Junio C HamanoAug 29, 2007
  4. martin f krafftAug 29, 2007
  5. Alex RiesenAug 29, 2007
  6. David KastrupAug 29, 2007
  7. Junio C HamanoAug 30, 2007
  8. David KastrupAug 30, 2007
  9. martin f krafftAug 29, 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.