Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make max_tree_size configurable per-repository #6806

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/linguist/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -129,10 +133,8 @@ def current_tree
end

protected
MAX_TREE_SIZE = 100_000
issyl0 marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
4 changes: 2 additions & 2 deletions test/test_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading