Skip to content

Commit 09bb4eb

Browse files
committed
Merge git://ozlabs.org/~paulus/gitk
* git://ozlabs.org/~paulus/gitk: gitk: Make vi-style keybindings more vi-like gitk: Make "touching paths" search support backslashes gitk: Show modified files with separate work tree gitk: Simplify calculation of gitdir gitk: Run 'git rev-parse --git-dir' only once gitk: Put temporary directory inside .git gitk: Fix "External diff" with separate work tree gitk: Fix "blame parent commit" with separate work tree gitk: Fix "show origin of this line" with separate work tree gitk: Fix file highlight when run in subdirectory gitk: Update copyright gitk: When a commit contains a note, mark it with a yellow box gitk: Remember time zones from author and commit timestamps gitk: Remove unused $cdate array
2 parents 10f4eb6 + 811c70f commit 09bb4eb

File tree

1 file changed

+65
-45
lines changed

1 file changed

+65
-45
lines changed

gitk-git/gitk

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22
# Tcl ignores the next line -*- tcl -*- \
33
exec wish "$0" -- "$@"
44

5-
# Copyright © 2005-2009 Paul Mackerras. All rights reserved.
5+
# Copyright © 2005-2011 Paul Mackerras. All rights reserved.
66
# This program is free software; it may be used, copied, modified
77
# and distributed under the terms of the GNU General Public Licence,
88
# either version 2, or (at your option) any later version.
99

1010
package require Tk
1111

12-
proc gitdir {} {
13-
global env
14-
if {[info exists env(GIT_DIR)]} {
15-
return $env(GIT_DIR)
16-
} else {
17-
return [exec git rev-parse --git-dir]
18-
}
12+
proc hasworktree {} {
13+
return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
14+
[exec git rev-parse --is-inside-git-dir] == "false"}]
1915
}
2016

2117
# A simple scheduler for compute-intensive stuff.
@@ -468,11 +464,11 @@ proc updatecommits {} {
468464
global viewactive viewcomplete tclencoding
469465
global startmsecs showneartags showlocalchanges
470466
global mainheadid viewmainheadid viewmainheadid_orig pending_select
471-
global isworktree
467+
global hasworktree
472468
global varcid vposids vnegids vflags vrevs
473469
global show_notes
474470

475-
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
471+
set hasworktree [hasworktree]
476472
rereadrefs
477473
set view $curview
478474
if {$mainheadid ne $viewmainheadid_orig($view)} {
@@ -659,7 +655,7 @@ proc newvarc {view id} {
659655
if {![info exists commitinfo($id)]} {
660656
parsecommit $id $commitdata($id) 1
661657
}
662-
set cdate [lindex $commitinfo($id) 4]
658+
set cdate [lindex [lindex $commitinfo($id) 4] 0]
663659
if {![string is integer -strict $cdate]} {
664660
set cdate 0
665661
}
@@ -1621,7 +1617,7 @@ proc readcommit {id} {
16211617
}
16221618

16231619
proc parsecommit {id contents listed} {
1624-
global commitinfo cdate
1620+
global commitinfo
16251621

16261622
set inhdr 1
16271623
set comment {}
@@ -1641,10 +1637,10 @@ proc parsecommit {id contents listed} {
16411637
set line [split $line " "]
16421638
set tag [lindex $line 0]
16431639
if {$tag == "author"} {
1644-
set audate [lindex $line end-1]
1640+
set audate [lrange $line end-1 end]
16451641
set auname [join [lrange $line 1 end-2] " "]
16461642
} elseif {$tag == "committer"} {
1647-
set comdate [lindex $line end-1]
1643+
set comdate [lrange $line end-1 end]
16481644
set comname [join [lrange $line 1 end-2] " "]
16491645
}
16501646
}
@@ -1671,11 +1667,9 @@ proc parsecommit {id contents listed} {
16711667
}
16721668
set comment $newcomment
16731669
}
1674-
if {$comdate != {}} {
1675-
set cdate($id) $comdate
1676-
}
1670+
set hasnote [string first "\nNotes:\n" $contents]
16771671
set commitinfo($id) [list $headline $auname $audate \
1678-
$comname $comdate $comment]
1672+
$comname $comdate $comment $hasnote]
16791673
}
16801674

16811675
proc getcommit {id} {
@@ -2437,9 +2431,9 @@ proc makewindow {} {
24372431
bindkey n "selnextline 1"
24382432
bindkey z "goback"
24392433
bindkey x "goforw"
2440-
bindkey i "selnextline -1"
2441-
bindkey k "selnextline 1"
2442-
bindkey j "goback"
2434+
bindkey k "selnextline -1"
2435+
bindkey j "selnextline 1"
2436+
bindkey h "goback"
24432437
bindkey l "goforw"
24442438
bindkey b prevfile
24452439
bindkey d "$ctext yview scroll 18 units"
@@ -2815,7 +2809,7 @@ proc about {} {
28152809
message $w.m -text [mc "
28162810
Gitk - a commit viewer for git
28172811
2818-
Copyright \u00a9 2005-2010 Paul Mackerras
2812+
Copyright \u00a9 2005-2011 Paul Mackerras
28192813
28202814
Use and redistribute under the terms of the GNU General Public License"] \
28212815
-justify center -aspect 400 -border 2 -bg white -relief groove
@@ -2850,9 +2844,9 @@ proc keys {} {
28502844
[mc "<%s-W> Close window" $M1T]
28512845
[mc "<Home> Move to first commit"]
28522846
[mc "<End> Move to last commit"]
2853-
[mc "<Up>, p, i Move up one commit"]
2854-
[mc "<Down>, n, k Move down one commit"]
2855-
[mc "<Left>, z, j Go back in history list"]
2847+
[mc "<Up>, p, k Move up one commit"]
2848+
[mc "<Down>, n, j Move down one commit"]
2849+
[mc "<Left>, z, h Go back in history list"]
28562850
[mc "<Right>, x, l Go forward in history list"]
28572851
[mc "<PageUp> Move up one page in commit list"]
28582852
[mc "<PageDown> Move down one page in commit list"]
@@ -3333,8 +3327,7 @@ proc gitknewtmpdir {} {
33333327
global diffnum gitktmpdir gitdir
33343328

33353329
if {![info exists gitktmpdir]} {
3336-
set gitktmpdir [file join [file dirname $gitdir] \
3337-
[format ".gitk-tmp.%s" [pid]]]
3330+
set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
33383331
if {[catch {file mkdir $gitktmpdir} err]} {
33393332
error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
33403333
unset gitktmpdir
@@ -3366,10 +3359,10 @@ proc save_file_from_commit {filename output what} {
33663359

33673360
proc external_diff_get_one_file {diffid filename diffdir} {
33683361
global nullid nullid2 nullfile
3369-
global gitdir
3362+
global worktree
33703363

33713364
if {$diffid == $nullid} {
3372-
set difffile [file join [file dirname $gitdir] $filename]
3365+
set difffile [file join $worktree $filename]
33733366
if {[file exists $difffile]} {
33743367
return $difffile
33753368
}
@@ -3559,7 +3552,7 @@ proc make_relative {f} {
35593552
}
35603553

35613554
proc external_blame {parent_idx {line {}}} {
3562-
global flist_menu_file gitdir
3555+
global flist_menu_file cdup
35633556
global nullid nullid2
35643557
global parentlist selectedline currentid
35653558

@@ -3578,7 +3571,7 @@ proc external_blame {parent_idx {line {}}} {
35783571
if {$line ne {} && $line > 1} {
35793572
lappend cmdline "--line=$line"
35803573
}
3581-
set f [file join [file dirname $gitdir] $flist_menu_file]
3574+
set f [file join $cdup $flist_menu_file]
35823575
# Unfortunately it seems git gui blame doesn't like
35833576
# being given an absolute path...
35843577
set f [make_relative $f]
@@ -3591,7 +3584,7 @@ proc external_blame {parent_idx {line {}}} {
35913584
proc show_line_source {} {
35923585
global cmitmode currentid parents curview blamestuff blameinst
35933586
global diff_menu_line diff_menu_filebase flist_menu_file
3594-
global nullid nullid2 gitdir
3587+
global nullid nullid2 gitdir cdup
35953588

35963589
set from_index {}
35973590
if {$cmitmode eq "tree"} {
@@ -3644,7 +3637,7 @@ proc show_line_source {} {
36443637
} else {
36453638
lappend blameargs $id
36463639
}
3647-
lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file]
3640+
lappend blameargs -- [file join $cdup $flist_menu_file]
36483641
if {[catch {
36493642
set f [open $blameargs r]
36503643
} err]} {
@@ -4529,12 +4522,22 @@ proc makepatterns {l} {
45294522

45304523
proc do_file_hl {serial} {
45314524
global highlight_files filehighlight highlight_paths gdttype fhl_list
4525+
global cdup findtype
45324526

45334527
if {$gdttype eq [mc "touching paths:"]} {
4528+
# If "exact" match then convert backslashes to forward slashes.
4529+
# Most useful to support Windows-flavoured file paths.
4530+
if {$findtype eq [mc "Exact"]} {
4531+
set highlight_files [string map {"\\" "/"} $highlight_files]
4532+
}
45344533
if {[catch {set paths [shellsplit $highlight_files]}]} return
45354534
set highlight_paths [makepatterns $paths]
45364535
highlight_filelist
4537-
set gdtargs [concat -- $paths]
4536+
set relative_paths {}
4537+
foreach path $paths {
4538+
lappend relative_paths [file join $cdup $path]
4539+
}
4540+
set gdtargs [concat -- $relative_paths]
45384541
} elseif {$gdttype eq [mc "adding/removing string:"]} {
45394542
set gdtargs [list "-S$highlight_files"]
45404543
} else {
@@ -5031,9 +5034,9 @@ proc dohidelocalchanges {} {
50315034
# spawn off a process to do git diff-index --cached HEAD
50325035
proc dodiffindex {} {
50335036
global lserial showlocalchanges vfilelimit curview
5034-
global isworktree
5037+
global hasworktree
50355038

5036-
if {!$showlocalchanges || !$isworktree} return
5039+
if {!$showlocalchanges || !$hasworktree} return
50375040
incr lserial
50385041
set cmd "|git diff-index --cached HEAD"
50395042
if {$vfilelimit($curview) ne {}} {
@@ -5899,6 +5902,9 @@ proc drawcmittext {id row col} {
58995902
|| [info exists idotherrefs($id)]} {
59005903
set xt [drawtags $id $x $xt $y]
59015904
}
5905+
if {[lindex $commitinfo($id) 6] > 0} {
5906+
set xt [drawnotesign $xt $y]
5907+
}
59025908
set headline [lindex $commitinfo($id) 0]
59035909
set name [lindex $commitinfo($id) 1]
59045910
set date [lindex $commitinfo($id) 2]
@@ -6345,6 +6351,17 @@ proc drawtags {id x xt y1} {
63456351
return $xt
63466352
}
63476353

6354+
proc drawnotesign {xt y} {
6355+
global linespc canv fgcolor
6356+
6357+
set orad [expr {$linespc / 3}]
6358+
set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6359+
[expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6360+
-fill yellow -outline $fgcolor -width 1 -tags circle]
6361+
set xt [expr {$xt + $orad * 3}]
6362+
return $xt
6363+
}
6364+
63486365
proc xcoord {i level ln} {
63496366
global canvx0 xspc1 xspc2
63506367

@@ -9043,6 +9060,7 @@ proc exec_citool {tool_args {baseid {}}} {
90439060
proc cherrypick {} {
90449061
global rowmenuid curview
90459062
global mainhead mainheadid
9063+
global gitdir
90469064

90479065
set oldhead [exec git rev-parse HEAD]
90489066
set dheads [descheads $rowmenuid]
@@ -9071,7 +9089,7 @@ proc cherrypick {} {
90719089
conflict.\nDo you wish to run git citool to\
90729090
resolve it?"]]} {
90739091
# Force citool to read MERGE_MSG
9074-
file delete [file join [gitdir] "GITGUI_MSG"]
9092+
file delete [file join $gitdir "GITGUI_MSG"]
90759093
exec_citool {} $rowmenuid
90769094
}
90779095
} else {
@@ -9437,14 +9455,15 @@ proc refill_reflist {} {
94379455
proc getallcommits {} {
94389456
global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
94399457
global idheads idtags idotherrefs allparents tagobjid
9458+
global gitdir
94409459

94419460
if {![info exists allcommits]} {
94429461
set nextarc 0
94439462
set allcommits 0
94449463
set seeds {}
94459464
set allcwait 0
94469465
set cachedarcs 0
9447-
set allccache [file join [gitdir] "gitk.cache"]
9466+
set allccache [file join $gitdir "gitk.cache"]
94489467
if {![catch {
94499468
set f [open $allccache r]
94509469
set allcwait 1
@@ -11024,7 +11043,7 @@ proc prefsok {} {
1102411043
proc formatdate {d} {
1102511044
global datetimeformat
1102611045
if {$d ne {}} {
11027-
set d [clock format $d -format $datetimeformat]
11046+
set d [clock format [lindex $d 0] -format $datetimeformat]
1102811047
}
1102911048
return $d
1103011049
}
@@ -11505,14 +11524,10 @@ setui $uicolor
1150511524
setoptions
1150611525

1150711526
# check that we can find a .git directory somewhere...
11508-
if {[catch {set gitdir [gitdir]}]} {
11527+
if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
1150911528
show_error {} . [mc "Cannot find a git repository here."]
1151011529
exit 1
1151111530
}
11512-
if {![file isdirectory $gitdir]} {
11513-
show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
11514-
exit 1
11515-
}
1151611531

1151711532
set selecthead {}
1151811533
set selectheadid {}
@@ -11628,7 +11643,12 @@ set stopped 0
1162811643
set stuffsaved 0
1162911644
set patchnum 0
1163011645
set lserial 0
11631-
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
11646+
set hasworktree [hasworktree]
11647+
set cdup {}
11648+
if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
11649+
set cdup [exec git rev-parse --show-cdup]
11650+
}
11651+
set worktree [exec git rev-parse --show-toplevel]
1163211652
setcoords
1163311653
makewindow
1163411654
catch {

0 commit comments

Comments
 (0)