From a08c9b8b4ffc95d13a2953357ec8c6afdde001c1 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 24 May 2019 13:57:52 -0600 Subject: [PATCH] helper methods to get actual Objects, not just information about them avoids having to have the caller keep looking up objects directly from the repo --- lib/rugged/diff/delta.rb | 8 ++++++++ lib/rugged/tree.rb | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/rugged/diff/delta.rb b/lib/rugged/diff/delta.rb index f2bc2dd98..2bb95cd53 100644 --- a/lib/rugged/diff/delta.rb +++ b/lib/rugged/diff/delta.rb @@ -50,6 +50,14 @@ def typechange? status == :typechange end + def old_blob + owner.lookup(old_file[:oid]) unless added? + end + + def new_blob + owner.lookup(new_file[:oid]) unless deleted? + end + def inspect "#<#{self.class.name}:#{object_id} {old_file: #{old_file.inspect}, new_file: #{new_file.inspect}, similarity: #{similarity.inspect}, status: #{status.inspect}>" end diff --git a/lib/rugged/tree.rb b/lib/rugged/tree.rb index 22db563c3..335aa7235 100644 --- a/lib/rugged/tree.rb +++ b/lib/rugged/tree.rb @@ -164,6 +164,11 @@ def diff(other = nil, options = nil) Tree.diff(repo, self, other, options) end + def lookup(entry_id) + entry = get_entry(entry_id) + owner.lookup(entry[:oid]) if entry + end + def inspect data = "#\n" self.each { |e| data << " <\"#{e[:name]}\" #{e[:oid]}>\n" }