Skip to content

Commit d1ed0f9

Browse files
committed
Add Repository::log_at method
Convenient shortcut for browsing commit log
1 parent 323181e commit d1ed0f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: lib/rugged/repository.rb

+18
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,24 @@ def blob_at(revision, path)
250250
(blob.type == :blob) ? blob : nil
251251
end
252252

253+
# Get log at path for specified object
254+
#
255+
# obj - Object in question
256+
# path - The String file path.
257+
#
258+
# Returns an Array of Rugged::Commit objects
259+
def log_at(obj, path)
260+
walker = Rugged::Walker.new(self)
261+
walker.sorting(Rugged::SORT_DATE)
262+
walker.push(obj.oid)
263+
en = Enumerator.new do |y|
264+
walker.each do |commit|
265+
y << commit if commit.diff(paths: [path]).size > 0
266+
end
267+
end
268+
return en
269+
end
270+
253271
def fetch(remote_or_url, *args, **kwargs)
254272
unless remote_or_url.kind_of? Remote
255273
remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url)

0 commit comments

Comments
 (0)