Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo#ls_tree #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/rugged_adapter/git_layer_rugged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,25 @@ def log(commit = Gollum::Git.default_ref_for_repo(@repo), path = nil, options =
git.log(commit, path, **options)
end

def lstree(sha, options = {})
results = []
@repo.lookup(sha).tree.walk(:postorder) do |root, entry|
results << ::Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root)
def lstree(sha, path, options = {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In RJGit adapter, the path argument in lstree has a default of nil. Should we do the same here?


if path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

tree = @repo.lookup(sha).tree
tree = tree / path if path

Instead of the if/else?

tree = @repo.lookup(sha).tree / path
else
tree = @repo.lookup(sha).tree
end

if options.fetch(:recursive, true)
results = []
tree.walk(:postorder) do |root, entry|
results << ::Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root)
end
results
else
tree.map do |entry|
Copy link
Member

@bartkamphorst bartkamphorst Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree.map { |entry| Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root) }

Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root)
end
end
results
end

def path
Expand Down
Loading