成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

聊一聊社區代碼統計的三種方式

系統 OpenHarmony
本文介紹了代碼量統計的各種方式。統計每一筆提交的增刪改修改量,偏重統計過程中的貢獻,批量增刪時,容易產生巨量的代碼量。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區??

??https://ost.51cto.com??

社區代碼度量方式總結

當開發者每提交一筆Pull Request/Commit時,都會有代碼修改量,包含新增了多少行代碼、刪除了多少行代碼。這屬于過程動態的統計方式。還可以統計倉庫代碼量,不關注提交過程,只關注存留的代碼量。這屬于靜態的統計方式。每位開發者都會關注自己貢獻的代碼量,此文就總結下,各個代碼量統計方式。

1、git log統計每筆提交的修改量

先看下git log相關的參數說明。

git log 參數說明

–numstat

Similar to --stat, but shows number of added and deleted lines in decimal notation and pathname without abbreviation, to make it more machine friendly. For binary files, outputs two ??-?? instead of saying ??0 0??.

–shortstat

Output only the last line of the --stat format containing total number of modified files, as well as number of added and deleted lines.

–stat

使用–stat參數主要可以在git log 的基礎上輸出文件增刪改的統計數據。

$ git log --stat
commit fa71c098e2912b69a1c82348d403b3260f2dc64e (HEAD -> temp_temp)
Author: zz********g <z********g@gmail.com>
Date: Wed Aug 12 17:19:05 2020 +0800
add txt file and dir # commit信息
txt/a.txt | 1 + # 文件修改狀態,添加或刪除了多少行
1 file changed, 1 insertion(+) # 統計變更文件數量?

執行后獲得輸出如下:

commit d0411d5e8d26be3abde076e24f026b25cc2e7819 (HEAD -> master, origin/master, origin/HEAD)
Merge: ae99435 faf351b
Author: ******** <d********g@h****I.com>
Date: Tue Feb 21 12:54:28 2023 +0000

!1358 add communication_dsoftbus commiter
Merge pull request !1358 from michael4096/master

commit ae99435b2347d4b648c03f9dcf7d7e095bb150a4
Author: z********o <z********0@h****I.com>
Date: Tue Feb 21 12:42:59 2023 +0000

!1360 Add libabigail and elfutils to openharmony-sig
* Add libabigail and elfutils to openharmony-sig

2 0 sig/sig-basicsoftwareservice/sig-basicsoftwareservice.md
2 0 sig/sig-basicsoftwareservice/sig-basicsoftwareservice_cn.md
6 2 sig/sigs.json
3 files changed, 10 insertions(+), 2 deletions(-)

開子進程:

process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding=_encoding, cwd=WORKING_DIR + project_name)

在檢出的代碼倉目錄下,執行 cmd=[‘git’, ‘log’, ‘–shortstat’, ‘–numstat’],處理輸出,就可以統計出來倉庫每一筆提交的代碼增刪修改量。

2、統計倉庫代碼量

使用cloc工具統計倉庫代碼量,cloc相關的參數如下,其中force-lang-def指定支持的編程語言定義,by-file-by-lang 指定按編程語言按文件分別輸出。

--read-lang-def=E:\\WorkSpace\\lmk-bohan\\stat-data\\my_definitions.txt --by-file-by-lang
參數說明
--force-lang-def=<file> Load language processing filters from <file>,
then use these filters instead of the built-in
filters. Note: languages which map to the same
file extension (for example:
MATLAB/Mathematica/Objective-C/MUMPS/Mercury;
Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
will be ignored as these require additional
processing that is not expressed in language
definition files. Use --read-lang-def to define
new language filters without replacing built-in
filters (see also --write-lang-def,
--write-lang-def-incl-dup).

--by-file-by-lang Report results for every source file encountered
in addition to reporting by language.?

在代碼倉下,開子進程:

process = subprocess.Popen(cmd,stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='utf-8', cwd=WORKING_DIR, errors='ignore')

執行:

cmd = ['stat-data\\cloc-1.92.exe', '--read-lang-def=' + _current_file + '\\stat-data\\my_definitions.txt',
'--by-file-by-lang', name]

即可以得到代碼倉的每個程序的文件的代碼量詳情,包含blank空行、comment注釋行、code代碼行等,通常取其加和,都計算為代碼量。輸出示例內容如下:

100 files
200 files
300 files
312 text files.
classified 254 files
Duplicate file check 254 files (245 known unique)
Unique: 100 files
Unique: 200 files
251 unique files.
Counting: 100
Counting: 200
131 files ignored.

github.com/AlDanial/cloc v 1.92 T=0.24 s (1034.9 files/s, 69044.2 lines/s)
-----------------------------------------------------------------------------------------
File blank comment code
-----------------------------------------------------------------------------------------
community\sig\sigs.json 0 0 1068
community\zh\committer.md 0 0 442
community\sig\sig_list.toml 49 1 283
community\sig\README.md 46 0 190



community\sig\sig-linkboy\oh\oh8.md 7 0 4
community\sig\sig-linkboy\sig_linkboy.md 4 0 4
community\sig\sig-linkboy\oh\oh3.md 6 0 3
-----------------------------------------------------------------------------------------
SUM: 3684 1 13061
-----------------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Markdown 248 3635 0 11685
JSON 2 0 0 1093
TOML 1 49 1 283
-------------------------------------------------------------------------------
SUM: 251 3684 1 13061
-------------------------------------------------------------------------------

3、統計代碼倉貢獻者的代碼量

在上一章節,可以統計代碼倉的代碼量,有時候還想知道每一個開發者在這個代碼倉中貢獻了多少代碼量,甚至還可以根據郵箱后綴,還知道每一家單位貢獻的代碼量。

對于上一章節cloc統計的每一個源代碼文件,可以對這些文件執行git blame命令:

  • 遍歷cloc統計文件列表,執行git blame -e,獲取貢獻者及其貢獻的代碼量:
cmd = ['git', 'blame', '-e', _file_path]

示例輸出如下,可以看出這個文件,每一行最后是誰貢獻的。如果一行文件,屬于A新增的,但是B修改后,那最終顯示這一行屬于B貢獻的,最后一次修改者最終貢獻了這一行代碼。

git blame -e default.xml
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 1) <?xml version="1.0" encoding="UTF-8"?>
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 2) <manifest>
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 3) <remote fetch="."1 name="origin" review="https://openharmony.gitee.com/openharmony/"/>
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 4) <default remote="origin" revision="master" sync-j="4" />
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 5)
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 6) <include name="ohos/ohos.xml" />
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 7) <include name="chipsets/all.xml" />
7d700a41 (<z**************n@h****I.com> 2022-05-07 21:01:53 +0800 8) </manifest>

D:\codes\code-count\manifest>git blame -e devboard.xml
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 1) <?xml version="1.0" encoding="UTF-8"?>
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 2) <manifest>
9e17c922 (<m***************1@h****I.com> 2021-11-27 06:33:25 +0000 3) <remote fetch="https://gitee.com/openharmony-sig" name="sig" review="https://gitee.com/openharmony-sig/"/>
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 4) <include name="default.xml" />
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 5) <project name="device_st" path="device/st" revision="master" remote="sig"/>
c3deb066 (<l*************g@h****I.com> 2021-04-28 17:04:50 +0800 6) <project name="device_allwinner" path="device/allwinner" revision="master" remote="sig"/>
c3deb066 (<l*************g@h****I.com> 2021-04-28 17:04:50 +0800 7) <project name="vendor_h****I_ipcamera_v3s" path="vendor/h****I/ipcamera_v3s" revision="master" remote="sig"/>
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 8) <project name="vendor_h****I_minidisplay_demo" path="vendor/h****I/minidisplay_demo" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 9) <project name="device_mediatek" path="device/mediatek" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 10) <project name="device_nordic" path="device/nordic" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 11) <project name="device_nxp" path="device/nxp" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 12) <project name="device_fudanmicro" path="device/fudanmicro" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 13) <project name="device_bestechnic" path="device/bestechnic" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 14) <project name="device_ingenic" path="device/ingenic" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 15) <project name="device_espressif" path="device/espressif" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 16) <project name="device_winnermicro" path="device/winnermicro" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 17) <project name="device_unisoc" path="device/unisoc" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 18) <project name="device_broadcom" path="device/broadcom" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 19) <project name="device_realtek" path="device/realtek" revision="master" remote="sig"/>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 20) <project name="device_bouffalolab" path="device/bouffalolab" revision="master" remote="sig"/>
019f8d3f (<m***************1@h****I.com> 2021-04-20 15:11:42 +0800 21) </manifest>
2bb5688e (<l*************g@h****I.com> 2021-06-07 10:45:13 +0800 22)

小結

本文介紹了代碼量統計的各種方式。統計每一筆提交的增刪改修改量,偏重統計過程中的貢獻,批量增刪時,容易產生巨量的代碼量。cloc可以看出代碼倉的最新最終規模,過程中的批量增刪,會對沖。而git blame統計會看重每一位貢獻者的代碼量。

??想了解更多關于開源的內容,請訪問:??

??51CTO 開源基礎軟件社區??

??https://ost.51cto.com??

責任編輯:jianghua 來源: 51CTO 開源基礎軟件社區
相關推薦

2022-09-26 08:03:25

VMware虛擬機

2021-05-12 18:02:23

方法創建線程

2025-01-10 08:15:22

C#異步底層

2021-02-22 14:04:47

Vue框架項目

2023-11-04 16:28:54

2024-09-09 08:29:25

2023-02-09 10:39:15

gRPC通信模式

2020-01-07 08:31:52

代碼分層Web

2020-09-08 06:54:29

Java Gradle語言

2024-03-11 07:46:40

React優先級隊列二叉堆

2023-07-06 13:56:14

微軟Skype

2020-09-15 12:45:48

系統LinuxUnix

2021-07-01 19:22:33

腳本Shell參數

2018-06-07 13:17:12

契約測試單元測試API測試

2018-03-26 14:51:17

數據中心停機中斷邊緣計算

2023-09-22 17:36:37

2021-01-28 22:31:33

分組密碼算法

2020-05-22 08:16:07

PONGPONXG-PON

2021-12-06 09:43:01

鏈表節點函數

2021-07-16 11:48:26

模型 .NET微軟
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: av片在线播放 | 亚洲成人免费av | 一区二区成人在线 | 国产最新视频在线 | 97色在线观看免费视频 | 欧美日韩一区不卡 | 久久久久久久久久久久91 | 欧美大片一区 | 亚洲乱码国产乱码精品精98午夜 | 丁香久久 | 久久国产精品亚洲 | 国产日韩免费视频 | 在线免费观看色 | 九七午夜剧场福利写真 | 高清黄色网址 | 亚洲成人av | 久久久久久高清 | 99免费在线视频 | 久操伊人| 日韩精品色网 | 韩国理论电影在线 | 欧美极品在线视频 | 99精品欧美一区二区三区综合在线 | 日韩黄a| 亚洲伊人精品酒店 | 九九在线视频 | 欧美伊人久久久久久久久影院 | 亚洲一区中文字幕 | 成人激情视频在线播放 | 亚洲精品美女视频 | 国产观看 | 亚洲逼院 | 亚洲人成在线播放 | 一区二区三区四区在线 | www免费视频 | 国产精品欧美一区二区 | 国产伦精品一区二区三区精品视频 | 精品国产不卡一区二区三区 | 人妖av| 亚洲国产精品久久久 | 玖操|