Skip to content

Gitlab::Git::Repository#autocrlf= should not be called for every call to Repository#raw_repository

Currently Gitlab::Git::Repository#autocrlf= is called every time Repository#raw_repository is called. This call in turn writes to the Git configuration of a repository. Because this particular action is only ever needed once (upon initializing a new repository) we should make sure this call is actually only called once. Caching this in Redis will only help until the cache expires (currently 2 weeks) so I propose adding a database column per project that tracks whether this action has been performed or not. This would lead to code something along the lines of the following:

def raw_repository
  return nil unless path_with_namespace

  @raw_repository ||= begin
    repo = Gitlab::Git::Repository.new(path_to_repo)

    unless project.repository_configured
      repo.autocrlf = :input

      project.update(repository_configured: true)
    end

    repo
  rescue Gitlab::Git::Repository::NoRepository
    nil
  end
end

The actual column name is just an example name.