Re: [PATCHv2 1/2] git-gui: respect conflict marker size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> writes:

>Respect the conflict-marker-size attribute on paths when detecting merge
>conflicts.
>
>Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>
>
>---
>
>v2 fixes the tags selection and also the regexp to match always exactly the
>desired number of markers.
>
>Bert
>
> git-gui/git-gui.sh   |    6 +++---
> git-gui/lib/diff.tcl |   22 ++++++++++++++++++----
> 2 files changed, 21 insertions(+), 7 deletions(-)
>
>diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
>index d3acf0d..38362fa 100755
>--- a/git-gui/git-gui.sh
>+++ b/git-gui/git-gui.sh
>@@ -3351,13 +3351,13 @@ $ui_diff tag conf d_s- \
> 	-foreground red \
> 	-background ivory1
> 
>-$ui_diff tag conf d<<<<<<< \
>+$ui_diff tag conf d< \
> 	-foreground orange \
> 	-font font_diffbold
>-$ui_diff tag conf d======= \
>+$ui_diff tag conf d= \
> 	-foreground orange \
> 	-font font_diffbold
>-$ui_diff tag conf d>>>>>>> \
>+$ui_diff tag conf d> \
> 	-foreground orange \
> 	-font font_diffbold
> 
>diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
>index dcf0711..d4e2ce3 100644
>--- a/git-gui/lib/diff.tcl
>+++ b/git-gui/lib/diff.tcl
>@@ -253,6 +253,19 @@ 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
>@@ -268,6 +281,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 cmd [list]
> 	if {$w eq $ui_index} {
>@@ -329,7 +343,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
> 		-blocking 0 \
> 		-encoding [get_path_encoding $path] \
> 		-translation lf
>-	fileevent $fd readable [list read_diff $fd $cont_info]
>+	fileevent $fd readable [list read_diff $fd $conflict_size $cont_info]
> }
> 
> proc parse_color_line {line} {
>@@ -349,7 +363,7 @@ proc parse_color_line {line} {
> 	return [list $result $markup]
> }
> 
>-proc read_diff {fd cont_info} {
>+proc read_diff {fd conflict_size cont_info} {
> 	global ui_diff diff_active is_submodule_diff
> 	global is_3way_diff is_conflict_diff current_diff_header
> 	global current_diff_queue
>@@ -402,7 +416,7 @@ proc read_diff {fd cont_info} {
> 			{- } {set tags d_-s}
> 			{--} {set tags d_--}
> 			{++} {
>-				if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
>+				if {[regexp {^\+\+([<>=]){$conflict_size}(?: |$)} $line _g op]} {
> 					set is_conflict_diff 1
> 					set line [string replace $line 0 1 {  }]
> 					set tags d$op
>@@ -441,7 +455,7 @@ proc read_diff {fd cont_info} {
> 			{@} {set tags d_@}
> 			{-} {set tags d_-}
> 			{+} {
>-				if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
>+				if {[regexp {^\+([<>=]){$conflict_size}(?: |$)} $line _g op]} {
> 					set is_conflict_diff 1
> 					set tags d$op
> 				} else {

Tcl doesn't expand variables in curly-braced expressions so the
$conflict_size is left in there verbatim.

Either 
  set regexp [string map [list %conflict_size $conflict_size]\
      {^\+([<>=]){%conflict_size}(?: |$)}]
which substitutes in the expanded value or double-quotes with care to
protect anything that Tcl would expand in the regexp. The string map
style is often easier to read.
  regexp "^\\+(\[<>=\]){$conflict_size}(?: |\$)" $line _g op

I've squashed in a fix using string map on this one. With that it
appears to work fine. I never noticed this attribute before.

-- 
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]