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

[PATCH v3.1] gitk: do not parse " >" context as submodule change

From
Thomas Rast <trast@student.ethz.ch>
Date
Apr 12, 2010, 13:25 UTC
Message-ID
<5531510bfb94997f729a894a0b5a3158177a9add.1271078624.git.trast@student.ethz.ch>
In-Reply-To
<ba83d579ded263a44455508ad89ff142272626c6.1271077334.git.trast@student.ethz.ch>

Since 5c838d2 (gitk: Use the --submodule option for displaying diffs when available, 2009-10-28) gitk erroneously matches " >" and " <" at the beginning of a line in the submodule code even if we're in the diff text section and the lines should be treated as context.

Fix by (ab)using the $diffinhdr variable also in the 'Submodule...' case, and move the " >"/" <" specific code inside the $diffinhdr test. The existing code will set $diffinhdr to 0 when it hits a "+++", so that it is always 0 when we can hit a context line. ---

I just noticed that I forgot to add the 'continue' that prevents the final 'insert' in the $diffinhdr block from kicking in, which resulted in doubling of the lines. This one has them. Sorry for the noise.

 gitk |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/gitk b/gitk
index 1f36a3e..7b8799e 100755
--- a/gitk
+++ b/gitk
@@ -7688,12 +7688,8 @@ proc getblobdiffline {bdf ids} {
 	    lappend ctext_file_lines $fname
 	    makediffhdr $fname $ids
 	    $ctext insert end "\n$line\n" filesep
-	} elseif {![string compare -length 3 "  >" $line]} {
-	    set line [encoding convertfrom $diffencoding $line]
-	    $ctext insert end "$line\n" dresult
-	} elseif {![string compare -length 3 "  <" $line]} {
-	    set line [encoding convertfrom $diffencoding $line]
-	    $ctext insert end "$line\n" d0
+	    # pretend we're in a file header to correctly parse "  [><]"
+	    set diffinhdr 1
 	} elseif {$diffinhdr} {
 	    if {![string compare -length 12 "rename from " $line]} {
 		set fname [string range $line [expr 6 + [string first " from " $line] ] end]
@@ -7712,6 +7708,14 @@ proc getblobdiffline {bdf ids} {
 		    set fname [lindex $fname 0]
 		}
 		makediffhdr $fname $ids
+	    } elseif {![string compare -length 3 "  >" $line]} {
+		set line [encoding convertfrom $diffencoding $line]
+		$ctext insert end "$line\n" dresult
+		continue
+	    } elseif {![string compare -length 3 "  <" $line]} {
+		set line [encoding convertfrom $diffencoding $line]
+		$ctext insert end "$line\n" d0
+		continue
 	    } elseif {[string compare -length 3 $line "---"] == 0} {
 		# do nothing
 		continue
-- 
1.7.1.rc0.260.g2b919
Previous: Thomas RastNext: Thomas Rast
Message 12 of 15 in “gitk --color-words”
  1. 0/2 gitk --color-wordsThomas Rast, Apr 4, 2010
  2. 1/2 diff: add --word-diff option that generalizes --color-wordsThomas Rast, Apr 4, 2010
  3. Junio C HamanoApr 5, 2010
  4. Thomas RastApr 5, 2010
  5. Junio C HamanoApr 5, 2010
  6. Miles BaderApr 5, 2010
  7. 0/2 gitk --color-wordsThomas Rast, Apr 12, 2010
  8. 1/3 diff: add --word-diff option that generalizes --color-wordsThomas Rast, Apr 12, 2010
  9. Junio C HamanoApr 12, 2010
  10. Thomas RastApr 13, 2010
  11. 2/3 gitk: do not parse " >" context as submodule changeThomas Rast, Apr 12, 2010
  12. gitk: do not parse " >" context as submodule changeThomas Rast, Apr 12, 2010
  13. 3/3 gitk: add the equivalent of diff --color-wordsThomas Rast, Apr 12, 2010
  14. Thomas RastApr 6, 2010
  15. 2/2 gitk: add the equivalent of diff --color-wordsThomas Rast, Apr 4, 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.