@matheusbsbs / matheus-bagliano / commits / 36a7cad6e4
Fork 0

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>

Junio C Hamano committed Nov 18, 2005 at 23:54 UTC 36a7cad6e4ae8a331731666d985a7619a76bb4fb
1 file changed +32 -66
gitk
+32 -66
@@ -238,77 +238,43 @@ proc parsecommit {id contents listed olds} {
238
239 proc readrefs {} {
240 global tagids idtags headids idheads tagcontents
241 -
242 - set tags [glob -nocomplain -types f [gitdir]/refs/tags/*]
243 - foreach f $tags {
244 - catch {
245 - set fd [open $f r]
246 - set line [read $fd]
247 - if {[regexp {^[0-9a-f]{40}} $line id]} {
248 - set direct [file tail $f]
249 - set tagids($direct) $id
250 - lappend idtags($id) $direct
251 - set tagblob [exec git-cat-file tag $id]
252 - set contents [split $tagblob "\n"]
253 - set obj {}
254 - set type {}
255 - set tag {}
256 - foreach l $contents {
257 - if {$l == {}} break
258 - switch -- [lindex $l 0] {
259 - "object" {set obj [lindex $l 1]}
260 - "type" {set type [lindex $l 1]}
261 - "tag" {set tag [string range $l 4 end]}
262 - }
263 - }
264 - if {$obj != {} && $type == "commit" && $tag != {}} {
265 - set tagids($tag) $obj
266 - lappend idtags($obj) $tag
267 - set tagcontents($tag) $tagblob
268 - }
269 - }
270 - close $fd
271 - }
272 - }
273 - set heads [glob -nocomplain -types f [gitdir]/refs/heads/*]
274 - foreach f $heads {
275 - catch {
276 - set fd [open $f r]
277 - set line [read $fd 40]
278 - if {[regexp {^[0-9a-f]{40}} $line id]} {
279 - set head [file tail $f]
280 - set headids($head) $line
281 - lappend idheads($line) $head
282 - }
283 - close $fd
284 - }
285 - }
286 - readotherrefs refs {} {tags heads}
287 -}
288 -
289 -proc readotherrefs {base dname excl} {
241 global otherrefids idotherrefs
242
292 - set git [gitdir]
293 - set files [glob -nocomplain -types f [file join $git $base *]]
294 - foreach f $files {
295 - catch {
296 - set fd [open $f r]
297 - set line [read $fd 40]
298 - if {[regexp {^[0-9a-f]{40}} $line id]} {
299 - set name "$dname[file tail $f]"
300 - set otherrefids($name) $id
301 - lappend idotherrefs($id) $name
243 + set refd [open [list | git-ls-remote [gitdir]] r]
244 + while {0 <= [set n [gets $refd line]]} {
245 + if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
246 + match id path]} {
247 + continue
248 + }
249 + if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
250 + set type others
251 + set name $path
252 + }
253 + if {$type == "tags"} {
254 + set tagids($name) $id
255 + lappend idtags($id) $name
256 + set obj {}
257 + set type {}
258 + set tag {}
259 + catch {
260 + set commit [exec git-rev-parse "$id^0"]
261 + if {"$commit" != "$id"} {
262 + set tagids($name) $commit
263 + lappend idtags($commit) $name
264 + }
265 + }
266 + catch {
267 + set tagcontents($name) [exec git-cat-file tag "$id"]
268 }
303 - close $fd
269 + } elseif { $type == "heads" } {
270 + set headids($name) $id
271 + lappend idheads($id) $name
272 + } else {
273 + set otherrefids($name) $id
274 + lappend idotherrefs($id) $name
275 }
276 }
306 - set dirs [glob -nocomplain -types d [file join $git $base *]]
307 - foreach d $dirs {
308 - set dir [file tail $d]
309 - if {[lsearch -exact $excl $dir] >= 0} continue
310 - readotherrefs [file join $base $dir] "$dname$dir/" {}
311 - }
277 + close $refd
278 }
279
280 proc error_popup msg {