Skip to content

Commit

Permalink
Load object metadata from the database
Browse files Browse the repository at this point in the history
When compressing objects in packs, we'd like to get some metadata about
all the objects so they can be sorted, without loading all the objects
into memory. We just need the type and size of each object.

The `Database#load_info` method is similar to `load_raw`, but it only
reads a short amount of the object file in order to parse out the type
and size. It does not return any data from the object.
  • Loading branch information
jcoglan committed Dec 12, 2018
1 parent a7593e5 commit f2c3375
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def load(oid)
@objects[oid] ||= read_object(oid)
end

def load_info(oid)
type, size, _ = read_object_header(oid, 128)
Raw.new(type, size)
end

def load_raw(oid)
type, size, scanner = read_object_header(oid)
Raw.new(type, size, scanner.rest)
Expand Down

0 comments on commit f2c3375

Please sign in to comment.