pjhyett (owner)

Revisions

gist: 50872 Download_button fork
public
Public Clone URL: git://gist.github.com/50872.git
Embed All Files: show embed
git-fast-log.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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