Skip to content

Commit

Permalink
gitk: Speed up the reading of references
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Paul Mackerras committed Jun 23, 2007
1 parent 219ea3a commit 62d3ea6
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -387,47 +387,39 @@ proc getcommit {id} {
}

proc readrefs {} {
global tagids idtags headids idheads tagcontents
global tagids idtags headids idheads tagobjid
global otherrefids idotherrefs mainhead mainheadid

foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
catch {unset $v}
}
set refd [open [list | git show-ref] r]
while {0 <= [set n [gets $refd line]]} {
if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
match id path]} {
continue
}
if {[regexp {^remotes/.*/HEAD$} $path match]} {
continue
}
if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
set type others
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]
set refd [open [list | git show-ref -d] r]
while {[gets $refd line] >= 0} {
if {[string index $line 40] ne " "} continue
set id [string range $line 0 39]
set ref [string range $line 41 end]
if {![string match "refs/*" $ref]} continue
set name [string range $ref 5 end]
if {[string match "remotes/*" $name]} {
if {![string match "*/HEAD" $name]} {
set headids($name) $id
lappend idheads($id) $name
}
} elseif { $type == "heads" } {
} elseif {[string match "heads/*" $name]} {
set name [string range $name 6 end]
set headids($name) $id
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 {
set otherrefids($name) $id
lappend idotherrefs($id) $name
Expand Down Expand Up @@ -6777,14 +6769,19 @@ proc listrefs {id} {
}

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

if {$isnew} {
addtohistory [list showtag $tag 0]
}
$ctext conf -state normal
clear_ctext
set linknum 0
if {![info exists tagcontents($tag)]} {
catch {
set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
}
}
if {[info exists tagcontents($tag)]} {
set text $tagcontents($tag)
} else {
Expand Down

0 comments on commit 62d3ea6

Please sign in to comment.