readrefs: grab all refs with one call to ls-remote.

Instead of reading refs/heads/* and refs/tags/* files ourselves
and missing files in subdirectories of heads/ and tags/, use
ls-remote on local repository and grab all of them.  This lets us
also remove the procedure readotherrefs.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano
2005-11-18 23:54:17 -08:00
parent 232475d382
commit 36a7cad6e4

84
gitk
View File

@ -238,77 +238,43 @@ proc parsecommit {id contents listed olds} {
proc readrefs {} { proc readrefs {} {
global tagids idtags headids idheads tagcontents global tagids idtags headids idheads tagcontents
global otherrefids idotherrefs
set tags [glob -nocomplain -types f [gitdir]/refs/tags/*] set refd [open [list | git-ls-remote [gitdir]] r]
foreach f $tags { while {0 <= [set n [gets $refd line]]} {
catch { if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
set fd [open $f r] match id path]} {
set line [read $fd] continue
if {[regexp {^[0-9a-f]{40}} $line id]} { }
set direct [file tail $f] if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
set tagids($direct) $id set type others
lappend idtags($id) $direct set name $path
set tagblob [exec git-cat-file tag $id] }
set contents [split $tagblob "\n"] if {$type == "tags"} {
set tagids($name) $id
lappend idtags($id) $name
set obj {} set obj {}
set type {} set type {}
set tag {} set tag {}
foreach l $contents {
if {$l == {}} break
switch -- [lindex $l 0] {
"object" {set obj [lindex $l 1]}
"type" {set type [lindex $l 1]}
"tag" {set tag [string range $l 4 end]}
}
}
if {$obj != {} && $type == "commit" && $tag != {}} {
set tagids($tag) $obj
lappend idtags($obj) $tag
set tagcontents($tag) $tagblob
}
}
close $fd
}
}
set heads [glob -nocomplain -types f [gitdir]/refs/heads/*]
foreach f $heads {
catch { catch {
set fd [open $f r] set commit [exec git-rev-parse "$id^0"]
set line [read $fd 40] if {"$commit" != "$id"} {
if {[regexp {^[0-9a-f]{40}} $line id]} { set tagids($name) $commit
set head [file tail $f] lappend idtags($commit) $name
set headids($head) $line
lappend idheads($line) $head
}
close $fd
} }
} }
readotherrefs refs {} {tags heads}
}
proc readotherrefs {base dname excl} {
global otherrefids idotherrefs
set git [gitdir]
set files [glob -nocomplain -types f [file join $git $base *]]
foreach f $files {
catch { catch {
set fd [open $f r] set tagcontents($name) [exec git-cat-file tag "$id"]
set line [read $fd 40] }
if {[regexp {^[0-9a-f]{40}} $line id]} { } elseif { $type == "heads" } {
set name "$dname[file tail $f]" set headids($name) $id
lappend idheads($id) $name
} else {
set otherrefids($name) $id set otherrefids($name) $id
lappend idotherrefs($id) $name lappend idotherrefs($id) $name
} }
close $fd
}
}
set dirs [glob -nocomplain -types d [file join $git $base *]]
foreach d $dirs {
set dir [file tail $d]
if {[lsearch -exact $excl $dir] >= 0} continue
readotherrefs [file join $base $dir] "$dname$dir/" {}
} }
close $refd
} }
proc error_popup msg { proc error_popup msg {