偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

大幅減小OH代碼占用磁盤空間的幾個小技巧

系統(tǒng) OpenHarmony
隨著版本的演進和更新,OpenHarmony的代碼量越來越大,非常消耗磁盤空間。下面我們組合使用repo和git命令的一些參數(shù),可以大幅減小OpenHarmony代碼的磁盤占用空間。

想了解更多關(guān)于開源的內(nèi)容,請訪問:

51CTO 鴻蒙開發(fā)者社區(qū)

https://ost.51cto.com

前言

隨著版本的演進和更新,OpenHarmony的代碼量越來越大,非常消耗磁盤空間。以 v4.1-Release 版本為例,參考官方文檔提供的以下四條命令獲取的OpenHarmony代碼已經(jīng)接近50G(包含//.repo/、//prebuilts/、checkout到工作區(qū)的代碼和通過git lfs pull下載的大文件):

$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release --no-repo-verify
$ repo sync -c
$ repo forall -c 'git lfs pull'
$ ./build/prebuilts_download.sh
1.
2.
3.
4.

如果完成了三類系統(tǒng)(輕量、小型、標(biāo)準(zhǔn))的全編譯,則會產(chǎn)生幾十個G的 .ccache 和幾十個G的 //out/ ,整體已經(jīng)占用超過150G的磁盤空間了。

下面我們組合使用repo和git命令的一些參數(shù),可以大幅減小OpenHarmony代碼的磁盤占用空間。

repo sync -m 參數(shù)

在repo sync 命令增加 -m 參數(shù),指定只同步(下載或clone)manifest倉庫中的某個manifest文件。

例如,不使用 -m 參數(shù)的官方命令:

$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release --no-repo-verify
1.

會在 //.repo/manifest.xml 中指定同步 //.repo/manifests/default.xml 文件,該文件中

<include name="ohos/ohos.xml" />
  <include name="chipsets/all.xml" />

會指定下載全量的OpenHarmony代碼,包括了開源出來的所有chipsets倉庫代碼,這樣會包含我們并不需要的非常多的倉庫。

而通過增加 -m 參數(shù)則可以只下載我們需要的chipsets倉庫代碼,例如:

$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release -m chipsets/hispark_taurus.xml 
--no-repo-verify
1.

上述命令增加 “-m chipsets/hispark_taurus.xml” 后,//.repo/manifest.xml 的描述則會指定同步 //.repo/manifests/chipsets/hispark_taurus.xml 文件:

<include name="ohos/ohos.xml" />
  <include name="chipsets/hispark/hispark.xml" />

這樣可以節(jié)省不少磁盤空間。

如果我們還需要其它的chipsets的manifest,那我們可以直接手動修改 //.repo/manifest.xml 的描述,按規(guī)則增加對應(yīng)的chipsets的manifest即可。

或者,不加 -m 參數(shù),也可以直接修改 //.repo/manifests/default.xml 文件的描述,再去repo sync,也可以達(dá)到同樣的效果:

<include name="ohos/ohos.xml" />
  <!-- include name="chipsets/all.xml" / -->
  <include name="chipsets/hispark/hispark.xml" />
  <include name="chipsets/dayu200/dayu200.xml" />

repo sync -g 參數(shù)

在repo sync 命令增加 -g 參數(shù),可以對各倉庫的groups字段進行過濾,匹配 -g 參數(shù)的倉庫才會同步(下載或clone)到本地。例如:

$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release -m chipsets/hispark_taurus.xml -g 
ohos:mini,ohos:small --no-repo-verify
$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release -m chipsets/dayu200.xml -g ohos:standard 
--no-repo-verify

但是需要注意,這個 groups 標(biāo)簽,看上去維護得并不好,甚至有些混亂。

有些倉庫只適用于標(biāo)準(zhǔn)系統(tǒng),也添加了ohos:mini,ohos:small標(biāo)簽;有些倉庫雖然沒有ohos:mini,ohos:small標(biāo)簽,但是在執(zhí)行 ./build/prebuilts_download.sh 時,則是需要依賴到的;有些倉庫則沒有ohos:mini,ohos:small標(biāo)簽,但會在編譯過程中或者鏡像打包階段依賴到而導(dǎo)致編譯錯誤;這些都需要根據(jù)實際情況自行修改 ohos.xml 中對應(yīng)倉庫的 groups 標(biāo)簽然后再同步和編譯代碼。

repo sync --depth 參數(shù)

ohos.xml 中對Linux內(nèi)核倉庫的描述:

<project name="kernel_linux_5.10" path="kernel/linux/linux-5.10" clone-depth="1" groups="..."/>

有一個 clone-depth=“1” 的字段,該字段表示在同步(下載或clone)遠(yuǎn)程倉庫到本地時,只下載遠(yuǎn)程倉庫默認(rèn)分支的最新一次提交記錄到本地,而不是將所有的歷史記錄都同步到本地,這樣可以大幅減少倉庫代碼的磁盤占用空間。

如果只想對某些倉庫(特別是歷史記錄特別長的倉庫)做 clone-depth="num"的操作,可以像上面一樣,在對應(yīng)倉庫的描述信息增加 clone-depth=“num” 字段就行了;如果想對所有倉庫進行一次性的操作,那就給 repo sync 命令增加一個 --depth 參數(shù)。例如:

$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release -m chipsets/hispark_taurus.xml -g 
ohos:mini,ohos:small --no-repo-verify --depth=1
$ repo init -u git@gitee.com:openharmony/manifest.git -b 
refs/tags/OpenHarmony-v4.1-Release -m chipsets/dayu200.xml -g ohos:standard 
--no-repo-verify --depth=1

git --depth 參數(shù)

通過 repo sync --depth=1 參數(shù)拉取的OpenHarmony代碼,默認(rèn)只獲取遠(yuǎn)程倉庫默認(rèn)分支的最新一次提交記錄到本地,并不包含更多的歷史提交記錄和其他費默認(rèn)分支的記錄。

對某個具體倉庫,可以通過git命令和參數(shù)進行一些操作,獲取更多的歷史提交記錄和其他費默認(rèn)分支的記錄到本地。

git 的 --depth參數(shù):

--depth 
Create a shallow clone【淺克隆】 with a history truncated to the specified 
number【depth】 of commits.
Implies【隱含參數(shù)是】--single-branch【僅獲取遠(yuǎn)程倉庫默認(rèn)分支的最新一次提交記錄】unless【除非顯式指定參數(shù)】--no-single-branch【通過這個參數(shù)指明獲取遠(yuǎn)程倉庫所有分支的最新一次提交記錄】is 
given to fetch the histories near the tips of all branches.
If you want to clone submodules shallowly, also pass 
--shallow-submodules.

即在默認(rèn)的 --single-branch 情況下,只獲取默認(rèn)分支到本地;如果要查看其他分支的代碼和提交記錄,可以按如下一些操作進行處理。

# 例如本地只有OpenHarmony-v4.1-Release的記錄,想要使用遠(yuǎn)程的OpenHarmony-v3.2-Release分支,
# 這樣操作就可以把遠(yuǎn)程的OpenHarmony-v3.2-Release分支拉取到本地進行切換和使用
$ git remote set-branches origin OpenHarmony-v3.2-Release
$ git fetch --depth=1 origin 
OpenHarmony-v3.2-Release:OpenHarmony-v3.2-Release
$ git checkout OpenHarmony-v3.2-Release

git-sparse-checkout 參數(shù)

對于特定的倉庫,git 還有一個稀疏檢出的操作可以稍微減少checkout的代碼量,更重要的是這個參數(shù)可以讓工作區(qū)的代碼目錄更清爽。

例如,對于 //vendor/hisilicon/ 倉庫,默認(rèn)是:

ohos@ohos:~/Lite/A41Rel/vendor/hisilicon$ ls -l
drwxrwxr-x 13 ohos ohos 4096 5月 30 15:26 ./
drwxrwxr-x 7 ohos ohos 4096 4月 29 17:48 ../
drwxrwxr-x 3 ohos ohos 4096 5月 30 15:26 .git/
drwxrwxr-x 2 ohos ohos 4096 5月 30 15:26 .gitee/
-rw-rw-r-- 1 ohos ohos 84 5月 30 15:26 .gitignore
drwxrwxr-x 6 ohos ohos 4096 5月 30 15:26 hispark_aries/
drwxrwxr-x 4 ohos ohos 4096 4月 14 11:50 hispark_pegasus/
drwxrwxr-x 3 ohos ohos 4096 5月 30 15:26 hispark_pegasus_mini_system/
drwxrwxr-x 7 ohos ohos 4096 5月 30 15:26 hispark_phoenix/
drwxrwxr-x 6 ohos ohos 4096 4月 14 00:21 hispark_taurus/
drwxrwxr-x 5 ohos ohos 4096 5月 10 09:18 hispark_taurus_linux/
drwxrwxr-x 6 ohos ohos 4096 5月 30 15:26 hispark_taurus_mini_system/
drwxrwxr-x 7 ohos ohos 4096 5月 30 15:26 hispark_taurus_standard/
-rw-rw-r-- 1 ohos ohos 10347 5月 30 15:26 LICENSE
-rw-rw-r-- 1 ohos ohos 6854 5月 30 15:26 OAT.xml
-rw-rw-r-- 1 ohos ohos 1345 5月 30 15:26 README_zh.md
drwxrwxr-x 6 ohos ohos 4096 5月 30 15:26 watchos/

這里面有很多項目是我們平?;旧嫌貌坏揭哺牟坏降?,放在這里很礙眼,通過hb set選擇項目時,也會出現(xiàn)太多的選項,因此,可以使用git-sparse-checkout的配置來只checkout我們想要的文件夾(項目)。

可以在這個倉庫目錄下執(zhí)行:

git config core.sparsecheckout true
# true 或 1,enable sparsecheckout
# false 或 0,disable sparsecheckout

該命令會在 //vendor/hisilicon/.git/config 文件的 [core] 段新增一個 sparsecheckout = true 的配置,enable 了sparsecheckout 功能,然后再執(zhí)行:

git sparse-checkout set hispark_pegasus hispark_taurus 
hispark_taurus_linux
或者
echo "hispark_pegasus hispark_taurus hispark_taurus_linux" > 
.git/info/sparse-checkout

作用都是將需要checkout的目錄和文件列表寫入到 //vendor/hisilicon/.git/info/sparse-checkout 文件中去,而不在該文件中的目錄和文件則不會checkout出來(但這些文件的objects對象,還是在本地倉庫中的,只是沒有解壓到工作區(qū)而已),而我們的修改和提交,也不會影響到未checkout的目錄和文件。

ohos@ohos:~/Lite/A41Rel/vendor/hisilicon$ ll
drwxrwxr-x 6 ohos ohos 4096 5月 30 15:46 ./
drwxrwxr-x 7 ohos ohos 4096 4月 29 17:48 ../
drwxrwxr-x 3 ohos ohos 4096 5月 30 15:46 .git/
drwxrwxr-x 4 ohos ohos 4096 4月 14 11:50 hispark_pegasus/
drwxrwxr-x 6 ohos ohos 4096 4月 14 00:21 hispark_taurus/
drwxrwxr-x 5 ohos ohos 4096 5月 10 09:18 hispark_taurus_linux/

當(dāng)我們需要把全部的目錄和文件列表全部checkout出來的時候,可以直接執(zhí)行:

git sparse-checkout set *
或者
echo "*" > .git/info/sparse-checkout

然后重新checkout一下當(dāng)前的分支即可。

注意:

實測發(fā)現(xiàn),是否執(zhí)行 “git config core.sparsecheckout” 命令來enable或disable sparsecheckout都沒關(guān)系(不知道是git版本問題還是bug),只要有 .git/info/sparse-checkout 文件,都可以通過改寫該文件達(dá)到稀疏檢出的目的。

補充

經(jīng)過上述命令和參數(shù)的組合使用,可以大幅減少OpenHarmony倉庫和代碼所占用的磁盤空間,但是三大巨頭(//prebuilts/、//out/、.ccache)仍然是占用著非常大的磁盤空間。

想了解更多關(guān)于開源的內(nèi)容,請訪問:

51CTO 鴻蒙開發(fā)者社區(qū)

https://ost.51cto.com

責(zé)任編輯:jianghua 來源: 51CTO 鴻蒙開發(fā)者社區(qū)
相關(guān)推薦

2015-11-25 13:37:52

磁盤空間LinuxUbuntu

2021-07-30 16:28:42

磁盤微信工具

2010-06-17 15:01:24

Linux查看磁盤空間

2021-03-05 08:29:20

DeleteMysql數(shù)據(jù)結(jié)構(gòu)

2020-03-31 18:50:33

微軟Windows操作系統(tǒng)

2020-02-03 13:50:17

Windows 10Windows技巧

2020-05-12 09:02:29

Linux磁盤硬盤

2010-04-08 15:24:36

Windows磁盤空間

2011-01-18 10:25:19

Linux磁盤分區(qū)

2023-04-18 23:31:59

Linux磁盤系統(tǒng)

2010-05-27 17:51:55

Linux查看磁盤空間

2011-08-19 14:34:03

iPhone開發(fā)

2018-07-24 08:50:40

Linux磁盤空間磁盤利用率

2021-02-11 08:11:50

Window10Docker容器

2024-11-28 13:16:47

Linux磁盤

2018-01-11 15:36:23

命令磁盤空間Docker

2024-10-31 16:46:36

2020-07-09 09:55:12

diskonautLinux導(dǎo)航器

2020-11-17 11:19:48

Linux磁盤空間

2021-08-06 20:22:27

Linuxdu命令
點贊
收藏

51CTO技術(shù)棧公眾號