threads / patch / 62581

patchDocumentation/git-update-index.txt: add an example of use

Subject: [PATCH] Documentation/git-update-index.txt: add an example of use

## tl;dr

3 messages between Dec 1, 2024 and Dec 2, 2024. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Matěj Cepl· Dec 1, 2024, 22:25 UTC · lore
I met this command in the wild and I spent a lot of time to
understand what it is good for.
---
 Documentation/git-update-index.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
Show changes to Documentation/git-update-index.txt +9 −0
diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
index 7128aed540..da11cbc418 100644
--- a/Documentation/git-update-index.txt
+++ b/Documentation/git-update-index.txt
@@ -399,6 +399,15 @@ M foo.c
 <8> you can tell about the change after the fact.
 <9> now it checks with lstat(2) and finds it has been changed.
 
+To speed up other Git commands that rely on the index, such as git status
+or git commit, user can refresh the index and avoid having to re-check
+the status of every file in the working directory. This command
+doesn't modify any committed data in your repository.
++
+----------------
+$ git update-index -q --refresh || true
+----------------
+
 
 SKIP-WORKTREE BIT
 -----------------
-- 
2.47.1
Junio C Hamano· Dec 2, 2024, 03:01 UTC · re: Matěj Cepl · lore

Re: [PATCH] Documentation/git-update-index.txt: add an example of use

Matěj Cepl <mcepl@cepl.eu> writes:
> I met this command in the wild and I spent a lot of time to
> understand what it is good for.
> ---
Missing sign-off.
Show 20 quoted lines
>  Documentation/git-update-index.txt | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt
> index 7128aed540..da11cbc418 100644
> --- a/Documentation/git-update-index.txt
> +++ b/Documentation/git-update-index.txt
> @@ -399,6 +399,15 @@ M foo.c
>  <8> you can tell about the change after the fact.
>  <9> now it checks with lstat(2) and finds it has been changed.
>  
> +To speed up other Git commands that rely on the index, such as git status
> +or git commit, user can refresh the index and avoid having to re-check
> +the status of every file in the working directory. This command
> +doesn't modify any committed data in your repository.
> ++
> +----------------
> +$ git update-index -q --refresh || true
> +----------------
> +
Two comments.
 * The example before the new one is for a rather esoteric corner
   case of running Git on an inefficient filesystem.  Perhaps this
   new one more commonly happens, in which case, it probably sits
   better earlier in the list of examples.
 * Because most (if not all) Porcelain commands like "git commit" or
   "git status" automatically refreshes the index, it is of dubious
   value to manually refresh, like your example does, before running
   them.  You pay the price either way, and the only difference may
   be the time (and brain cycle) you spend to manually issue the
   "update-index --refresh" command.

The benefit of refreshing the index manually beforehand mostly comes when you are running two or more plumbing commands that do not refresh the index by themselves. We used to implement an equivlent of today's "git status" using "git diff-files" and "git diff-cache" (yes, we literally ran these two commands in a row to show their results in the output, one for "changes to be committed" and the other for "changes left in the working tree"), and before running these two, the scripted implementation of "git status" ran "git update-index --refresh".

Thanks.
Matěj Cepl· Dec 2, 2024, 06:56 UTC · re: Junio C Hamano · lore

Re: [PATCH] Documentation/git-update-index.txt: add an example of use

On Mon Dec 2, 2024 at 4:01 AM CET, Junio C Hamano wrote:
> Missing sign-off.

Whoopsie! I am sorry, but given that I am probably withdrawing my submission anyway, it is not relevant, I guess.

Show 9 quoted lines
> The benefit of refreshing the index manually beforehand mostly comes
> when you are running two or more plumbing commands that do not
> refresh the index by themselves.  We used to implement an equivlent
> of today's "git status" using "git diff-files" and "git diff-cache"
> (yes, we literally ran these two commands in a row to show their
> results in the output, one for "changes to be committed" and the
> other for "changes left in the working tree"), and before running
> these two, the scripted implementation of "git status" ran "git
> update-index --refresh".

I’ve got the idea from https://groups.google.com/g/git-mentoring/c/mJnuzbUqyAQ/m/02Pr9uhmAAAJ , so I thought it something one does.

Best,
Matěj
-- 
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
All men's miseries derive from not being able to sit in a quiet
room alone.
  -- Blaise Pascal

← back to recent threads