Module: GitDump::Repo::Rugged
- Includes:
- Git
- Defined in:
- lib/git_dump/repo/rugged.rb
Overview
Interface to git using libgit2 through rugged
Constant Summary
Constants included from Git
Class Method Summary collapse
Instance Method Summary collapse
-
#blob_read(sha, io = nil) ⇒ Object
Return contents of blob identified by sha If io is specified, then content will be written to io.
-
#data_sha(content) ⇒ Object
Add blob for content to repository, return sha.
-
#path_sha(path) ⇒ Object
Add blob for content at path to repository, return sha.
-
#size(sha) ⇒ Object
Return size of object identified by sha.
-
#tag_entries ⇒ Object
Return list of entries per tag ref Each entry is a hash with following keys: :sha => tag or commit sha :name => ref name.
-
#tree_entries(sha) ⇒ Object
Read tree at sha returning list of entries Each entry is a hash like one for treeify.
-
#treeify(entries) ⇒ Object
Add blob for entries to repository, return sha Each entry is a hash with following keys: :type => :blob or :tree :name => name string :sha => sha of content :mode => last three octets of mode.
Methods included from Git
#blob_pipe, #blob_unpack, #commit, #fetch, #gc, #push, #remove_tag, #tag
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/git_dump/repo/rugged.rb', line 12 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#blob_read(sha, io = nil) ⇒ Object
Return contents of blob identified by sha If io is specified, then content will be written to io
57 58 59 60 61 62 63 |
# File 'lib/git_dump/repo/rugged.rb', line 57 def blob_read(sha, io = nil) if io super(sha, io) else ::Rugged::Object.new(repo, sha).content end end |
#data_sha(content) ⇒ Object
Add blob for content to repository, return sha
17 18 19 20 21 22 23 |
# File 'lib/git_dump/repo/rugged.rb', line 17 def data_sha(content) if content.respond_to?(:read) ::Rugged::Blob.from_io(repo, content) else ::Rugged::Blob.from_buffer(repo, content) end end |
#path_sha(path) ⇒ Object
Add blob for content at path to repository, return sha
26 27 28 |
# File 'lib/git_dump/repo/rugged.rb', line 26 def path_sha(path) ::Rugged::Blob.from_disk(repo, path) end |
#size(sha) ⇒ Object
Return size of object identified by sha
51 52 53 |
# File 'lib/git_dump/repo/rugged.rb', line 51 def size(sha) ::Rugged::Object.new(repo, sha).size end |
#tag_entries ⇒ Object
Return list of entries per tag ref Each entry is a hash with following keys:
:sha => tag or commit sha
:name => ref name
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/git_dump/repo/rugged.rb', line 84 def tag_entries repo..map do |tag| { :name => tag.name, :sha => tag.target.oid, :author_time => tag.target.[:time], :commit_time => tag.target.committer[:time], :tag_message => tag.annotation && tag.annotation., :commit_message => tag.target., } end end |
#tree_entries(sha) ⇒ Object
Read tree at sha returning list of entries Each entry is a hash like one for treeify
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/git_dump/repo/rugged.rb', line 67 def tree_entries(sha) object = repo.lookup(sha) tree = object.type == :tree ? object : object.tree tree.map do |entry| { :type => entry[:type], :name => entry[:name], :sha => entry[:oid], :mode => entry[:filemode], } end end |
#treeify(entries) ⇒ Object
Add blob for entries to repository, return sha Each entry is a hash with following keys:
:type => :blob or :tree
:name => name string
:sha => sha of content
:mode => last three octets of mode
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/git_dump/repo/rugged.rb', line 36 def treeify(entries) builder = ::Rugged::Tree::Builder.new(repo) entries.map do |entry| entry = normalize_entry(entry) builder << { :type => entry[:type], :name => entry[:name], :oid => entry[:sha], :filemode => entry[:mode], } end builder.write end |