Skip to content

Commit 5fc3e67

Browse files
committed
Merge updated git-gui and gitk that call each other
Merge git://repo.or.cz/git-gui and git://git.kernel.org/pub/scm/gitk/gitk * git://repo.or.cz/git-gui: git-gui: Show special diffs for complex conflict cases. git-gui: Make F5 reselect a diff, if an untracked file is selected. git-gui: Reimplement and enhance auto-selection of diffs. git-gui: Support conflict states _U & UT. git-gui: Support more merge tools. git-gui: Don't allow staging files with conflicts. git-gui: Support calling merge tools. git-gui: Support resolving conflicts via the diff context menu. git-gui: Mark forgotten strings for translation. git-gui: Allow specifying an initial line for git gui blame. git-gui: Better positioning in Blame Parent Commit git-gui: Support passing blame to a parent commit. git-gui: Support starting gitk from Gui Blame git-gui: Teach git gui about file type changes * git://git.kernel.org/pub/scm/gitk/gitk: gitk: Add menu item for calling git gui blame gitk: Add option to specify the default commit on command line
3 parents 4a09bc9 + 95b6a2d + 77aa0ae commit 5fc3e67

File tree

9 files changed

+943
-120
lines changed

9 files changed

+943
-120
lines changed

git-gui/git-gui.sh

Lines changed: 259 additions & 90 deletions
Large diffs are not rendered by default.

git-gui/lib/blame.tcl

Lines changed: 150 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ field tooltip_t {} ; # Text widget in $tooltip_wm
5858
field tooltip_timer {} ; # Current timer event for our tooltip
5959
field tooltip_commit {} ; # Commit(s) in tooltip
6060

61-
constructor new {i_commit i_path} {
61+
constructor new {i_commit i_path i_jump} {
6262
global cursor_ptr
6363
variable active_color
6464
variable group_colors
@@ -259,6 +259,12 @@ constructor new {i_commit i_path} {
259259
$w.ctxm add command \
260260
-label [mc "Do Full Copy Detection"] \
261261
-command [cb _fullcopyblame]
262+
$w.ctxm add command \
263+
-label [mc "Show History Context"] \
264+
-command [cb _gitkcommit]
265+
$w.ctxm add command \
266+
-label [mc "Blame Parent Commit"] \
267+
-command [cb _blameparent]
262268

263269
foreach i $w_columns {
264270
for {set g 0} {$g < [llength $group_colors]} {incr g} {
@@ -332,7 +338,7 @@ constructor new {i_commit i_path} {
332338
wm protocol $top WM_DELETE_WINDOW "destroy $top"
333339
bind $top <Destroy> [cb _kill]
334340

335-
_load $this {}
341+
_load $this $i_jump
336342
}
337343

338344
method _kill {} {
@@ -787,19 +793,27 @@ method _load_commit {cur_w cur_d pos} {
787793
set lno [lindex [split [$cur_w index $pos] .] 0]
788794
set dat [lindex $line_data $lno]
789795
if {$dat ne {}} {
790-
lappend history [list \
791-
$commit $path \
792-
$highlight_column \
793-
$highlight_line \
794-
[lindex [$w_file xview] 0] \
795-
[lindex [$w_file yview] 0] \
796-
]
797-
set commit [lindex $dat 0]
798-
set path [lindex $dat 1]
799-
_load $this [list [lindex $dat 2]]
796+
_load_new_commit $this \
797+
[lindex $dat 0] \
798+
[lindex $dat 1] \
799+
[list [lindex $dat 2]]
800800
}
801801
}
802802

803+
method _load_new_commit {new_commit new_path jump} {
804+
lappend history [list \
805+
$commit $path \
806+
$highlight_column \
807+
$highlight_line \
808+
[lindex [$w_file xview] 0] \
809+
[lindex [$w_file yview] 0] \
810+
]
811+
812+
set commit $new_commit
813+
set path $new_path
814+
_load $this $jump
815+
}
816+
803817
method _showcommit {cur_w lno} {
804818
global repo_config
805819
variable active_color
@@ -905,10 +919,14 @@ method _showcommit {cur_w lno} {
905919
}
906920
}
907921

908-
method _copycommit {} {
922+
method _get_click_amov_info {} {
909923
set pos @$::cursorX,$::cursorY
910924
set lno [lindex [split [$::cursorW index $pos] .] 0]
911-
set dat [lindex $amov_data $lno]
925+
return [lindex $amov_data $lno]
926+
}
927+
928+
method _copycommit {} {
929+
set dat [_get_click_amov_info $this]
912930
if {$dat ne {}} {
913931
clipboard clear
914932
clipboard append \
@@ -918,6 +936,124 @@ method _copycommit {} {
918936
}
919937
}
920938

939+
method _format_offset_date {base offset} {
940+
set exval [expr {$base + $offset*24*60*60}]
941+
return [clock format $exval -format {%Y-%m-%d}]
942+
}
943+
944+
method _gitkcommit {} {
945+
set dat [_get_click_amov_info $this]
946+
if {$dat ne {}} {
947+
set cmit [lindex $dat 0]
948+
set radius [get_config gui.blamehistoryctx]
949+
set cmdline [list --select-commit=$cmit]
950+
951+
if {$radius > 0} {
952+
set author_time {}
953+
set committer_time {}
954+
955+
catch {set author_time $header($cmit,author-time)}
956+
catch {set committer_time $header($cmit,committer-time)}
957+
958+
if {$committer_time eq {}} {
959+
set committer_time $author_time
960+
}
961+
962+
set after_time [_format_offset_date $this $committer_time [expr {-$radius}]]
963+
set before_time [_format_offset_date $this $committer_time $radius]
964+
965+
lappend cmdline --after=$after_time --before=$before_time
966+
}
967+
968+
lappend cmdline $cmit
969+
970+
set base_rev "HEAD"
971+
if {$commit ne {}} {
972+
set base_rev $commit
973+
}
974+
975+
if {$base_rev ne $cmit} {
976+
lappend cmdline $base_rev
977+
}
978+
979+
do_gitk $cmdline
980+
}
981+
}
982+
983+
method _blameparent {} {
984+
set dat [_get_click_amov_info $this]
985+
if {$dat ne {}} {
986+
set cmit [lindex $dat 0]
987+
set new_path [lindex $dat 1]
988+
989+
if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
990+
error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
991+
return;
992+
}
993+
994+
_kill $this
995+
996+
# Generate a diff between the commit and its parent,
997+
# and use the hunks to update the line number.
998+
# Request zero context to simplify calculations.
999+
if {[catch {set fd [eval git_read diff-tree \
1000+
--unified=0 $cparent $cmit $new_path]} err]} {
1001+
$status stop [mc "Unable to display parent"]
1002+
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
1003+
return
1004+
}
1005+
1006+
set r_orig_line [lindex $dat 2]
1007+
1008+
fconfigure $fd \
1009+
-blocking 0 \
1010+
-encoding binary \
1011+
-translation binary
1012+
fileevent $fd readable [cb _read_diff_load_commit \
1013+
$fd $cparent $new_path $r_orig_line]
1014+
set current_fd $fd
1015+
}
1016+
}
1017+
1018+
method _read_diff_load_commit {fd cparent new_path tline} {
1019+
if {$fd ne $current_fd} {
1020+
catch {close $fd}
1021+
return
1022+
}
1023+
1024+
while {[gets $fd line] >= 0} {
1025+
if {[regexp {^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@} $line line \
1026+
old_line osz old_size new_line nsz new_size]} {
1027+
1028+
if {$osz eq {}} { set old_size 1 }
1029+
if {$nsz eq {}} { set new_size 1 }
1030+
1031+
if {$new_line <= $tline} {
1032+
if {[expr {$new_line + $new_size}] > $tline} {
1033+
# Target line within the hunk
1034+
set line_shift [expr {
1035+
($new_size-$old_size)*($tline-$new_line)/$new_size
1036+
}]
1037+
} else {
1038+
set line_shift [expr {$new_size-$old_size}]
1039+
}
1040+
1041+
set r_orig_line [expr {$r_orig_line - $line_shift}]
1042+
}
1043+
}
1044+
}
1045+
1046+
if {[eof $fd]} {
1047+
close $fd;
1048+
set current_fd {}
1049+
1050+
_load_new_commit $this \
1051+
$cparent \
1052+
$new_path \
1053+
[list $r_orig_line]
1054+
}
1055+
} ifdeleted { catch {close $fd} }
1056+
9211057
method _show_tooltip {cur_w pos} {
9221058
if {$tooltip_wm ne {}} {
9231059
_open_tooltip $this $cur_w

git-gui/lib/browser.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ method _enter {} {
151151
append p [lindex $n 1]
152152
}
153153
append p $name
154-
blame::new $browser_commit $p
154+
blame::new $browser_commit $p {}
155155
}
156156
}
157157
}

git-gui/lib/commit.tcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ The rescan will be automatically started now.
149149
_? {continue}
150150
A? -
151151
D? -
152+
T_ -
152153
M? {set files_ready 1}
154+
_U -
153155
U? {
154156
error_popup [mc "Unmerged files cannot be committed.
155157
@@ -428,6 +430,7 @@ A rescan will be automatically started now.
428430
__ -
429431
A_ -
430432
M_ -
433+
T_ -
431434
D_ {
432435
unset file_states($path)
433436
catch {unset selected_paths($path)}

0 commit comments

Comments
 (0)