diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 39eead6a34..6ef697f07b 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -10,10 +10,12 @@ module Linguist class Repository attr_reader :repository + MAX_TREE_SIZE = 100_000 + # Public: Create a new Repository based on the stats of # an existing one - def self.incremental(repo, commit_oid, old_commit_oid, old_stats) - repo = self.new(repo, commit_oid) + def self.incremental(repo, commit_oid, old_commit_oid, old_stats, max_tree_size = MAX_TREE_SIZE) + repo = self.new(repo, commit_oid, max_tree_size) repo.load_existing_stats(old_commit_oid, old_stats) repo end @@ -24,11 +26,13 @@ def self.incremental(repo, commit_oid, old_commit_oid, old_stats) # repo - a Rugged::Repository object # commit_oid - the sha1 of the commit that will be analyzed; # this is usually the master branch + # max_tree_size - the maximum tree size to consider for analysis (default: MAX_TREE_SIZE) # # Returns a Repository - def initialize(repo, commit_oid) + def initialize(repo, commit_oid, max_tree_size = MAX_TREE_SIZE) @repository = repo @commit_oid = commit_oid + @max_tree_size = max_tree_size @old_commit_oid = nil @old_stats = nil @@ -129,10 +133,8 @@ def current_tree end protected - MAX_TREE_SIZE = 100_000 - def compute_stats(old_commit_oid, cache = nil) - return {} if current_tree.count_recursive(MAX_TREE_SIZE) >= MAX_TREE_SIZE + return {} if current_tree.count_recursive(@max_tree_size) >= @max_tree_size old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree read_index diff --git a/test/test_repository.rb b/test/test_repository.rb index 9a6e503980..2dcfdfce01 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -87,8 +87,8 @@ def test_commit_with_git_attributes_data # With some .gitattributes data attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' - # It's incremental but should bust the cache - new_repo = Linguist::Repository.incremental(rugged_repository, attr_commit, old_commit, old_repo.cache) + # It's incremental but now is scanning more data and should bust the cache + new_repo = Linguist::Repository.incremental(rugged_repository, attr_commit, old_commit, old_repo.cache, 350_000) assert new_repo.breakdown_by_file["Java"].include?("lib/linguist.rb") end