Skip to content

Commit

Permalink
Merge git://ozlabs.org/~paulus/gitk
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Dec 17, 2011
2 parents 10f4eb6 + 811c70f commit 09bb4eb
Showing 1 changed file with 65 additions and 45 deletions.
110 changes: 65 additions & 45 deletions gitk-git/gitk
Expand Up @@ -2,20 +2,16 @@
# Tcl ignores the next line -*- tcl -*- \ # Tcl ignores the next line -*- tcl -*- \
exec wish "$0" -- "$@" exec wish "$0" -- "$@"


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


package require Tk package require Tk


proc gitdir {} { proc hasworktree {} {
global env return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
if {[info exists env(GIT_DIR)]} { [exec git rev-parse --is-inside-git-dir] == "false"}]
return $env(GIT_DIR)
} else {
return [exec git rev-parse --git-dir]
}
} }


# A simple scheduler for compute-intensive stuff. # A simple scheduler for compute-intensive stuff.
Expand Down Expand Up @@ -468,11 +464,11 @@ proc updatecommits {} {
global viewactive viewcomplete tclencoding global viewactive viewcomplete tclencoding
global startmsecs showneartags showlocalchanges global startmsecs showneartags showlocalchanges
global mainheadid viewmainheadid viewmainheadid_orig pending_select global mainheadid viewmainheadid viewmainheadid_orig pending_select
global isworktree global hasworktree
global varcid vposids vnegids vflags vrevs global varcid vposids vnegids vflags vrevs
global show_notes global show_notes


set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}] set hasworktree [hasworktree]
rereadrefs rereadrefs
set view $curview set view $curview
if {$mainheadid ne $viewmainheadid_orig($view)} { if {$mainheadid ne $viewmainheadid_orig($view)} {
Expand Down Expand Up @@ -659,7 +655,7 @@ proc newvarc {view id} {
if {![info exists commitinfo($id)]} { if {![info exists commitinfo($id)]} {
parsecommit $id $commitdata($id) 1 parsecommit $id $commitdata($id) 1
} }
set cdate [lindex $commitinfo($id) 4] set cdate [lindex [lindex $commitinfo($id) 4] 0]
if {![string is integer -strict $cdate]} { if {![string is integer -strict $cdate]} {
set cdate 0 set cdate 0
} }
Expand Down Expand Up @@ -1621,7 +1617,7 @@ proc readcommit {id} {
} }


proc parsecommit {id contents listed} { proc parsecommit {id contents listed} {
global commitinfo cdate global commitinfo


set inhdr 1 set inhdr 1
set comment {} set comment {}
Expand All @@ -1641,10 +1637,10 @@ proc parsecommit {id contents listed} {
set line [split $line " "] set line [split $line " "]
set tag [lindex $line 0] set tag [lindex $line 0]
if {$tag == "author"} { if {$tag == "author"} {
set audate [lindex $line end-1] set audate [lrange $line end-1 end]
set auname [join [lrange $line 1 end-2] " "] set auname [join [lrange $line 1 end-2] " "]
} elseif {$tag == "committer"} { } elseif {$tag == "committer"} {
set comdate [lindex $line end-1] set comdate [lrange $line end-1 end]
set comname [join [lrange $line 1 end-2] " "] set comname [join [lrange $line 1 end-2] " "]
} }
} }
Expand All @@ -1671,11 +1667,9 @@ proc parsecommit {id contents listed} {
} }
set comment $newcomment set comment $newcomment
} }
if {$comdate != {}} { set hasnote [string first "\nNotes:\n" $contents]
set cdate($id) $comdate
}
set commitinfo($id) [list $headline $auname $audate \ set commitinfo($id) [list $headline $auname $audate \
$comname $comdate $comment] $comname $comdate $comment $hasnote]
} }


proc getcommit {id} { proc getcommit {id} {
Expand Down Expand Up @@ -2437,9 +2431,9 @@ proc makewindow {} {
bindkey n "selnextline 1" bindkey n "selnextline 1"
bindkey z "goback" bindkey z "goback"
bindkey x "goforw" bindkey x "goforw"
bindkey i "selnextline -1" bindkey k "selnextline -1"
bindkey k "selnextline 1" bindkey j "selnextline 1"
bindkey j "goback" bindkey h "goback"
bindkey l "goforw" bindkey l "goforw"
bindkey b prevfile bindkey b prevfile
bindkey d "$ctext yview scroll 18 units" bindkey d "$ctext yview scroll 18 units"
Expand Down Expand Up @@ -2815,7 +2809,7 @@ proc about {} {
message $w.m -text [mc " message $w.m -text [mc "
Gitk - a commit viewer for git Gitk - a commit viewer for git
Copyright \u00a9 2005-2010 Paul Mackerras Copyright \u00a9 2005-2011 Paul Mackerras
Use and redistribute under the terms of the GNU General Public License"] \ Use and redistribute under the terms of the GNU General Public License"] \
-justify center -aspect 400 -border 2 -bg white -relief groove -justify center -aspect 400 -border 2 -bg white -relief groove
Expand Down Expand Up @@ -2850,9 +2844,9 @@ proc keys {} {
[mc "<%s-W> Close window" $M1T] [mc "<%s-W> Close window" $M1T]
[mc "<Home> Move to first commit"] [mc "<Home> Move to first commit"]
[mc "<End> Move to last commit"] [mc "<End> Move to last commit"]
[mc "<Up>, p, i Move up one commit"] [mc "<Up>, p, k Move up one commit"]
[mc "<Down>, n, k Move down one commit"] [mc "<Down>, n, j Move down one commit"]
[mc "<Left>, z, j Go back in history list"] [mc "<Left>, z, h Go back in history list"]
[mc "<Right>, x, l Go forward in history list"] [mc "<Right>, x, l Go forward in history list"]
[mc "<PageUp> Move up one page in commit list"] [mc "<PageUp> Move up one page in commit list"]
[mc "<PageDown> Move down one page in commit list"] [mc "<PageDown> Move down one page in commit list"]
Expand Down Expand Up @@ -3333,8 +3327,7 @@ proc gitknewtmpdir {} {
global diffnum gitktmpdir gitdir global diffnum gitktmpdir gitdir


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


proc external_diff_get_one_file {diffid filename diffdir} { proc external_diff_get_one_file {diffid filename diffdir} {
global nullid nullid2 nullfile global nullid nullid2 nullfile
global gitdir global worktree


if {$diffid == $nullid} { if {$diffid == $nullid} {
set difffile [file join [file dirname $gitdir] $filename] set difffile [file join $worktree $filename]
if {[file exists $difffile]} { if {[file exists $difffile]} {
return $difffile return $difffile
} }
Expand Down Expand Up @@ -3559,7 +3552,7 @@ proc make_relative {f} {
} }


proc external_blame {parent_idx {line {}}} { proc external_blame {parent_idx {line {}}} {
global flist_menu_file gitdir global flist_menu_file cdup
global nullid nullid2 global nullid nullid2
global parentlist selectedline currentid global parentlist selectedline currentid


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


set from_index {} set from_index {}
if {$cmitmode eq "tree"} { if {$cmitmode eq "tree"} {
Expand Down Expand Up @@ -3644,7 +3637,7 @@ proc show_line_source {} {
} else { } else {
lappend blameargs $id lappend blameargs $id
} }
lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file] lappend blameargs -- [file join $cdup $flist_menu_file]
if {[catch { if {[catch {
set f [open $blameargs r] set f [open $blameargs r]
} err]} { } err]} {
Expand Down Expand Up @@ -4529,12 +4522,22 @@ proc makepatterns {l} {


proc do_file_hl {serial} { proc do_file_hl {serial} {
global highlight_files filehighlight highlight_paths gdttype fhl_list global highlight_files filehighlight highlight_paths gdttype fhl_list
global cdup findtype


if {$gdttype eq [mc "touching paths:"]} { if {$gdttype eq [mc "touching paths:"]} {
# If "exact" match then convert backslashes to forward slashes.
# Most useful to support Windows-flavoured file paths.
if {$findtype eq [mc "Exact"]} {
set highlight_files [string map {"\\" "/"} $highlight_files]
}
if {[catch {set paths [shellsplit $highlight_files]}]} return if {[catch {set paths [shellsplit $highlight_files]}]} return
set highlight_paths [makepatterns $paths] set highlight_paths [makepatterns $paths]
highlight_filelist highlight_filelist
set gdtargs [concat -- $paths] set relative_paths {}
foreach path $paths {
lappend relative_paths [file join $cdup $path]
}
set gdtargs [concat -- $relative_paths]
} elseif {$gdttype eq [mc "adding/removing string:"]} { } elseif {$gdttype eq [mc "adding/removing string:"]} {
set gdtargs [list "-S$highlight_files"] set gdtargs [list "-S$highlight_files"]
} else { } else {
Expand Down Expand Up @@ -5031,9 +5034,9 @@ proc dohidelocalchanges {} {
# spawn off a process to do git diff-index --cached HEAD # spawn off a process to do git diff-index --cached HEAD
proc dodiffindex {} { proc dodiffindex {} {
global lserial showlocalchanges vfilelimit curview global lserial showlocalchanges vfilelimit curview
global isworktree global hasworktree


if {!$showlocalchanges || !$isworktree} return if {!$showlocalchanges || !$hasworktree} return
incr lserial incr lserial
set cmd "|git diff-index --cached HEAD" set cmd "|git diff-index --cached HEAD"
if {$vfilelimit($curview) ne {}} { if {$vfilelimit($curview) ne {}} {
Expand Down Expand Up @@ -5899,6 +5902,9 @@ proc drawcmittext {id row col} {
|| [info exists idotherrefs($id)]} { || [info exists idotherrefs($id)]} {
set xt [drawtags $id $x $xt $y] set xt [drawtags $id $x $xt $y]
} }
if {[lindex $commitinfo($id) 6] > 0} {
set xt [drawnotesign $xt $y]
}
set headline [lindex $commitinfo($id) 0] set headline [lindex $commitinfo($id) 0]
set name [lindex $commitinfo($id) 1] set name [lindex $commitinfo($id) 1]
set date [lindex $commitinfo($id) 2] set date [lindex $commitinfo($id) 2]
Expand Down Expand Up @@ -6345,6 +6351,17 @@ proc drawtags {id x xt y1} {
return $xt return $xt
} }


proc drawnotesign {xt y} {
global linespc canv fgcolor

set orad [expr {$linespc / 3}]
set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
[expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
-fill yellow -outline $fgcolor -width 1 -tags circle]
set xt [expr {$xt + $orad * 3}]
return $xt
}

proc xcoord {i level ln} { proc xcoord {i level ln} {
global canvx0 xspc1 xspc2 global canvx0 xspc1 xspc2


Expand Down Expand Up @@ -9043,6 +9060,7 @@ proc exec_citool {tool_args {baseid {}}} {
proc cherrypick {} { proc cherrypick {} {
global rowmenuid curview global rowmenuid curview
global mainhead mainheadid global mainhead mainheadid
global gitdir


set oldhead [exec git rev-parse HEAD] set oldhead [exec git rev-parse HEAD]
set dheads [descheads $rowmenuid] set dheads [descheads $rowmenuid]
Expand Down Expand Up @@ -9071,7 +9089,7 @@ proc cherrypick {} {
conflict.\nDo you wish to run git citool to\ conflict.\nDo you wish to run git citool to\
resolve it?"]]} { resolve it?"]]} {
# Force citool to read MERGE_MSG # Force citool to read MERGE_MSG
file delete [file join [gitdir] "GITGUI_MSG"] file delete [file join $gitdir "GITGUI_MSG"]
exec_citool {} $rowmenuid exec_citool {} $rowmenuid
} }
} else { } else {
Expand Down Expand Up @@ -9437,14 +9455,15 @@ proc refill_reflist {} {
proc getallcommits {} { proc getallcommits {} {
global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
global idheads idtags idotherrefs allparents tagobjid global idheads idtags idotherrefs allparents tagobjid
global gitdir


if {![info exists allcommits]} { if {![info exists allcommits]} {
set nextarc 0 set nextarc 0
set allcommits 0 set allcommits 0
set seeds {} set seeds {}
set allcwait 0 set allcwait 0
set cachedarcs 0 set cachedarcs 0
set allccache [file join [gitdir] "gitk.cache"] set allccache [file join $gitdir "gitk.cache"]
if {![catch { if {![catch {
set f [open $allccache r] set f [open $allccache r]
set allcwait 1 set allcwait 1
Expand Down Expand Up @@ -11024,7 +11043,7 @@ proc prefsok {} {
proc formatdate {d} { proc formatdate {d} {
global datetimeformat global datetimeformat
if {$d ne {}} { if {$d ne {}} {
set d [clock format $d -format $datetimeformat] set d [clock format [lindex $d 0] -format $datetimeformat]
} }
return $d return $d
} }
Expand Down Expand Up @@ -11505,14 +11524,10 @@ setui $uicolor
setoptions setoptions


# check that we can find a .git directory somewhere... # check that we can find a .git directory somewhere...
if {[catch {set gitdir [gitdir]}]} { if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
show_error {} . [mc "Cannot find a git repository here."] show_error {} . [mc "Cannot find a git repository here."]
exit 1 exit 1
} }
if {![file isdirectory $gitdir]} {
show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
exit 1
}


set selecthead {} set selecthead {}
set selectheadid {} set selectheadid {}
Expand Down Expand Up @@ -11628,7 +11643,12 @@ set stopped 0
set stuffsaved 0 set stuffsaved 0
set patchnum 0 set patchnum 0
set lserial 0 set lserial 0
set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}] set hasworktree [hasworktree]
set cdup {}
if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
set cdup [exec git rev-parse --show-cdup]
}
set worktree [exec git rev-parse --show-toplevel]
setcoords setcoords
makewindow makewindow
catch { catch {
Expand Down

0 comments on commit 09bb4eb

Please sign in to comment.