0

我想计算 git 存储库中每个分支的总代码行数。我已经通过这样的 git 命令完成了

  def count_code_lines(project, branch_name)
    project_path = "#{SettingConfig.repos_path}/#{project.disk_path}.git"
    count_string = `cd #{project_path} && git ls-tree --full-tree -r HEAD --name-only | xargs -I '$' git show #{branch_name}:$ | wc -l`  
    count_string.to_i
  rescue StandardError => e
    @fail_count += 1
    Gitlab::AppLogger.info "ProjectCustomStatisticWorker count_code_lines Error. project_id: #{project.id}, error: #{e}"
    nil
  end

但它太慢了。有没有办法通过崎岖不平来计算代码行?

4

0 回答 0