Skip to content

Instantly share code, notes, and snippets.

@jrsconfitto
Created January 25, 2013 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrsconfitto/4637339 to your computer and use it in GitHub Desktop.
Save jrsconfitto/4637339 to your computer and use it in GitHub Desktop.
This is a playground for me to try to git a `git log -- [path]` equivalent from Rugged
gem 'rugged', :path => '../rugged'
#!ruby
#
# History
#
# This is a playground for me to try to git a `git log -- [path]` equivalent from Rugged
require 'rugged'
repo = Rugged::Repository.new(ARGV[0])
path = ARGV[1]
puts "Looking for the file named: #{path} in Repository: #{repo}"
versions = []
walker = Rugged::Walker.new(repo)
walker.push(repo.head.target)
walker.each do |commit|
commit.tree.walk(:preorder) do |root, entry|
if root + entry[:name] == path
commit.parents.each do |parent|
parent = repo.lookup(parent.oid)
parent.tree.each_blob do |parent_blob|
if parent_blob[:name] == entry[:name] and parent_blob[:oid] != entry[:oid]
# Add the commit to the list of versions
versions << commit if not versions.include?(commit)
end
end
end
end
end
end
puts "There are #{versions.size} commits affecting your file going back from the head ref"
versions.each do |version|
puts "#{version.oid} #{version.message.split(/\r?\n/)[0]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment