Skip to content

Instantly share code, notes, and snippets.

@pjhyett
Created January 23, 2009 03:47
Show Gist options
  • Save pjhyett/50872 to your computer and use it in GitHub Desktop.
Save pjhyett/50872 to your computer and use it in GitHub Desktop.
# An old experiment, it's marginally faster for big repos
# git-fast-log <branch> <path>
branch = ARGV[0] || "master"
dir = ARGV[1] || "."
dir += "/" if dir[dir.size - 1].chr != '/'
tree = `git-ls-tree #{branch} #{dir}`.split("\n").map { |l| l.split("\t").last }
diff_rev = "git-rev-list --max-count=#{tree.size * 2} #{branch} #{dir}"
diff_tree = "git-diff-tree --stdin --numstat -v --pretty=oneline #{dir}"
commits = {}
`#{diff_rev} | #{diff_tree}`.split("\n").each do |line|
if line !~ /\t/
@commit = line.split(' ').first
next
end
path = line.split("\t").last
key = tree.detect { |file| path =~ /^#{file}/ }
commits[key] ||= @commit if key
end
commits.each do |file, commit|
commits[file] = `git-show #{commit}`
end
puts "#{commits.size} out of #{tree.size} found"
(tree - commits.keys).each do |file|
commits[file] = `git-log --max-count=1 #{branch} #{file}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment