Merge git://ozlabs.org/~paulus/gitk

* git://ozlabs.org/~paulus/gitk:
  gitk: Recognize -L option
  gitk: Support showing the gathered inline diffs
  gitk: Split out diff part in $commitinfo
  gitk: Refactor per-line part of getblobdiffline and its support
  gitk: Support -G option from the command line
  gitk: Tag display improvements
maint
Junio C Hamano 2013-12-09 14:55:41 -08:00
commit ec418bcfd0
1 changed files with 371 additions and 228 deletions

View File

@ -156,10 +156,12 @@ proc unmerged_files {files} {


proc parseviewargs {n arglist} { proc parseviewargs {n arglist} {
global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
global vinlinediff
global worddiff git_version global worddiff git_version


set vdatemode($n) 0 set vdatemode($n) 0
set vmergeonly($n) 0 set vmergeonly($n) 0
set vinlinediff($n) 0
set glflags {} set glflags {}
set diffargs {} set diffargs {}
set nextisval 0 set nextisval 0
@ -227,12 +229,20 @@ proc parseviewargs {n arglist} {
"--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
"--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
"--remove-empty" - "--first-parent" - "--cherry-pick" - "--remove-empty" - "--first-parent" - "--cherry-pick" -
"-S*" - "--pickaxe-all" - "--pickaxe-regex" - "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
"--simplify-by-decoration" { "--simplify-by-decoration" {
# These mean that we get a subset of the commits # These mean that we get a subset of the commits
set filtered 1 set filtered 1
lappend glflags $arg lappend glflags $arg
} }
"-L*" {
# Line-log with 'stuck' argument (unstuck form is
# not supported)
set filtered 1
set vinlinediff($n) 1
set allknown 0
lappend glflags $arg
}
"-n" { "-n" {
# This appears to be the only one that has a value as a # This appears to be the only one that has a value as a
# separate word following it # separate word following it
@ -1704,8 +1714,17 @@ proc parsecommit {id contents listed} {
set comment $newcomment set comment $newcomment
} }
set hasnote [string first "\nNotes:\n" $contents] set hasnote [string first "\nNotes:\n" $contents]
set diff ""
# If there is diff output shown in the git-log stream, split it
# out. But get rid of the empty line that always precedes the
# diff.
set i [string first "\n\ndiff" $comment]
if {$i >= 0} {
set diff [string range $comment $i+1 end]
set comment [string range $comment 0 $i-1]
}
set commitinfo($id) [list $headline $auname $audate \ set commitinfo($id) [list $headline $auname $audate \
$comname $comdate $comment $hasnote] $comname $comdate $comment $hasnote $diff]
} }


proc getcommit {id} { proc getcommit {id} {
@ -2385,6 +2404,7 @@ proc makewindow {} {
$ctext tag conf found -back $foundbgcolor $ctext tag conf found -back $foundbgcolor
$ctext tag conf currentsearchhit -back $currentsearchhitbgcolor $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
$ctext tag conf wwrap -wrap word $ctext tag conf wwrap -wrap word
$ctext tag conf bold -font textfontbold


.pwbottom add .bleft .pwbottom add .bleft
if {!$use_ttk} { if {!$use_ttk} {
@ -6387,6 +6407,25 @@ proc bindline {t id} {
$canv bind $t <Button-1> "lineclick %x %y $id 1" $canv bind $t <Button-1> "lineclick %x %y $id 1"
} }


proc graph_pane_width {} {
global use_ttk

if {$use_ttk} {
set g [.tf.histframe.pwclist sashpos 0]
} else {
set g [.tf.histframe.pwclist sash coord 0]
}
return [lindex $g 0]
}

proc totalwidth {l font extra} {
set tot 0
foreach str $l {
set tot [expr {$tot + [font measure $font $str] + $extra}]
}
return $tot
}

proc drawtags {id x xt y1} { proc drawtags {id x xt y1} {
global idtags idheads idotherrefs mainhead global idtags idheads idotherrefs mainhead
global linespc lthickness global linespc lthickness
@ -6398,9 +6437,27 @@ proc drawtags {id x xt y1} {
set marks {} set marks {}
set ntags 0 set ntags 0
set nheads 0 set nheads 0
set singletag 0
set maxtags 3
set maxtagpct 25
set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
set delta [expr {int(0.5 * ($linespc - $lthickness))}]
set extra [expr {$delta + $lthickness + $linespc}]

if {[info exists idtags($id)]} { if {[info exists idtags($id)]} {
set marks $idtags($id) set marks $idtags($id)
set ntags [llength $marks] set ntags [llength $marks]
if {$ntags > $maxtags ||
[totalwidth $marks mainfont $extra] > $maxwidth} {
# show just a single "n tags..." tag
set singletag 1
if {$ntags == 1} {
set marks [list "tag..."]
} else {
set marks [list [format "%d tags..." $ntags]]
}
set ntags 1
}
} }
if {[info exists idheads($id)]} { if {[info exists idheads($id)]} {
set marks [concat $marks $idheads($id)] set marks [concat $marks $idheads($id)]
@ -6413,7 +6470,6 @@ proc drawtags {id x xt y1} {
return $xt return $xt
} }


set delta [expr {int(0.5 * ($linespc - $lthickness))}]
set yt [expr {$y1 - 0.5 * $linespc}] set yt [expr {$y1 - 0.5 * $linespc}]
set yb [expr {$yt + $linespc - 1}] set yb [expr {$yt + $linespc - 1}]
set xvals {} set xvals {}
@ -6428,7 +6484,7 @@ proc drawtags {id x xt y1} {
} }
lappend xvals $xt lappend xvals $xt
lappend wvals $wid lappend wvals $wid
set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}] set xt [expr {$xt + $wid + $extra}]
} }
set t [$canv create line $x $y1 [lindex $xvals end] $y1 \ set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
-width $lthickness -fill $reflinecolor -tags tag.$id] -width $lthickness -fill $reflinecolor -tags tag.$id]
@ -6444,7 +6500,12 @@ proc drawtags {id x xt y1} {
$xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \ $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
-width 1 -outline $tagoutlinecolor -fill $tagbgcolor \ -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
-tags tag.$id] -tags tag.$id]
$canv bind $t <1> [list showtag $tag_quoted 1] if {$singletag} {
set tagclick [list showtags $id 1]
} else {
set tagclick [list showtag $tag_quoted 1]
}
$canv bind $t <1> $tagclick
set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}] set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
} else { } else {
# draw a head or other ref # draw a head or other ref
@ -6471,7 +6532,7 @@ proc drawtags {id x xt y1} {
set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \ set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
-font $font -tags [list tag.$id text]] -font $font -tags [list tag.$id text]]
if {$ntags >= 0} { if {$ntags >= 0} {
$canv bind $t <1> [list showtag $tag_quoted 1] $canv bind $t <1> $tagclick
} elseif {$nheads >= 0} { } elseif {$nheads >= 0} {
$canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted] $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
} }
@ -7080,6 +7141,7 @@ proc selectline {l isnew {desired_loc {}}} {
global cmitmode showneartags allcommits global cmitmode showneartags allcommits
global targetrow targetid lastscrollrows global targetrow targetid lastscrollrows
global autoselect autosellen jump_to_here global autoselect autosellen jump_to_here
global vinlinediff


catch {unset pending_select} catch {unset pending_select}
$canv delete hover $canv delete hover
@ -7221,6 +7283,8 @@ proc selectline {l isnew {desired_loc {}}} {
init_flist [mc "Comments"] init_flist [mc "Comments"]
if {$cmitmode eq "tree"} { if {$cmitmode eq "tree"} {
gettree $id gettree $id
} elseif {$vinlinediff($curview) == 1} {
showinlinediff $id
} elseif {[llength $olds] <= 1} { } elseif {[llength $olds] <= 1} {
startdiff $id startdiff $id
} else { } else {
@ -7557,6 +7621,39 @@ proc startdiff {ids} {
} }
} }


proc showinlinediff {ids} {
global commitinfo commitdata ctext
global treediffs

set info $commitinfo($ids)
set diff [lindex $info 7]
set difflines [split $diff "\n"]

initblobdiffvars
set treediff {}

set inhdr 0
foreach line $difflines {
if {![string compare -length 5 "diff " $line]} {
set inhdr 1
} elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
# offset also accounts for the b/ prefix
lappend treediff [string range $line 6 end]
set inhdr 0
}
}

set treediffs($ids) $treediff
add_flist $treediff

$ctext conf -state normal
foreach line $difflines {
parseblobdiffline $ids $line
}
maybe_scroll_ctext 1
$ctext conf -state disabled
}

# If the filename (name) is under any of the passed filter paths # If the filename (name) is under any of the passed filter paths
# then return true to include the file in the listing. # then return true to include the file in the listing.
proc path_filter {filter name} { proc path_filter {filter name} {
@ -7710,15 +7807,25 @@ proc changeworddiff {name ix op} {
reselectline reselectline
} }


proc initblobdiffvars {} {
global diffencoding targetline diffnparents
global diffinhdr currdiffsubmod diffseehere
set targetline {}
set diffnparents 0
set diffinhdr 0
set diffencoding [get_path_encoding {}]
set currdiffsubmod ""
set diffseehere -1
}

proc getblobdiffs {ids} { proc getblobdiffs {ids} {
global blobdifffd diffids env global blobdifffd diffids env
global diffinhdr treediffs global treediffs
global diffcontext global diffcontext
global ignorespace global ignorespace
global worddiff global worddiff
global limitdiffs vfilelimit curview global limitdiffs vfilelimit curview
global diffencoding targetline diffnparents global git_version
global git_version currdiffsubmod


set textconv {} set textconv {}
if {[package vcompare $git_version "1.6.1"] >= 0} { if {[package vcompare $git_version "1.6.1"] >= 0} {
@ -7742,13 +7849,9 @@ proc getblobdiffs {ids} {
error_popup [mc "Error getting diffs: %s" $err] error_popup [mc "Error getting diffs: %s" $err]
return return
} }
set targetline {}
set diffnparents 0
set diffinhdr 0
set diffencoding [get_path_encoding {}]
fconfigure $bdf -blocking 0 -encoding binary -eofchar {} fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
set blobdifffd($ids) $bdf set blobdifffd($ids) $bdf
set currdiffsubmod "" initblobdiffvars
filerun $bdf [list getblobdiffline $bdf $diffids] filerun $bdf [list getblobdiffline $bdf $diffids]
} }


@ -7814,13 +7917,17 @@ proc makediffhdr {fname ids} {
set diffline 0 set diffline 0
} }


proc blobdiffmaybeseehere {ateof} {
global diffseehere
if {$diffseehere >= 0} {
mark_ctext_line [lindex [split $diffseehere .] 0]
}
maybe_scroll_ctext ateof
}

proc getblobdiffline {bdf ids} { proc getblobdiffline {bdf ids} {
global diffids blobdifffd ctext curdiffstart global diffids blobdifffd
global diffnexthead diffnextnote difffilestart global ctext
global ctext_file_names ctext_file_lines
global diffinhdr treediffs mergemax diffnparents
global diffencoding jump_to_here targetline diffline currdiffsubmod
global worddiff


set nr 0 set nr 0
$ctext conf -state normal $ctext conf -state normal
@ -7829,6 +7936,25 @@ proc getblobdiffline {bdf ids} {
catch {close $bdf} catch {close $bdf}
return 0 return 0
} }
parseblobdiffline $ids $line
}
$ctext conf -state disabled
blobdiffmaybeseehere [eof $bdf]
if {[eof $bdf]} {
catch {close $bdf}
return 0
}
return [expr {$nr >= 1000? 2: 1}]
}

proc parseblobdiffline {ids line} {
global ctext curdiffstart
global diffnexthead diffnextnote difffilestart
global ctext_file_names ctext_file_lines
global diffinhdr treediffs mergemax diffnparents
global diffencoding jump_to_here targetline diffline currdiffsubmod
global worddiff diffseehere

if {![string compare -length 5 "diff " $line]} { if {![string compare -length 5 "diff " $line]} {
if {![regexp {^diff (--cc|--git) } $line m type]} { if {![regexp {^diff (--cc|--git) } $line m type]} {
set line [encoding convertfrom $line] set line [encoding convertfrom $line]
@ -7866,7 +7992,7 @@ proc getblobdiffline {bdf ids} {
if {!(($l & 1) && [string index $line $i] eq " " && if {!(($l & 1) && [string index $line $i] eq " " &&
[string range $line 2 [expr {$i - 1}]] eq \ [string range $line 2 [expr {$i - 1}]] eq \
[string range $line [expr {$i + 3}] end])} { [string range $line [expr {$i + 3}] end])} {
continue return
} }
# unescape if quoted and chop off the a/ from the front # unescape if quoted and chop off the a/ from the front
if {[string index $line 0] eq "\""} { if {[string index $line 0] eq "\""} {
@ -7947,10 +8073,10 @@ proc getblobdiffline {bdf ids} {
makediffhdr $fname $ids makediffhdr $fname $ids
} elseif {[string compare -length 3 $line "---"] == 0} { } elseif {[string compare -length 3 $line "---"] == 0} {
# do nothing # do nothing
continue return
} elseif {[string compare -length 3 $line "+++"] == 0} { } elseif {[string compare -length 3 $line "+++"] == 0} {
set diffinhdr 0 set diffinhdr 0
continue return
} }
$ctext insert end "$line\n" filesep $ctext insert end "$line\n" filesep


@ -8001,7 +8127,7 @@ proc getblobdiffline {bdf ids} {
} }
if {$targetline ne {}} { if {$targetline ne {}} {
if {$diffline == $targetline} { if {$diffline == $targetline} {
set seehere [$ctext index "end - 1 chars"] set diffseehere [$ctext index "end - 1 chars"]
set targetline {} set targetline {}
} else { } else {
incr diffline incr diffline
@ -8025,17 +8151,6 @@ proc getblobdiffline {bdf ids} {
} }
} }
} }
if {[info exists seehere]} {
mark_ctext_line [lindex [split $seehere .] 0]
}
maybe_scroll_ctext [eof $bdf]
$ctext conf -state disabled
if {[eof $bdf]} {
catch {close $bdf}
return 0
}
return [expr {$nr >= 1000? 2: 1}]
}


proc changediffdisp {} { proc changediffdisp {} {
global ctext diffelide global ctext diffelide
@ -10878,6 +10993,23 @@ proc listrefs {id} {
return [list $x $y $z] return [list $x $y $z]
} }


proc add_tag_ctext {tag} {
global ctext cached_tagcontent tagids

if {![info exists cached_tagcontent($tag)]} {
catch {
set cached_tagcontent($tag) [exec git cat-file -p $tag]
}
}
$ctext insert end "[mc "Tag"]: $tag\n" bold
if {[info exists cached_tagcontent($tag)]} {
set text $cached_tagcontent($tag)
} else {
set text "[mc "Id"]: $tagids($tag)"
}
appendwithlinks $text {}
}

proc showtag {tag isnew} { proc showtag {tag isnew} {
global ctext cached_tagcontent tagids linknum tagobjid global ctext cached_tagcontent tagids linknum tagobjid


@ -10888,17 +11020,28 @@ proc showtag {tag isnew} {
clear_ctext clear_ctext
settabs 0 settabs 0
set linknum 0 set linknum 0
if {![info exists cached_tagcontent($tag)]} { add_tag_ctext $tag
catch { maybe_scroll_ctext 1
set cached_tagcontent($tag) [exec git cat-file -p $tag] $ctext conf -state disabled
init_flist {}
} }

proc showtags {id isnew} {
global idtags ctext linknum

if {$isnew} {
addtohistory [list showtags $id 0] savectextpos
} }
if {[info exists cached_tagcontent($tag)]} { $ctext conf -state normal
set text $cached_tagcontent($tag) clear_ctext
} else { settabs 0
set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)" set linknum 0
set sep {}
foreach tag $idtags($id) {
$ctext insert end $sep
add_tag_ctext $tag
set sep "\n\n"
} }
appendwithlinks $text {}
maybe_scroll_ctext 1 maybe_scroll_ctext 1
$ctext conf -state disabled $ctext conf -state disabled
init_flist {} init_flist {}