Class: Amp::Core::Repositories::Git::LooseObject
- Defined in:
- lib/amp-git/repo_format/loose_object.rb
Overview
LooseObject
A single loose object (tree, tag, commit, etc.) in the Git system. Its type and content will be determined after we read the file.
It is uniquely identified by a SHA1 hash.
Constant Summary
Constants inherited from RawObject
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from RawObject
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hsh, opener, content = nil) ⇒ LooseObject
constructor
Initializes the RawObject.
Methods inherited from RawObject
Constructor Details
#initialize(hsh, opener, content = nil) ⇒ LooseObject
Initializes the RawObject. Needs a hash to identify it and an opener. The opener should point to the .git directory.
70 71 72 |
# File 'lib/amp-git/repo_format/loose_object.rb', line 70 def initialize(hsh, opener, content = nil) @hash_id, @opener, @content = hsh, opener, content end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
61 62 63 |
# File 'lib/amp-git/repo_format/loose_object.rb', line 61 def type @type end |
Class Method Details
.lookup(hsh, opener) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/amp-git/repo_format/loose_object.rb', line 36 def lookup(hsh, opener) require 'scanf' path = File.join("objects", hsh[0..1], hsh[2..40]) mode = "r" type, content = nil, nil begin opener.open(path, mode) do |fp| type, content_size = fp.scanf("%s %d") fp.seek(type.size + 1 + content_size.to_s.size + 1, IO::SEEK_SET) content = fp.read(content_size) end rescue SystemCallError if create FileUtils.mkdir_p(opener.join("objects", hsh[0..1])) mode = "w+" retry else raise end end RawObject.construct(hsh, opener, type, content) end |