# [PATCH] gitk: don't highlight files after submodules as submodules

2 messages from 2019-11-01 to 2019-12-15. Participants: Роман Донченко, Paul Mackerras.
Thread: https://gitlist.dev/t/52172

## Роман Донченко, 2019-11-01 23:34

Subject: [PATCH] gitk: don't highlight files after submodules as submodules
Message-ID: <20191101233427.4108-1-dpb@corrigendum.ru>
URL: https://gitlist.dev/e/20191101233427.4108-1-dpb%40corrigendum.ru

```
gitk applies submodule highlighting (coloring lines starting with
"  >" and "  <") when `currdiffsubmod` is not an empty string.
However, it fails to reset `currdiffsubmod` after a submodule diff
ends, so any file diffs following a submodule diff will still be
highlighted as if they were submodule diffs.

There are two problems with the way gitk tries to reset `currdiffsubmod`:

1. The code says `set $currdiffsubmod` instead of `set currdiffsubmod`,
   so it actually sets the variable whose name is the submodule path
   instead.

2. It tries to do it after the first line in a submodule diff, which
   is incorrect, since submodule diffs can contain multiple lines.

Fix this by resetting `currdiffsubmod` when a file diff starts.

Signed-off-by: Роман Донченко <dpb@corrigendum.ru>
---
 gitk | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gitk b/gitk
index abe4805..7c425d2 100755
--- a/gitk
+++ b/gitk
@@ -8146,6 +8146,8 @@ proc parseblobdiffline {ids line} {
 	}
 	# start of a new file
 	set diffinhdr 1
+	set currdiffsubmod ""
+
 	$ctext insert end "\n"
 	set curdiffstart [$ctext index "end - 1c"]
 	lappend ctext_file_names ""
@@ -8229,11 +8231,9 @@ proc parseblobdiffline {ids line} {
 	    $ctext insert end "$line\n" filesep
 	}
     } elseif {$currdiffsubmod != "" && ![string compare -length 3 "  >" $line]} {
-	set $currdiffsubmod ""
 	set line [encoding convertfrom $diffencoding $line]
 	$ctext insert end "$line\n" dresult
     } elseif {$currdiffsubmod != "" && ![string compare -length 3 "  <" $line]} {
-	set $currdiffsubmod ""
 	set line [encoding convertfrom $diffencoding $line]
 	$ctext insert end "$line\n" d0
     } elseif {$diffinhdr} {
-- 
2.19.1.windows.1


```

## Paul Mackerras, 2019-12-15 04:39

Subject: Re: [PATCH] gitk: don't highlight files after submodules as submodules
Message-ID: <20191215043926.GE12512@blackberry>
URL: https://gitlist.dev/e/20191215043926.GE12512%40blackberry
In-Reply-To: <20191101233427.4108-1-dpb@corrigendum.ru>

```
On Sat, Nov 02, 2019 at 02:34:27AM +0300, Роман Донченко wrote:
> gitk applies submodule highlighting (coloring lines starting with
> "  >" and "  <") when `currdiffsubmod` is not an empty string.
> However, it fails to reset `currdiffsubmod` after a submodule diff
> ends, so any file diffs following a submodule diff will still be
> highlighted as if they were submodule diffs.
> 
> There are two problems with the way gitk tries to reset `currdiffsubmod`:
> 
> 1. The code says `set $currdiffsubmod` instead of `set currdiffsubmod`,
>    so it actually sets the variable whose name is the submodule path
>    instead.
> 
> 2. It tries to do it after the first line in a submodule diff, which
>    is incorrect, since submodule diffs can contain multiple lines.
> 
> Fix this by resetting `currdiffsubmod` when a file diff starts.
> 
> Signed-off-by: Роман Донченко <dpb@corrigendum.ru>

Thanks, patch applied.

Paul.

```
