2
2
# Tcl ignores the next line -*- tcl -*- \
3
3
exec wish "$0" -- "$@"
4
4
5
- # Copyright © 2005-2009 Paul Mackerras. All rights reserved.
5
+ # Copyright © 2005-2011 Paul Mackerras. All rights reserved.
6
6
# This program is free software; it may be used, copied, modified
7
7
# and distributed under the terms of the GNU General Public Licence,
8
8
# either version 2, or (at your option) any later version.
9
9
10
10
package require Tk
11
11
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" }]
19
15
}
20
16
21
17
# A simple scheduler for compute-intensive stuff.
@@ -468,11 +464,11 @@ proc updatecommits {} {
468
464
global viewactive viewcomplete tclencoding
469
465
global startmsecs showneartags showlocalchanges
470
466
global mainheadid viewmainheadid viewmainheadid_orig pending_select
471
- global isworktree
467
+ global hasworktree
472
468
global varcid vposids vnegids vflags vrevs
473
469
global show_notes
474
470
475
- set isworktree [ expr {[ exec git rev-parse --is-inside-work-tree] == " true " } ]
471
+ set hasworktree [hasworktree ]
476
472
rereadrefs
477
473
set view $curview
478
474
if {$mainheadid ne $viewmainheadid_orig($view) } {
@@ -659,7 +655,7 @@ proc newvarc {view id} {
659
655
if {![info exists commitinfo($id )]} {
660
656
parsecommit $id $commitdata($id) 1
661
657
}
662
- set cdate [lindex $commitinfo($id) 4]
658
+ set cdate [lindex [ lindex $commitinfo($id) 4] 0 ]
663
659
if {![string is integer -strict $cdate ]} {
664
660
set cdate 0
665
661
}
@@ -1621,7 +1617,7 @@ proc readcommit {id} {
1621
1617
}
1622
1618
1623
1619
proc parsecommit {id contents listed} {
1624
- global commitinfo cdate
1620
+ global commitinfo
1625
1621
1626
1622
set inhdr 1
1627
1623
set comment {}
@@ -1641,10 +1637,10 @@ proc parsecommit {id contents listed} {
1641
1637
set line [split $line " " ]
1642
1638
set tag [lindex $line 0]
1643
1639
if {$tag == " author" } {
1644
- set audate [lindex $line end-1]
1640
+ set audate [lrange $line end-1 end ]
1645
1641
set auname [join [lrange $line 1 end-2] " " ]
1646
1642
} elseif {$tag == " committer" } {
1647
- set comdate [lindex $line end-1]
1643
+ set comdate [lrange $line end-1 end ]
1648
1644
set comname [join [lrange $line 1 end-2] " " ]
1649
1645
}
1650
1646
}
@@ -1671,11 +1667,9 @@ proc parsecommit {id contents listed} {
1671
1667
}
1672
1668
set comment $newcomment
1673
1669
}
1674
- if {$comdate != {}} {
1675
- set cdate($id ) $comdate
1676
- }
1670
+ set hasnote [string first " \n Notes:\n " $contents ]
1677
1671
set commitinfo($id ) [list $headline $auname $audate \
1678
- $comname $comdate $comment ]
1672
+ $comname $comdate $comment $hasnote ]
1679
1673
}
1680
1674
1681
1675
proc getcommit {id} {
@@ -2437,9 +2431,9 @@ proc makewindow {} {
2437
2431
bindkey n " selnextline 1"
2438
2432
bindkey z " goback"
2439
2433
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"
2443
2437
bindkey l " goforw"
2444
2438
bindkey b prevfile
2445
2439
bindkey d " $ctext yview scroll 18 units"
@@ -2815,7 +2809,7 @@ proc about {} {
2815
2809
message $w .m -text [mc "
2816
2810
Gitk - a commit viewer for git
2817
2811
2818
- Copyright \u00a9 2005-2010 Paul Mackerras
2812
+ Copyright \u00a9 2005-2011 Paul Mackerras
2819
2813
2820
2814
Use and redistribute under the terms of the GNU General Public License" ] \
2821
2815
-justify center -aspect 400 -border 2 -bg white -relief groove
@@ -2850,9 +2844,9 @@ proc keys {} {
2850
2844
[ mc " <%s-W> Close window" $M1T ]
2851
2845
[ mc " <Home> Move to first commit" ]
2852
2846
[ 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" ]
2856
2850
[ mc " <Right>, x, l Go forward in history list" ]
2857
2851
[ mc " <PageUp> Move up one page in commit list" ]
2858
2852
[ mc " <PageDown> Move down one page in commit list" ]
@@ -3333,8 +3327,7 @@ proc gitknewtmpdir {} {
3333
3327
global diffnum gitktmpdir gitdir
3334
3328
3335
3329
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 ]]]
3338
3331
if {[catch {file mkdir $gitktmpdir } err]} {
3339
3332
error_popup " [ mc " Error creating temporary directory %s:" $gitktmpdir ] $err "
3340
3333
unset gitktmpdir
@@ -3366,10 +3359,10 @@ proc save_file_from_commit {filename output what} {
3366
3359
3367
3360
proc external_diff_get_one_file {diffid filename diffdir} {
3368
3361
global nullid nullid2 nullfile
3369
- global gitdir
3362
+ global worktree
3370
3363
3371
3364
if {$diffid == $nullid } {
3372
- set difffile [file join [ file dirname $gitdir ] $filename ]
3365
+ set difffile [file join $worktree $filename ]
3373
3366
if {[file exists $difffile ]} {
3374
3367
return $difffile
3375
3368
}
@@ -3559,7 +3552,7 @@ proc make_relative {f} {
3559
3552
}
3560
3553
3561
3554
proc external_blame {parent_idx {line {}}} {
3562
- global flist_menu_file gitdir
3555
+ global flist_menu_file cdup
3563
3556
global nullid nullid2
3564
3557
global parentlist selectedline currentid
3565
3558
@@ -3578,7 +3571,7 @@ proc external_blame {parent_idx {line {}}} {
3578
3571
if {$line ne {} && $line > 1} {
3579
3572
lappend cmdline " --line=$line "
3580
3573
}
3581
- set f [file join [ file dirname $gitdir ] $flist_menu_file ]
3574
+ set f [file join $cdup $flist_menu_file ]
3582
3575
# Unfortunately it seems git gui blame doesn't like
3583
3576
# being given an absolute path...
3584
3577
set f [make_relative $f ]
@@ -3591,7 +3584,7 @@ proc external_blame {parent_idx {line {}}} {
3591
3584
proc show_line_source {} {
3592
3585
global cmitmode currentid parents curview blamestuff blameinst
3593
3586
global diff_menu_line diff_menu_filebase flist_menu_file
3594
- global nullid nullid2 gitdir
3587
+ global nullid nullid2 gitdir cdup
3595
3588
3596
3589
set from_index {}
3597
3590
if {$cmitmode eq " tree" } {
@@ -3644,7 +3637,7 @@ proc show_line_source {} {
3644
3637
} else {
3645
3638
lappend blameargs $id
3646
3639
}
3647
- lappend blameargs -- [file join [ file dirname $gitdir ] $flist_menu_file ]
3640
+ lappend blameargs -- [file join $cdup $flist_menu_file ]
3648
3641
if {[catch {
3649
3642
set f [open $blameargs r]
3650
3643
} err]} {
@@ -4529,12 +4522,22 @@ proc makepatterns {l} {
4529
4522
4530
4523
proc do_file_hl {serial} {
4531
4524
global highlight_files filehighlight highlight_paths gdttype fhl_list
4525
+ global cdup findtype
4532
4526
4533
4527
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
+ }
4534
4533
if {[catch {set paths [shellsplit $highlight_files ]}]} return
4535
4534
set highlight_paths [makepatterns $paths ]
4536
4535
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 ]
4538
4541
} elseif {$gdttype eq [mc " adding/removing string:" ]} {
4539
4542
set gdtargs [list " -S$highlight_files " ]
4540
4543
} else {
@@ -5031,9 +5034,9 @@ proc dohidelocalchanges {} {
5031
5034
# spawn off a process to do git diff-index --cached HEAD
5032
5035
proc dodiffindex {} {
5033
5036
global lserial showlocalchanges vfilelimit curview
5034
- global isworktree
5037
+ global hasworktree
5035
5038
5036
- if {!$showlocalchanges || !$isworktree } return
5039
+ if {!$showlocalchanges || !$hasworktree } return
5037
5040
incr lserial
5038
5041
set cmd " |git diff-index --cached HEAD"
5039
5042
if {$vfilelimit($curview) ne {}} {
@@ -5899,6 +5902,9 @@ proc drawcmittext {id row col} {
5899
5902
|| [info exists idotherrefs($id )]} {
5900
5903
set xt [drawtags $id $x $xt $y ]
5901
5904
}
5905
+ if {[lindex $commitinfo($id) 6] > 0} {
5906
+ set xt [drawnotesign $xt $y ]
5907
+ }
5902
5908
set headline [lindex $commitinfo($id) 0]
5903
5909
set name [lindex $commitinfo($id) 1]
5904
5910
set date [lindex $commitinfo($id) 2]
@@ -6345,6 +6351,17 @@ proc drawtags {id x xt y1} {
6345
6351
return $xt
6346
6352
}
6347
6353
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
+
6348
6365
proc xcoord {i level ln} {
6349
6366
global canvx0 xspc1 xspc2
6350
6367
@@ -9043,6 +9060,7 @@ proc exec_citool {tool_args {baseid {}}} {
9043
9060
proc cherrypick {} {
9044
9061
global rowmenuid curview
9045
9062
global mainhead mainheadid
9063
+ global gitdir
9046
9064
9047
9065
set oldhead [exec git rev-parse HEAD]
9048
9066
set dheads [descheads $rowmenuid ]
@@ -9071,7 +9089,7 @@ proc cherrypick {} {
9071
9089
conflict.\n Do you wish to run git citool to\
9072
9090
resolve it?" ]]} {
9073
9091
# Force citool to read MERGE_MSG
9074
- file delete [file join [ gitdir] " GITGUI_MSG" ]
9092
+ file delete [file join $ gitdir " GITGUI_MSG" ]
9075
9093
exec_citool {} $rowmenuid
9076
9094
}
9077
9095
} else {
@@ -9437,14 +9455,15 @@ proc refill_reflist {} {
9437
9455
proc getallcommits {} {
9438
9456
global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9439
9457
global idheads idtags idotherrefs allparents tagobjid
9458
+ global gitdir
9440
9459
9441
9460
if {![info exists allcommits]} {
9442
9461
set nextarc 0
9443
9462
set allcommits 0
9444
9463
set seeds {}
9445
9464
set allcwait 0
9446
9465
set cachedarcs 0
9447
- set allccache [file join [ gitdir] " gitk.cache" ]
9466
+ set allccache [file join $ gitdir " gitk.cache" ]
9448
9467
if {![catch {
9449
9468
set f [open $allccache r]
9450
9469
set allcwait 1
@@ -11024,7 +11043,7 @@ proc prefsok {} {
11024
11043
proc formatdate {d} {
11025
11044
global datetimeformat
11026
11045
if {$d ne {}} {
11027
- set d [clock format $d -format $datetimeformat ]
11046
+ set d [clock format [ lindex $d 0] -format $datetimeformat ]
11028
11047
}
11029
11048
return $d
11030
11049
}
@@ -11505,14 +11524,10 @@ setui $uicolor
11505
11524
setoptions
11506
11525
11507
11526
# 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 ]}]} {
11509
11528
show_error {} . [mc " Cannot find a git repository here." ]
11510
11529
exit 1
11511
11530
}
11512
- if {![file isdirectory $gitdir ]} {
11513
- show_error {} . [mc " Cannot find the git directory \" %s\" ." $gitdir ]
11514
- exit 1
11515
- }
11516
11531
11517
11532
set selecthead {}
11518
11533
set selectheadid {}
@@ -11628,7 +11643,12 @@ set stopped 0
11628
11643
set stuffsaved 0
11629
11644
set patchnum 0
11630
11645
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]
11632
11652
setcoords
11633
11653
makewindow
11634
11654
catch {
0 commit comments