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

Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2022, 16:00 UTC
Message-ID
<xmqqilmt4huq.fsf@gitster.g>
In-Reply-To
<08a8e78d-7861-3da3-f6f6-bba466655071@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 6 quoted lines
> I had not commented as I don't use the prompt. I have just had a quick
> read and I wonder if it would be more efficient to use
>     git diff --cached --quiet --diff-filter=U
> rather than
>     git ls-files --unmerged 2>/dev/null
> to check if there are unmerged entries,

The former reads the on-disk index into in-core index, and reads tree objects (recursively for subdirectories) referenced by the HEAD, walks both in parallel to find differences and filters out the result to unmerged (I am not sure how well diff-filter works with unmerged paths, though).

The latter rads the on-disk index into in-core index, scans the entries and finds unmerged entries.

So if we compare the overhead to run either command standalone, I am reasonably sure that the latter would be a lot more efficient.

But if the shell prompt code already needs to run the diff-index for other reasons (e.g. to show if there is any modification added to the index), that may change the equation. Instead of adding a separate and extra call to "ls-files -u", it might be more efficient if you can somehow piggy-back on an existing diff-index call. For example, you may be running "git diff --cached --quiet" for exit code to show if any change has been added, but you can instead run "git diff --no-ext-diff --no-renames --cached --name-status" and (1) if there is any output, then the index is dirty, and (2) if there is a line that begins with "U", you have an unmerged path right there.

Previous: Phillip WoodNext: Justin Donnelly
Message 12 of 17 in “git-prompt: show 'CONFLICT' indicator at command prompt”
  1. git-prompt: show 'CONFLICT' indicator at command promptJustin Donnelly via GitGitGadget, Jul 26, 2022
  2. Junio C HamanoJul 27, 2022
  3. Justin DonnellyJul 28, 2022
  4. Junio C HamanoJul 28, 2022
  5. Justin DonnellyJul 28, 2022
  6. git-prompt: show presence of unresolved conflicts at command promptJustin Donnelly via GitGitGadget, Jul 29, 2022
  7. Justin DonnellyAug 14, 2022
  8. Junio C HamanoAug 15, 2022
  9. Johannes SchindelinAug 15, 2022
  10. Justin DonnellyAug 16, 2022
  11. Phillip WoodAug 15, 2022
  12. Junio C HamanoAug 15, 2022
  13. Justin DonnellyAug 16, 2022
  14. Justin DonnellyAug 16, 2022
  15. git-prompt: show presence of unresolved conflicts at command promptJustin Donnelly via GitGitGadget, Aug 17, 2022
  16. Johannes SchindelinAug 19, 2022
  17. Junio C HamanoAug 19, 2022

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.