Skip to content

Commit

Permalink
Implement Tree#find_blob (#25)
Browse files Browse the repository at this point in the history
* Add Tree#find_blob
* Require latest RJGit
* Decomplicate file mode logic
  • Loading branch information
Dawa Ometto authored May 24, 2023
1 parent e6367d9 commit 5240790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gollum-rjgit_adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.summary = %q{Adapter for Gollum to use RJGit at the backend.}
s.description = %q{Adapter for Gollum to use RJGit at the backend.}

s.add_runtime_dependency "rjgit", "~> 6.1"
s.add_runtime_dependency "rjgit", "~> 6.5"
s.add_development_dependency "rspec", "3.4.0"

s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
Expand Down
12 changes: 10 additions & 2 deletions lib/rjgit_adapter/git_layer_rjgit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
def lstree(sha, options={})
entries = RJGit::Porcelain.ls_tree(@repo.jrepo, nil, @repo.find(sha, :tree), {:recursive => options[:recursive]})
entries.map! do |entry|
entry[:mode] = entry[:mode].to_s(8)
entry[:mode] = entry[:mode]
entry[:sha] = entry[:id]
entry
end
Expand Down Expand Up @@ -478,13 +478,21 @@ def id
end

def /(file)
@tree.send(:/, file)
obj = @tree.send(:/, file)
return nil if obj.nil?
obj.is_a?(RJGit::Tree) ? Gollum::Git::Tree.new(obj) : Gollum::Git::Blob.new(obj)
end

def blobs
return Array.new if @tree == {}
@tree.blobs.map{|blob| Gollum::Git::Blob.new(blob) }
end

def find_blob(&block)
return nil unless block_given?
blob = @tree.find_blob {|blob| yield blob[:name] }
blob ? Gollum::Git::Blob.new(blob) : nil
end
end

class NoSuchShaFound < StandardError
Expand Down

0 comments on commit 5240790

Please sign in to comment.