2017-09-13 58 views
0

我有一個用戶案例,我需要計算每個BUC-ID的代碼行數。 我一直在使用如何在計算代碼行時跳過特定的文件?

  git log --shortstat --grep=BUC3565-EPIC16 |grep -E "fil(e|es) changed" | awk -v BUC=$i '{ inserted+=$4; deleted+=$6; delta+=$4-$6i } END {printf "%s, %s, %s, %s \n",BUC, inserted, deleted, delta }' 

現在我有BUC-ID與多個文件實現相同。有沒有什麼辦法可以跳過幾個文件/文件夾,並且仍然能夠計算該BUC-ID的線路關閉代碼?

Basically, I need to exclude some files/folders while calculating Lines of Code. I am not able to do so because each commit has multiple files. Some should be included and some excluded...Any idea how to achieve that? 

CLOC是否提供排除文件的功能?

回答

0
  1. 查找所有與BUC-ID相關的提交。

    git log --pretty=%H --grep=BUC3565-EPIC16

  2. 提交,列出所有修改過的文件排除某些文件/文件夾。

    git show $commit --pretty=format:"" --name-only | grep -ve "foo.txt" -ve "bar/"

  3. 對於剩下的每文件,計算出其insertionsdeletionsdelta

    git show $commit --pretty=format:"" --short-stat -- $file | grep -E "fil(e|es) changed" | awk

  4. 總結的結果。

0

cloc有幾種排除文件的機制;有關詳細信息,請在 https://github.com/AlDanial/cloc上搜索「排除」。

簡而言之,--exclude-list-file讓您在包含文件名的文件,你想排除通過,--exclude-dir,您可以跳過指定的目錄,--exclude-ext跳過與給定文件擴展名的文件,--exclude-lang忽略給定的編程語言,--not-match-f讓你指定一個正則表達式其比賽被跳過。