Class: Linguist::Source::RuggedRepository
- Inherits:
-
Repository
- Object
- Repository
- Linguist::Source::RuggedRepository
- Defined in:
- lib/linguist/source/rugged.rb
Overview
RuggedRepository is an implementation of the Source::Repository abstract class. It represents a Git repository that is accessed using the libgit2 wrapper Rugged.
Defined Under Namespace
Classes: Diff
Constant Summary collapse
- GIT_ATTR_OPTS =
{ :priority => [:index], :skip_system => true }
- GIT_ATTR_FLAGS =
Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS)
Instance Method Summary collapse
- #diff(old_commit, new_commit) ⇒ Object
-
#get_tree(commit_id) ⇒ Object
Internal: get the Rugged::Tree associated with a given commit ID.
- #get_tree_size(commit_id, limit) ⇒ Object
-
#initialize(rugged) ⇒ RuggedRepository
constructor
A new instance of RuggedRepository.
- #load_attributes_for_path(path, attr_names) ⇒ Object
- #load_blob(blob_id, max_size) ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #set_attribute_source(commit_id) ⇒ Object
Constructor Details
#initialize(rugged) ⇒ RuggedRepository
Returns a new instance of RuggedRepository.
40 41 42 43 44 |
# File 'lib/linguist/source/rugged.rb', line 40 def initialize(rugged) @rugged = rugged @tree_map = {} @attr_source = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
90 91 92 |
# File 'lib/linguist/source/rugged.rb', line 90 def method_missing(method_name, *args, &block) @rugged.send(method_name, *args, &block) end |
Instance Method Details
#diff(old_commit, new_commit) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/linguist/source/rugged.rb', line 68 def diff(old_commit, new_commit) old_tree = old_commit.nil? ? nil : get_tree(old_commit) new_tree = new_commit.nil? ? nil : get_tree(new_commit) Diff.new(Rugged::Tree.diff(@rugged, old_tree, new_tree)) end |
#get_tree(commit_id) ⇒ Object
Internal: get the Rugged::Tree associated with a given commit ID. This method should not be used outside of Linguist itself and is subject to change or be removed.
commit_id - the object ID of the commit whose tree instance we want.
Returns the Rugged::Tree of the specified commit.
82 83 84 85 86 87 88 |
# File 'lib/linguist/source/rugged.rb', line 82 def get_tree(commit_id) tree = @tree_map[commit_id] return tree if tree @tree_map[commit_id] = Rugged::Commit.lookup(@rugged, commit_id).tree @tree_map[commit_id] end |
#get_tree_size(commit_id, limit) ⇒ Object
46 47 48 |
# File 'lib/linguist/source/rugged.rb', line 46 def get_tree_size(commit_id, limit) get_tree(commit_id).count_recursive(limit) end |
#load_attributes_for_path(path, attr_names) ⇒ Object
60 61 62 |
# File 'lib/linguist/source/rugged.rb', line 60 def load_attributes_for_path(path, attr_names) @rugged.fetch_attributes(path, attr_names, GIT_ATTR_FLAGS) end |
#load_blob(blob_id, max_size) ⇒ Object
64 65 66 |
# File 'lib/linguist/source/rugged.rb', line 64 def load_blob(blob_id, max_size) Rugged::Blob.to_buffer(@rugged, blob_id, max_size) end |
#set_attribute_source(commit_id) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/linguist/source/rugged.rb', line 50 def set_attribute_source(commit_id) tree = get_tree(commit_id) return if @attr_source == tree @attr_source = tree attr_index = Rugged::Index.new attr_index.read_tree(@attr_source) @rugged.index = attr_index end |