Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Rake task to generate a standalone script
Even though the code is easier to manage and test as something like a Ruby project, it's harder to install and use. The rake task added `rake bundle` will output an executable, standalone script called git-rank in the project root. The README install instructions have also been updated to give this as an options, and provide better documentation to the other installation options.
- Loading branch information
Matt Robinson
committed
Jan 16, 2012
1 parent
4834a8e
commit 8020311
Showing
7 changed files
with
85 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rake' | ||
|
||
desc "Bundle all the code into a single script" | ||
|
||
task :bundle do | ||
require 'find' | ||
|
||
git_rank = File.open('git-rank', 'w') | ||
git_rank.puts "#!/usr/bin/env ruby" | ||
|
||
Find.find('lib', 'bin') do |file| | ||
next unless FileTest.file? file | ||
File.read(file).each_line do |line| | ||
next if line =~ /^require.*git-rank/ | ||
next if line =~ /^#!/ | ||
git_rank.puts line | ||
end | ||
end | ||
|
||
File.chmod(0755, git_rank.path) | ||
git_rank.close | ||
puts "git-rank created" | ||
puts "This file be run as a script" | ||
puts "Add it somewhere in your PATH for easy execution" | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'digest/md5' | ||
|
||
module GitRank | ||
module Blame | ||
class << self | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
require 'yaml' | ||
require 'fileutils' | ||
|
||
module GitRank | ||
module Cache | ||
class << self | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
require 'digest/md5' | ||
|
||
module GitRank | ||
module Log | ||
class << self | ||
def calculate(options = {}) | ||
authors = Hash.new {|h, k| h[k] = h[k] = Hash.new(0)} | ||
options_digest = Digest::MD5.hexdigest(options[:additions_only].to_s + options[:deletions_only].to_s) | ||
module Log | ||
class << self | ||
def calculate(options = {}) | ||
authors = Hash.new {|h, k| h[k] = h[k] = Hash.new(0)} | ||
options_digest = Digest::MD5.hexdigest(options[:additions_only].to_s + options[:deletions_only].to_s) | ||
|
||
author = nil | ||
file = nil | ||
state = :pre_author | ||
git_log.each do |line| | ||
case | ||
when (state == :pre_author || state == :post_author) && line =~ /Author: (.*)\s</ | ||
author = $1 | ||
state = :post_author | ||
when line =~ /^(\d+)\s+(\d+)\s+(.*)/ | ||
additions = $1.to_i | ||
deletions = $2.to_i | ||
file = $3 | ||
authors[author][file] += (additions + deletions) | ||
state = :in_diff | ||
when state == :in_diff && line =~ /^commit / | ||
state = :pre_author | ||
author = nil | ||
file = nil | ||
state = :pre_author | ||
git_log.each do |line| | ||
case | ||
when (state == :pre_author || state == :post_author) && line =~ /Author: (.*)\s</ | ||
author = $1 | ||
state = :post_author | ||
when line =~ /^(\d+)\s+(\d+)\s+(.*)/ | ||
additions = $1.to_i | ||
deletions = $2.to_i | ||
file = $3 | ||
authors[author][file] += (additions + deletions) | ||
state = :in_diff | ||
when state == :in_diff && line =~ /^commit / | ||
state = :pre_author | ||
end | ||
end | ||
authors | ||
end | ||
authors | ||
end | ||
|
||
private | ||
private | ||
|
||
def git_log | ||
`git log -M -C -C -w --no-color --numstat` | ||
def git_log | ||
`git log -M -C -C -w --no-color --numstat` | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'optparse' | ||
|
||
module GitRank::Options | ||
def self.parse | ||
options = {} | ||
|