Class: Database
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/database.rb,
lib/database/blob.rb,
lib/database/tree.rb,
lib/database/entry.rb,
lib/database/loose.rb,
lib/database/author.rb,
lib/database/commit.rb,
lib/database/packed.rb,
lib/database/backends.rb,
lib/database/tree_diff.rb
Defined Under Namespace
Classes: Author, Backends, Blob, Commit, Entry, Loose, Packed, Raw, Tree, TreeDiff
Constant Summary
collapse
- TYPES =
{
"blob" => Blob,
"tree" => Tree,
"commit" => Commit
}
- TIME_FORMAT =
"%s %z"
Instance Method Summary
collapse
Constructor Details
#initialize(pathname) ⇒ Database
Returns a new instance of Database.
29
30
31
32
|
# File 'lib/database.rb', line 29
def initialize(pathname)
@objects = {}
@backend = Backends.new(pathname)
end
|
Instance Method Details
#build_list(list, entry, prefix) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/database.rb', line 70
def build_list(list, entry, prefix)
return unless entry
return list[prefix.to_s] = entry unless entry.tree?
load(entry.oid).entries.each do |name, item|
build_list(list, item, prefix.join(name))
end
end
|
#hash_object(object) ⇒ Object
41
42
43
|
# File 'lib/database.rb', line 41
def hash_object(object)
hash_content(serialize_object(object))
end
|
#load(oid) ⇒ Object
45
46
47
|
# File 'lib/database.rb', line 45
def load(oid)
@objects[oid] ||= read_object(oid)
end
|
#load_tree_entry(oid, pathname) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/database.rb', line 49
def load_tree_entry(oid, pathname)
commit = load(oid)
root = Database::Entry.new(commit.tree, Tree::TREE_MODE)
return root unless pathname
pathname.each_filename.reduce(root) do |entry, name|
entry ? load(entry.oid).entries[name] : nil
end
end
|
#load_tree_list(oid, pathname = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/database.rb', line 60
def load_tree_list(oid, pathname = nil)
return {} unless oid
entry = load_tree_entry(oid, pathname)
list = {}
build_list(list, entry, pathname || Pathname.new(""))
list
end
|
#short_oid(oid) ⇒ Object
83
84
85
|
# File 'lib/database.rb', line 83
def short_oid(oid)
oid[0..6]
end
|
#store(object) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/database.rb', line 34
def store(object)
content = serialize_object(object)
object.oid = hash_content(content)
@backend.write_object(object.oid, content)
end
|
#tree_diff(a, b, filter = PathFilter.new) ⇒ Object
87
88
89
90
91
|
# File 'lib/database.rb', line 87
def tree_diff(a, b, filter = PathFilter.new)
diff = TreeDiff.new(self)
diff.compare_oids(a, b, filter)
diff.changes
end
|
#tree_entry(oid) ⇒ Object