Created
January 25, 2013 19:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'rugged', :path => '../rugged' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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