内核优化
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$root"
|
||||
origin="$(git remote get-url origin)"
|
||||
origin="${origin%/}"
|
||||
remote_root="$(printf '%s\n' "$origin" | sed -E 's#/[^/]+(\.git)?$##')"
|
||||
fetch_repo() {
|
||||
local repo="$1"
|
||||
local branch="$2"
|
||||
local dir="$3"
|
||||
if [ -e "$dir" ]; then
|
||||
printf '路径【%s】已存在,跳过初始化\n' "$dir"
|
||||
return 0
|
||||
fi
|
||||
git clone --branch "$branch" --single-branch "$repo" "$dir"
|
||||
}
|
||||
fetch_repo_ex() {
|
||||
local name="$1"
|
||||
local repo="${remote_root}/${name}"
|
||||
local branch="master"
|
||||
fetch_repo "$repo" "$branch" "third_party/${name}"
|
||||
}
|
||||
clone_git_shallow() {
|
||||
if [ "$#" -ne 2 ]; then
|
||||
printf '用法: clone_git_shallow <git地址> <分支或标签>\n' >&2
|
||||
return 2
|
||||
fi
|
||||
local git_url="${1%/}"
|
||||
local branch="$2"
|
||||
local repo_name="${git_url##*/}"
|
||||
local dir
|
||||
repo_name="${repo_name%.git}"
|
||||
dir="third_party/${repo_name}"
|
||||
if [ -e "$dir" ]; then
|
||||
printf '路径【%s】已存在,跳过初始化\n' "$dir"
|
||||
return 0
|
||||
fi
|
||||
git clone --branch "$branch" --depth 1 --single-branch "$git_url" "$dir"
|
||||
}
|
||||
|
||||
mkdir -p third_party
|
||||
clone_git_shallow "https://github.com/nlohmann/json.git" "v3.12.0"
|
||||
fetch_repo_ex "CPP_Core"
|
||||
Reference in New Issue
Block a user