# [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute

7 messages from 2019-09-30 to 2019-10-02. Participants: Bert Wesarg, Pratyush Yadav.
Thread: https://gitlist.dev/t/51943

## Bert Wesarg, 2019-09-30 19:54

Subject: [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute
Message-ID: <97013a71289857767100d6a4adcb39ca99b2b21b.1569873171.git.bert.wesarg@googlemail.com>
URL: https://gitlist.dev/e/97013a71289857767100d6a4adcb39ca99b2b21b.1569873171.git.bert.wesarg%40googlemail.com

```
Replace the hand-coded call to git check-attr with the already provided one.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 lib/diff.tcl | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/lib/diff.tcl b/lib/diff.tcl
index 958a0fa..0fd4600 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -270,19 +270,6 @@ proc show_other_diff {path w m cont_info} {
 	}
 }
 
-proc get_conflict_marker_size {path} {
-	set size 7
-	catch {
-		set fd_rc [eval [list git_read check-attr "conflict-marker-size" -- $path]]
-		set ret [gets $fd_rc line]
-		close $fd_rc
-		if {$ret > 0} {
-			regexp {.*: conflict-marker-size: (\d+)$} $line line size
-		}
-	}
-	return $size
-}
-
 proc start_show_diff {cont_info {add_opts {}}} {
 	global file_states file_lists
 	global is_3way_diff is_submodule_diff diff_active repo_config
@@ -298,7 +285,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
 	set is_submodule_diff 0
 	set diff_active 1
 	set current_diff_header {}
-	set conflict_size [get_conflict_marker_size $path]
+	set conflict_size [gitattr $path conflict-marker-size 7]
 
 	set cmd [list]
 	if {$w eq $ui_index} {
-- 
2.23.0.11.g242cf7f110


```

## Pratyush Yadav, 2019-10-01 14:24

Subject: Re: [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute
Message-ID: <20191001142401.hhg5dtefj6qg66dd@yadavpratyush.com>
URL: https://gitlist.dev/e/20191001142401.hhg5dtefj6qg66dd%40yadavpratyush.com
In-Reply-To: <97013a71289857767100d6a4adcb39ca99b2b21b.1569873171.git.bert.wesarg@googlemail.com>

```
Hi,

I don't see any difference between v3 and v2 of this patch. What changed 
in this version?

On 30/09/19 09:54PM, Bert Wesarg wrote:
> Replace the hand-coded call to git check-attr with the already provided one.
> 
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
>  lib/diff.tcl | 15 +--------------
>  1 file changed, 1 insertion(+), 14 deletions(-)
> 
> diff --git a/lib/diff.tcl b/lib/diff.tcl
> index 958a0fa..0fd4600 100644
> --- a/lib/diff.tcl
> +++ b/lib/diff.tcl
> @@ -270,19 +270,6 @@ proc show_other_diff {path w m cont_info} {
>  	}
>  }
>  
> -proc get_conflict_marker_size {path} {
> -	set size 7
> -	catch {
> -		set fd_rc [eval [list git_read check-attr "conflict-marker-size" -- $path]]
> -		set ret [gets $fd_rc line]
> -		close $fd_rc
> -		if {$ret > 0} {
> -			regexp {.*: conflict-marker-size: (\d+)$} $line line size
> -		}
> -	}
> -	return $size
> -}
> -
>  proc start_show_diff {cont_info {add_opts {}}} {
>  	global file_states file_lists
>  	global is_3way_diff is_submodule_diff diff_active repo_config
> @@ -298,7 +285,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
>  	set is_submodule_diff 0
>  	set diff_active 1
>  	set current_diff_header {}
> -	set conflict_size [get_conflict_marker_size $path]
> +	set conflict_size [gitattr $path conflict-marker-size 7]
>  
>  	set cmd [list]
>  	if {$w eq $ui_index} {
> -- 
> 2.23.0.11.g242cf7f110
> 

-- 
Regards,
Pratyush Yadav

```

## Bert Wesarg, 2019-10-01 15:22

Subject: Re: [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute
Message-ID: <CAKPyHN2qSudnEMfokp5-BXBDU6_kcVv3aokNUYdqZOnMXYVzYw@mail.gmail.com>
URL: https://gitlist.dev/e/CAKPyHN2qSudnEMfokp5-BXBDU6_kcVv3aokNUYdqZOnMXYVzYw%40mail.gmail.com
In-Reply-To: <20191001142401.hhg5dtefj6qg66dd@yadavpratyush.com>

```
On Tue, Oct 1, 2019 at 4:24 PM Pratyush Yadav <me@yadavpratyush.com> wrote:
>
> Hi,
>
> I don't see any difference between v3 and v2 of this patch. What changed
> in this version?

nothing, but 2/2 changed.

Bert

>
> On 30/09/19 09:54PM, Bert Wesarg wrote:
> > Replace the hand-coded call to git check-attr with the already provided one.
> >
> > Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> > ---
> >  lib/diff.tcl | 15 +--------------
> >  1 file changed, 1 insertion(+), 14 deletions(-)
> >
> > diff --git a/lib/diff.tcl b/lib/diff.tcl
> > index 958a0fa..0fd4600 100644
> > --- a/lib/diff.tcl
> > +++ b/lib/diff.tcl
> > @@ -270,19 +270,6 @@ proc show_other_diff {path w m cont_info} {
> >       }
> >  }
> >
> > -proc get_conflict_marker_size {path} {
> > -     set size 7
> > -     catch {
> > -             set fd_rc [eval [list git_read check-attr "conflict-marker-size" -- $path]]
> > -             set ret [gets $fd_rc line]
> > -             close $fd_rc
> > -             if {$ret > 0} {
> > -                     regexp {.*: conflict-marker-size: (\d+)$} $line line size
> > -             }
> > -     }
> > -     return $size
> > -}
> > -
> >  proc start_show_diff {cont_info {add_opts {}}} {
> >       global file_states file_lists
> >       global is_3way_diff is_submodule_diff diff_active repo_config
> > @@ -298,7 +285,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
> >       set is_submodule_diff 0
> >       set diff_active 1
> >       set current_diff_header {}
> > -     set conflict_size [get_conflict_marker_size $path]
> > +     set conflict_size [gitattr $path conflict-marker-size 7]
> >
> >       set cmd [list]
> >       if {$w eq $ui_index} {
> > --
> > 2.23.0.11.g242cf7f110
> >
>
> --
> Regards,
> Pratyush Yadav

```

## Pratyush Yadav, 2019-10-01 17:31

Subject: Re: [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute
Message-ID: <20191001173100.n5dipyhjk4uxcnnj@yadavpratyush.com>
URL: https://gitlist.dev/e/20191001173100.n5dipyhjk4uxcnnj%40yadavpratyush.com
In-Reply-To: <CAKPyHN2qSudnEMfokp5-BXBDU6_kcVv3aokNUYdqZOnMXYVzYw@mail.gmail.com>

```
On 01/10/19 05:22PM, Bert Wesarg wrote:
> On Tue, Oct 1, 2019 at 4:24 PM Pratyush Yadav <me@yadavpratyush.com> wrote:
> >
> > Hi,
> >
> > I don't see any difference between v3 and v2 of this patch. What changed
> > in this version?
> 
> nothing, but 2/2 changed.

I don't see a v3 of 2/2 in my inbox. A search on public-inbox yields 
nothing either. Can you please check if the patch was sent properly? Or 
if you _can_ find it on public-inbox.org, a link to that would do just 
fine.

I _do_ have v2 of both patches, but the v3 of the second patch is the 
one missing.

-- 
Regards,
Pratyush Yadav

```

## Bert Wesarg, 2019-10-02 07:35

Subject: Re: [PATCH v3 1/2] git-gui: use existing interface to query a path's attribute
Message-ID: <CAKPyHN31qQwL=x0hwk2TjOkyC8iRtcLY0v6NgwA81N2i8P6aBg@mail.gmail.com>
URL: https://gitlist.dev/e/CAKPyHN31qQwL%3Dx0hwk2TjOkyC8iRtcLY0v6NgwA81N2i8P6aBg%40mail.gmail.com
In-Reply-To: <20191001173100.n5dipyhjk4uxcnnj@yadavpratyush.com>

```
Pratyush,

On Tue, Oct 1, 2019 at 7:31 PM Pratyush Yadav <me@yadavpratyush.com> wrote:
>
> On 01/10/19 05:22PM, Bert Wesarg wrote:
> > On Tue, Oct 1, 2019 at 4:24 PM Pratyush Yadav <me@yadavpratyush.com> wrote:
> > >
> > > Hi,
> > >
> > > I don't see any difference between v3 and v2 of this patch. What changed
> > > in this version?
> >
> > nothing, but 2/2 changed.
>
> I don't see a v3 of 2/2 in my inbox. A search on public-inbox yields
> nothing either. Can you please check if the patch was sent properly? Or
> if you _can_ find it on public-inbox.org, a link to that would do just
> fine.
>
> I _do_ have v2 of both patches, but the v3 of the second patch is the
> one missing.

I noticed this already, while in contact with Johannes on GitHub and I
found my error. While pasting messages ids for References into the v3
patch, I missed to renamed Message-Id to References for the v2 patch,
thus the v3 has the same Message-Id than the v2 patch. Will resend
now.

Bert

>
> --
> Regards,
> Pratyush Yadav

```

## Bert Wesarg, 2019-10-02 07:36

Subject: [PATCH v3 2/2] git-gui: support for diff3 conflict style
Message-ID: <a7cff5097eaf29a80c822cb37b537b3859d06ad7.1569873171.git.bert.wesarg@googlemail.com>
URL: https://gitlist.dev/e/a7cff5097eaf29a80c822cb37b537b3859d06ad7.1569873171.git.bert.wesarg%40googlemail.com
In-Reply-To: <97013a71289857767100d6a4adcb39ca99b2b21b.1569873171.git.bert.wesarg@googlemail.com>

```
This adds highlight support for the diff3 conflict style.

The common pre-image will be reversed to --, because it has been removed
and replaced with ours or theirs side respectively.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 git-gui.sh   |  3 +++
 lib/diff.tcl | 17 ++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

--- 

v3: Fixed a syntax error

diff --git a/git-gui.sh b/git-gui.sh
index fd476b6..6d80f82 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3581,6 +3581,9 @@ $ui_diff tag conf d_s- \
 $ui_diff tag conf d< \
 	-foreground orange \
 	-font font_diffbold
+$ui_diff tag conf d| \
+	-foreground orange \
+	-font font_diffbold
 $ui_diff tag conf d= \
 	-foreground orange \
 	-font font_diffbold
diff --git a/lib/diff.tcl b/lib/diff.tcl
index 0fd4600..dacdda2 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -347,6 +347,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
 	}
 
 	set ::current_diff_inheader 1
+	# detect pre-image lines of the diff3 conflict-style, they are just '++'
+	# lines which is not bijective, thus we need to maintain a state across
+	# lines
+	set ::conflict_in_pre_image 0
 	fconfigure $fd \
 		-blocking 0 \
 		-encoding [get_path_encoding $path] \
@@ -449,11 +453,22 @@ proc read_diff {fd conflict_size cont_info} {
 			{--} {set tags d_--}
 			{++} {
 				set regexp [string map [list %conflict_size $conflict_size]\
-								{^\+\+([<>=]){%conflict_size}(?: |$)}]
+								{^\+\+([<>=|]){%conflict_size}(?: |$)}]
 				if {[regexp $regexp $line _g op]} {
 					set is_conflict_diff 1
 					set line [string replace $line 0 1 {  }]
 					set tags d$op
+					# the ||| conflict-marker marks the start of the pre-image,
+					# all those lines are also prefixed with '++', thus we need
+					# to maintain this state
+					set ::conflict_in_pre_image [expr {$op eq {|}}]
+				} elseif {$::conflict_in_pre_image} {
+					# this is a pre-image line, it is the one which both sides
+					# are based on. As it has also the '++' line start, it is
+					# normally shown as 'added', invert this to '--' to make
+					# it a 'removed' line
+					set line [string replace $line 0 1 {--}]
+					set tags d_--
 				} else {
 					set tags d_++
 				}
-- 
2.23.0.11.g242cf7f110


```

## Pratyush Yadav, 2019-10-02 23:54

Subject: Re: [PATCH v3 2/2] git-gui: support for diff3 conflict style
Message-ID: <20191002235411.bfkrjc6cgyayqwud@yadavpratyush.com>
URL: https://gitlist.dev/e/20191002235411.bfkrjc6cgyayqwud%40yadavpratyush.com
In-Reply-To: <a7cff5097eaf29a80c822cb37b537b3859d06ad7.1569873171.git.bert.wesarg@googlemail.com>

```
Hi,

I made some fixes to the punctuation and capitalization in the comments 
you added. You can take a look at [0].

Just to be sure, I get the following text in git-gui when I ran your 
example:

  <<<<<<< HEAD
 +Proin bibendum purus ut est tristique, non pharetra dui consectetur.
  ||||||| merged common ancestors
--Proin in felis eu elit suscipit rhoncus vel ut metus.
  =======
+ Proin placerat leo malesuada lacinia lobortis.
  >>>>>>> branch

I noticed that the line after '<<<<<<< HEAD' starts with ' +' and the 
line after '=======' starts with '+ '.

So on the "HEAD" version, the space is before the '+', and on the 
"branch" version, the space is after the '+'. This is the intended 
behaviour, right?

It is not strictly related to your patch because it happens without 
diff3 conflict style enabled as well, but I just want to make sure this 
is not a bug.

The patch looks good. Will queue. Thanks.

[0] https://github.com/prati0100/git-gui/commit/d6e413c7cff6d09a0089d7a5de115ad438b42e81

On 02/10/19 09:36AM, Bert Wesarg wrote:
> This adds highlight support for the diff3 conflict style.
> 
> The common pre-image will be reversed to --, because it has been removed
> and replaced with ours or theirs side respectively.
> 
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
>  git-gui.sh   |  3 +++
>  lib/diff.tcl | 17 ++++++++++++++++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> --- 
> 
> v3: Fixed a syntax error
> 
> diff --git a/git-gui.sh b/git-gui.sh
> index fd476b6..6d80f82 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -3581,6 +3581,9 @@ $ui_diff tag conf d_s- \
>  $ui_diff tag conf d< \
>  	-foreground orange \
>  	-font font_diffbold
> +$ui_diff tag conf d| \
> +	-foreground orange \
> +	-font font_diffbold
>  $ui_diff tag conf d= \
>  	-foreground orange \
>  	-font font_diffbold
> diff --git a/lib/diff.tcl b/lib/diff.tcl
> index 0fd4600..dacdda2 100644
> --- a/lib/diff.tcl
> +++ b/lib/diff.tcl
> @@ -347,6 +347,10 @@ proc start_show_diff {cont_info {add_opts {}}} {
>  	}
>  
>  	set ::current_diff_inheader 1
> +	# detect pre-image lines of the diff3 conflict-style, they are just '++'
> +	# lines which is not bijective, thus we need to maintain a state across
> +	# lines
> +	set ::conflict_in_pre_image 0
>  	fconfigure $fd \
>  		-blocking 0 \
>  		-encoding [get_path_encoding $path] \
> @@ -449,11 +453,22 @@ proc read_diff {fd conflict_size cont_info} {
>  			{--} {set tags d_--}
>  			{++} {
>  				set regexp [string map [list %conflict_size $conflict_size]\
> -								{^\+\+([<>=]){%conflict_size}(?: |$)}]
> +								{^\+\+([<>=|]){%conflict_size}(?: |$)}]
>  				if {[regexp $regexp $line _g op]} {
>  					set is_conflict_diff 1
>  					set line [string replace $line 0 1 {  }]
>  					set tags d$op
> +					# the ||| conflict-marker marks the start of the pre-image,
> +					# all those lines are also prefixed with '++', thus we need
> +					# to maintain this state
> +					set ::conflict_in_pre_image [expr {$op eq {|}}]
> +				} elseif {$::conflict_in_pre_image} {
> +					# this is a pre-image line, it is the one which both sides
> +					# are based on. As it has also the '++' line start, it is
> +					# normally shown as 'added', invert this to '--' to make
> +					# it a 'removed' line
> +					set line [string replace $line 0 1 {--}]
> +					set tags d_--
>  				} else {
>  					set tags d_++
>  				}

-- 
Regards,
Pratyush Yadav

```
