Skip to content

Commit

Permalink
more efficient commit count
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Oct 21, 2008
1 parent 6b86674 commit 6571f70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/grit/commit.rb
Expand Up @@ -71,7 +71,7 @@ def lazy_source
#
# Returns Integer
def self.count(repo, ref)
repo.git.rev_list({}, ref).strip.split("\n").size
repo.git.rev_list({}, ref).size / 41
end

# Find all commits matching the given criteria.
Expand Down
2 changes: 1 addition & 1 deletion lib/grit/git-ruby.rb
Expand Up @@ -51,7 +51,7 @@ def rev_list(options, ref = 'master')
elsif (options.size == 0)
# pure rev-list
begin
return file_index.commits_from(rev_parse({}, ref)).join("\n")
return file_index.commits_from(rev_parse({}, ref)).join("\n") + "\n"
rescue
return method_missing('rev-list', options, ref)
end
Expand Down
6 changes: 6 additions & 0 deletions test/test_commit.rb
Expand Up @@ -22,6 +22,12 @@ def test_id_abbrev
assert_equal '80f136f', @r.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev
end

# count

def test_count
assert_equal 107, Commit.count(@r, 'master')
end

# diff

def test_diff
Expand Down
2 changes: 1 addition & 1 deletion test/test_rubygit.rb
Expand Up @@ -128,7 +128,7 @@ def test_rev_list_pretty_raw

def test_rev_list
out = @git.rev_list({}, 'master')
assert_equal out, fixture('rev_list_lines').chomp
assert_equal out, fixture('rev_list_lines')
end

def test_rev_list_range
Expand Down

0 comments on commit 6571f70

Please sign in to comment.