gitk: Speed up the reading of references

We were doing two execs for each tag - one to map the tag ID to a
commit ID and one to read the contents of the tag for later display.
This speeds up the process by not reading the contents of the tag
(instead it is read later if needed), and by using the -d flag to
git show-ref, which gives us refs/tags/foo^{} lines which give us
the commit ID.  Also this uses string operations instead of regexps.

Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
Paul Mackerras
2006-09-11 10:36:53 +10:00
parent 219ea3a99b
commit 62d3ea65a7

65
gitk
View File

@ -387,47 +387,39 @@ proc getcommit {id} {
} }
proc readrefs {} { proc readrefs {} {
global tagids idtags headids idheads tagcontents global tagids idtags headids idheads tagobjid
global otherrefids idotherrefs mainhead mainheadid global otherrefids idotherrefs mainhead mainheadid
foreach v {tagids idtags headids idheads otherrefids idotherrefs} { foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
catch {unset $v} catch {unset $v}
} }
set refd [open [list | git show-ref] r] set refd [open [list | git show-ref -d] r]
while {0 <= [set n [gets $refd line]]} { while {[gets $refd line] >= 0} {
if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \ if {[string index $line 40] ne " "} continue
match id path]} { set id [string range $line 0 39]
continue set ref [string range $line 41 end]
} if {![string match "refs/*" $ref]} continue
if {[regexp {^remotes/.*/HEAD$} $path match]} { set name [string range $ref 5 end]
continue if {[string match "remotes/*" $name]} {
} if {![string match "*/HEAD" $name]} {
if {![regexp {^(tags|heads)/(.*)$} $path match type name]} { set headids($name) $id
set type others lappend idheads($id) $name
set name $path
}
if {[regexp {^remotes/} $path match]} {
set type heads
}
if {$type == "tags"} {
set tagids($name) $id
lappend idtags($id) $name
set obj {}
set type {}
set tag {}
catch {
set commit [exec git rev-parse "$id^0"]
if {$commit != $id} {
set tagids($name) $commit
lappend idtags($commit) $name
}
}
catch {
set tagcontents($name) [exec git cat-file tag $id]
} }
} elseif { $type == "heads" } { } elseif {[string match "heads/*" $name]} {
set name [string range $name 6 end]
set headids($name) $id set headids($name) $id
lappend idheads($id) $name lappend idheads($id) $name
} elseif {[string match "tags/*" $name]} {
# this lets refs/tags/foo^{} overwrite refs/tags/foo,
# which is what we want since the former is the commit ID
set name [string range $name 5 end]
if {[string match "*^{}" $name]} {
set name [string range $name 0 end-3]
} else {
set tagobjid($name) $id
}
set tagids($name) $id
lappend idtags($id) $name
} else { } else {
set otherrefids($name) $id set otherrefids($name) $id
lappend idotherrefs($id) $name lappend idotherrefs($id) $name
@ -6777,7 +6769,7 @@ proc listrefs {id} {
} }
proc showtag {tag isnew} { proc showtag {tag isnew} {
global ctext tagcontents tagids linknum global ctext tagcontents tagids linknum tagobjid
if {$isnew} { if {$isnew} {
addtohistory [list showtag $tag 0] addtohistory [list showtag $tag 0]
@ -6785,6 +6777,11 @@ proc showtag {tag isnew} {
$ctext conf -state normal $ctext conf -state normal
clear_ctext clear_ctext
set linknum 0 set linknum 0
if {![info exists tagcontents($tag)]} {
catch {
set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
}
}
if {[info exists tagcontents($tag)]} { if {[info exists tagcontents($tag)]} {
set text $tagcontents($tag) set text $tagcontents($tag)
} else { } else {