Skip to content

Commit

Permalink
Fancy progress. Fancy configuration. Fancy
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed Feb 5, 2014
1 parent dead69a commit deadb3a
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions git-vain
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

require 'digest/sha1'

MSG = 'dead'
base = `git cat-file -p HEAD`
def get_message
msg = `git config vein.default`.chomp
unless msg =~ /\A[a-f0-9]{2,10}\z/
abort "ERROR: vein.default not set, or not lowercase hex\nhint: git config --global --add vein.default <hex>"
end
msg
end

def parse_commit(original)
def parse_commit
original = `git cat-file -p HEAD`
parts = original.split(/(^author.*> |committer.*> )(\d+)(.*$)/, 3)
[ parts[0..1].join,
parts[2 ].to_i,
Expand All @@ -14,36 +20,39 @@ def parse_commit(original)
parts[7..-1].join ]
end

@head, @t_author, @middle, @t_committer, @rest = parse_commit(base)
def format_progress(ad, cd, hashes, rewrite="\r")
print "∆author: %5d, ∆committor: %5d, khash: %d#{rewrite}" % [ad,cd,hashes/1000]
end

def search
def search(message, parsed_commit)
puts "searching for: #{message}"
@head, @t_author, @middle, @t_committer, @rest = parsed_commit
counter = 0

(0..3600).each do |a|
[a*1,a*-1].uniq.each do |ao|
auth_t = @t_author+ao
[a*1,a*-1].uniq.each do |ad|
auth_t = @t_author+ad
(0..3600).each do |c|
[c*1,c*-1].uniq.each do |co|
comm_t = @t_committer+co
#(0..80 ).each do |space|
[c*1,c*-1].uniq.each do |cd|
comm_t = @t_committer+cd
content = [@head, auth_t, @middle, comm_t, @rest].join
store = "commit #{content.length}\0" + content
sha1 = Digest::SHA1.hexdigest(store)

if sha1[0..3] == MSG
puts "comm_t: #{co} auth_t: #{ao} counter: #{counter}"
if sha1.start_with?(message)
format_progress(ad,cd,counter,"\n")
return [content,sha1]
end

counter+=1
puts counter if (counter%100000).zero?
#end
counter += 1
format_progress(ad,cd,counter) if (counter%100000).zero?
end
end
end
end
end

content, sha1 = search()
content, sha1 = search(get_message, parse_commit)

exit if ARGV.include? "--dry-run"

Expand All @@ -58,4 +67,5 @@ else
puts "failed, git doesn't agree:"
puts sha1
puts sha2
exit 1
end

0 comments on commit deadb3a

Please sign in to comment.