about summary refs log tree commit diff
path: root/third_party/git/git-gui/lib/diff.tcl
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T23·06+0100
commit93ba78d6f4632ef1c5228965e3edc8c0faf88c1e (patch)
tree85730c182a9f5f492ade8e8ccdb1c2356f9900bd /third_party/git/git-gui/lib/diff.tcl
parent6f8fbf4aa4b1654ab27d4829e114538761817de0 (diff)
revert(3p/git): Revert merge of git upstream at v2.26.2 r/852
This causes cgit to serve error pages, which is undesirable.

This reverts commit 5229c9b232de5bfa959ad6ebbb4c8192ac513352, reversing
changes made to f2b211131f2347342dde63975b09cf603149f1a3.
Diffstat (limited to 'third_party/git/git-gui/lib/diff.tcl')
-rw-r--r--third_party/git/git-gui/lib/diff.tcl129
1 files changed, 30 insertions, 99 deletions
diff --git a/third_party/git/git-gui/lib/diff.tcl b/third_party/git/git-gui/lib/diff.tcl
index 871ad488c2..68c4a6c736 100644
--- a/third_party/git/git-gui/lib/diff.tcl
+++ b/third_party/git/git-gui/lib/diff.tcl
@@ -55,7 +55,7 @@ proc reshow_diff {{after {}}} {
 
 proc force_diff_encoding {enc} {
 	global current_diff_path
-
+	
 	if {$current_diff_path ne {}} {
 		force_path_encoding $current_diff_path $enc
 		reshow_diff
@@ -270,6 +270,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
@@ -285,7 +298,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 [gitattr $path conflict-marker-size 7]
+	set conflict_size [get_conflict_marker_size $path]
 
 	set cmd [list]
 	if {$w eq $ui_index} {
@@ -347,10 +360,6 @@ 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] \
@@ -453,23 +462,11 @@ 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_++
 				}
@@ -570,31 +567,24 @@ proc read_diff {fd conflict_size cont_info} {
 	}
 }
 
-proc apply_or_revert_hunk {x y revert} {
+proc apply_hunk {x y} {
 	global current_diff_path current_diff_header current_diff_side
-	global ui_diff ui_index file_states last_revert last_revert_enc
+	global ui_diff ui_index file_states
 
 	if {$current_diff_path eq {} || $current_diff_header eq {}} return
 	if {![lock_index apply_hunk]} return
 
-	set apply_cmd {apply --whitespace=nowarn}
+	set apply_cmd {apply --cached --whitespace=nowarn}
 	set mi [lindex $file_states($current_diff_path) 0]
 	if {$current_diff_side eq $ui_index} {
 		set failed_msg [mc "Failed to unstage selected hunk."]
-		lappend apply_cmd --reverse --cached
+		lappend apply_cmd --reverse
 		if {[string index $mi 0] ne {M}} {
 			unlock_index
 			return
 		}
 	} else {
-		if {$revert} {
-			set failed_msg [mc "Failed to revert selected hunk."]
-			lappend apply_cmd --reverse
-		} else {
-			set failed_msg [mc "Failed to stage selected hunk."]
-			lappend apply_cmd --cached
-		}
-
+		set failed_msg [mc "Failed to stage selected hunk."]
 		if {[string index $mi 1] ne {M}} {
 			unlock_index
 			return
@@ -613,40 +603,29 @@ proc apply_or_revert_hunk {x y revert} {
 		set e_lno end
 	}
 
-	set wholepatch "$current_diff_header[$ui_diff get $s_lno $e_lno]"
-
 	if {[catch {
 		set enc [get_path_encoding $current_diff_path]
 		set p [eval git_write $apply_cmd]
 		fconfigure $p -translation binary -encoding $enc
-		puts -nonewline $p $wholepatch
+		puts -nonewline $p $current_diff_header
+		puts -nonewline $p [$ui_diff get $s_lno $e_lno]
 		close $p} err]} {
 		error_popup "$failed_msg\n\n$err"
 		unlock_index
 		return
 	}
 
-	if {$revert} {
-		# Save a copy of this patch for undoing reverts.
-		set last_revert $wholepatch
-		set last_revert_enc $enc
-	}
-
 	$ui_diff conf -state normal
 	$ui_diff delete $s_lno $e_lno
 	$ui_diff conf -state disabled
 
-	# Check if the hunk was the last one in the file.
 	if {[$ui_diff get 1.0 end] eq "\n"} {
 		set o _
 	} else {
 		set o ?
 	}
 
-	# Update the status flags.
-	if {$revert} {
-		set mi [string index $mi 0]$o
-	} elseif {$current_diff_side eq $ui_index} {
+	if {$current_diff_side eq $ui_index} {
 		set mi ${o}M
 	} elseif {[string index $mi 0] eq {_}} {
 		set mi M$o
@@ -661,9 +640,9 @@ proc apply_or_revert_hunk {x y revert} {
 	}
 }
 
-proc apply_or_revert_range_or_line {x y revert} {
+proc apply_range_or_line {x y} {
 	global current_diff_path current_diff_header current_diff_side
-	global ui_diff ui_index file_states last_revert
+	global ui_diff ui_index file_states
 
 	set selected [$ui_diff tag nextrange sel 0.0]
 
@@ -681,27 +660,19 @@ proc apply_or_revert_range_or_line {x y revert} {
 	if {$current_diff_path eq {} || $current_diff_header eq {}} return
 	if {![lock_index apply_hunk]} return
 
-	set apply_cmd {apply --whitespace=nowarn}
+	set apply_cmd {apply --cached --whitespace=nowarn}
 	set mi [lindex $file_states($current_diff_path) 0]
 	if {$current_diff_side eq $ui_index} {
 		set failed_msg [mc "Failed to unstage selected line."]
 		set to_context {+}
-		lappend apply_cmd --reverse --cached
+		lappend apply_cmd --reverse
 		if {[string index $mi 0] ne {M}} {
 			unlock_index
 			return
 		}
 	} else {
-		if {$revert} {
-			set failed_msg [mc "Failed to revert selected line."]
-			set to_context {+}
-			lappend apply_cmd --reverse
-		} else {
-			set failed_msg [mc "Failed to stage selected line."]
-			set to_context {-}
-			lappend apply_cmd --cached
-		}
-
+		set failed_msg [mc "Failed to stage selected line."]
+		set to_context {-}
 		if {[string index $mi 1] ne {M}} {
 			unlock_index
 			return
@@ -859,47 +830,7 @@ proc apply_or_revert_range_or_line {x y revert} {
 		puts -nonewline $p $wholepatch
 		close $p} err]} {
 		error_popup "$failed_msg\n\n$err"
-		unlock_index
-		return
-	}
-
-	if {$revert} {
-		# Save a copy of this patch for undoing reverts.
-		set last_revert $current_diff_header$wholepatch
-		set last_revert_enc $enc
-	}
-
-	unlock_index
-}
-
-# Undo the last line/hunk reverted. When hunks and lines are reverted, a copy
-# of the diff applied is saved. Re-apply that diff to undo the revert.
-#
-# Right now, we only use a single variable to hold the copy, and not a
-# stack/deque for simplicity, so multiple undos are not possible. Maybe this
-# can be added if the need for something like this is felt in the future.
-proc undo_last_revert {} {
-	global last_revert current_diff_path current_diff_header
-	global last_revert_enc
-
-	if {$last_revert eq {}} return
-	if {![lock_index apply_hunk]} return
-
-	set apply_cmd {apply --whitespace=nowarn}
-	set failed_msg [mc "Failed to undo last revert."]
-
-	if {[catch {
-		set enc $last_revert_enc
-		set p [eval git_write $apply_cmd]
-		fconfigure $p -translation binary -encoding $enc
-		puts -nonewline $p $last_revert
-		close $p} err]} {
-		error_popup "$failed_msg\n\n$err"
-		unlock_index
-		return
 	}
 
-	set last_revert {}
-
 	unlock_index
 }