请稍侯

统计 git 代码仓库

13 January 2024

统计 Git 代码仓库中Swift与OC代码行数

一个示例的 shell 脚本,用于统计指定的 Git 代码仓库中指定标签的 Swift 和 Objective-C 代码行数的变化数据,并将结果以表格形式输出:

#!/bin/bash

# 定义要统计的标签数组
tags=("6.6" "6.7" "6.8" "6.9" "7.0")

# 定义代码仓库路径
repo_path="/path/to/your/git/repo"

# 定义代码文件类型
swift_files=("*.swift")
objc_files=("*.m" "*.h")

# 输出表头
echo -e "Tag\tSwift\tObjective-C"

# 遍历标签数组
for tag in "${tags[@]}"; do
  # 切换到指定标签
  git -C "$repo_path" checkout "$tag" >/dev/null 2>&1

  # 统计 Swift 代码行数
  swift_lines=$(find "$repo_path/Code" -name "${swift_files[0]}" | xargs cat | wc -l)
  
  # 统计 Objective-C 代码行数
  objc_lines=$(find "$repo_path/Code" -name "${objc_files[0]}" -o -name "${objc_files[1]}" | xargs cat | wc -l)
  
  # 输出数据
  echo -e "$tag\t$swift_lines\t$objc_lines"
done