Class: Database

Inherits:
Object
  • 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



28
29
30
31
# File 'lib/database.rb', line 28

def initialize(pathname)
  @objects = {}
  @backend = Backends.new(pathname)
end

Instance Method Details

#build_list(list, entry, prefix) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/database.rb', line 69

def build_list(list, entry, prefix)
  return unless entry
  return list[prefix.to_s] = entry unless entry.tree?

  load(entry.oid).each_entry do |name, item|
    build_list(list, item, prefix.join(name))
  end
end

#hash_object(object) ⇒ Object



40
41
42
# File 'lib/database.rb', line 40

def hash_object(object)
  hash_content(serialize_object(object))
end

#load(oid) ⇒ Object



44
45
46
# File 'lib/database.rb', line 44

def load(oid)
  @objects[oid] ||= read_object(oid)
end

#load_tree_entry(oid, pathname) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/database.rb', line 48

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



59
60
61
62
63
64
65
66
67
# File 'lib/database.rb', line 59

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



82
83
84
# File 'lib/database.rb', line 82

def short_oid(oid)
  oid[0..6]
end

#store(object) ⇒ Object



33
34
35
36
37
38
# File 'lib/database.rb', line 33

def store(object)
  content    = serialize_object(object)
  object.oid = hash_content(content)

  @backend.write_object(object.oid, content)
end

#tree_diff(a, b, prune = []) ⇒ Object



86
87
88
89
90
# File 'lib/database.rb', line 86

def tree_diff(a, b, prune = [])
  diff = TreeDiff.new(self, prune)
  diff.compare_oids(a, b)
  diff.changes
end

#tree_entry(oid) ⇒ Object



78
79
80
# File 'lib/database.rb', line 78

def tree_entry(oid)
  Entry.new(oid, Tree::TREE_MODE)
end