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

[PATCH/RFC] gitk: refresh index before checking for local changes

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 7, 2010, 00:43 UTC
Message-ID
<20100407004353.GA11346@progeny.tock>
In-Reply-To
<n2kc6c947f61004061647ybb6c2f55zc70197362764ef8@mail.gmail.com>

Most git porcelain silently refreshes stat-dirty index entries. Teach gitk to, too; this will make the behavior easier to understand when a person makes a change to a file and then changes mind and restores the old version in her editor of choice.

This patch does not change the ‘checkout’ code path, since it is assumed that the index is already being cleaned in that case.

Testing is needed to check if this breaks operation with read-only access to a repository.

Requested-by: Alexander Gladysh <agladysh@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Alexander Gladysh wrote:
> Jonathan Nieder wrote:
[some nonsense about configurability]
> That's fine as far as I'm concerned.
> 
> The current behaviour is really annoying.

Maybe that could be added in the future. From testing this out, refreshing unconditionally seems fast enough, at least.

 gitk |   50 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/gitk b/gitk
index 1f36a3e..2753446 100755
--- a/gitk
+++ b/gitk
@@ -375,7 +375,7 @@ proc start_rev_list {view} {
 	get_viewmainhead $view
     }
     if {$showlocalchanges && $viewmainheadid($view) ne {}} {
-	interestedin $viewmainheadid($view) dodiffindex
+	interestedin $viewmainheadid($view) dorefreshindex
     }
     fconfigure $fd -blocking 0 -translation lf -eofchar {}
     if {$tclencoding != {}} {
@@ -4974,9 +4974,9 @@ proc doshowlocalchanges {} {
 
     if {$viewmainheadid($curview) eq {}} return
     if {[commitinview $viewmainheadid($curview) $curview]} {
-	dodiffindex
+	dorefreshindex
     } else {
-	interestedin $viewmainheadid($curview) dodiffindex
+	interestedin $viewmainheadid($curview) dorefreshindex
     }
 }
 
@@ -4992,6 +4992,42 @@ proc dohidelocalchanges {} {
     incr lserial
 }
 
+# spawn off a process to refresh the index
+proc dorefreshindex {} {
+    global lserial showlocalchanges isworktree vfilelimit curview
+
+    if {!$showlocalchanges || !$isworktree} return
+    incr lserial
+    set cmd "|git update-index --refresh -q"
+    if {$vfilelimit($curview) ne {}} {
+	set cmd [concat $cmd -- $vfilelimit($curview)]
+    }
+    set fd [open $cmd r]
+    fconfigure $fd -blocking 0
+    set i [reg_instance $fd]
+    filerun $fd [list readrefreshindex $fd $lserial $i]
+}
+
+# update-index --refresh -q finished?
+proc readrefreshindex {fd serial inst} {
+    global lserial
+
+    if {$serial != $lserial} {
+	stop_instance $inst
+	return 0
+    }
+    if {[gets $fd line] == 0} {
+	# ignore output
+	return 0
+    }
+    if {![eof $fd]} {
+        return 1
+    }
+    stop_instance $inst
+    dodiffindex
+    return 0
+}
+
 # spawn off a process to do git diff-index --cached HEAD
 proc dodiffindex {} {
     global lserial showlocalchanges vfilelimit curview
@@ -7504,13 +7540,9 @@ proc getblobdiffs {ids} {
     global git_version
 
     set textconv {}
-    if {[package vcompare $git_version "1.6.1"] >= 0} {
-	set textconv "--textconv"
-    }
+    set textconv "--textconv"
     set submodule {}
-    if {[package vcompare $git_version "1.6.6"] >= 0} {
-	set submodule "--submodule"
-    }
+    set submodule "--submodule"
     set cmd [diffcmd $ids "-p $textconv $submodule  -C --cc --no-commit-id -U$diffcontext"]
     if {$ignorespace} {
 	append cmd " -w"
-- 
debian.1.7.0.3.1.469.g398f8
Previous: Alexander GladyshNext: Alexander Gladysh
Message 5 of 15 in “gitk pays too much attention to file timestamps”
  1. Alexander GladyshApr 6, 2010
  2. Markus HeidelbergApr 6, 2010
  3. Jonathan NiederApr 6, 2010
  4. Alexander GladyshApr 6, 2010
  5. gitk: refresh index before checking for local changesJonathan Nieder, Apr 7, 2010
  6. Alexander GladyshApr 7, 2010
  7. Jonathan NiederApr 7, 2010
  8. A Large Angry SCMApr 7, 2010
  9. Jonathan NiederApr 7, 2010
  10. Junio C HamanoApr 7, 2010
  11. A Large Angry SCMApr 7, 2010
  12. Avery PennarunApr 7, 2010
  13. Jon SeymourApr 7, 2010
  14. Avery PennarunApr 6, 2010
  15. Jonathan NiederApr 7, 2010

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.