Skip to content

Commit 7726572

Browse files
committed
dist: tools: add git-cache
1 parent d79a662 commit 7726572

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

Makefile.include

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ RIOTPKG ?= $(RIOTBASE)/pkg
2020
RIOTPROJECT ?= $(shell git rev-parse --show-toplevel 2>/dev/null || pwd)
2121
RIOTPROJECT := $(abspath $(RIOTPROJECT))
2222

23+
GITCACHE:=$(RIOTBASE)/dist/tools/git/git-cache
24+
2325
# Include Docker settings near the top because we need to build the environment
2426
# command line before some of the variable origins are overwritten below when
2527
# using abspath, strip etc.

Makefile.vars

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export SIZE # The command to read to size of the ELF sections.
4343
export UNDEF # Set by the BOARD's and CPU's Makefile.include, this contains object files with must not be used in the ELFFILE even if the if no call to the functions.
4444
export WERROR # Treat all compiler warnings as errors if set to 1 (see -Werror flag in GCC manual)
4545

46+
export GITCACHE # path to git-cache executable
4647
export FLASHER # The command to call on "make flash".
4748
export FFLAGS # The parameters to supply to FLASHER.
4849
export TERMPROG # The command to call on "make term".

dist/tools/git/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Overview
2+
3+
This directory contains some git tools used by RIOT's build system
4+
5+
## git-cache
6+
7+
Simple git caching script, from https://github.com/kaspar030/git-cache
8+
If git-cache is unconfigured, the script pulls from the given remote location.
9+
10+
In order to set up the cache, do:
11+
12+
- install the git-cache binary into path.
13+
This will make the script available as "git cache ...".
14+
Alternatively, directly execute it.
15+
- run "git cache init", which initializes a git cache in ${HOME}/.gitcache.
16+
The used path can be overridden using the "GIT_CACHE_DIR" environment
17+
variable.
18+
The cache repository will be used to cache multiple remote repositories.
19+
- add a repository to the cache: "git cache add \<name\> \<URL\>
20+
- whenever needed (at least once after adding a repository),
21+
run "git cache update"

dist/tools/git/git-cache

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/sh
2+
3+
git_cache() {
4+
git -C "${GIT_CACHE_DIR}" $*
5+
}
6+
7+
init() {
8+
set -ex
9+
test -d "${GIT_CACHE_DIR}/.git" || {
10+
mkdir -p "${GIT_CACHE_DIR}"
11+
12+
git_cache init --bare
13+
git_cache config core.compression 1
14+
}
15+
set +ex
16+
}
17+
18+
add() {
19+
set -ex
20+
git_cache remote add $1 $2
21+
set +ex
22+
}
23+
24+
update() {
25+
set -ex
26+
local REMOTE=${1:---all}
27+
git_cache fetch $REMOTE
28+
set +ex
29+
}
30+
31+
list() {
32+
local REMOTES="$(git_cache remote show)"
33+
for remote in $REMOTES; do
34+
echo "${remote}: $(git_cache remote get-url $remote)"
35+
done
36+
}
37+
38+
drop() {
39+
set -ex
40+
local REMOTE=${1}
41+
[ -z "$REMOTE" ] && {
42+
echo "usage: git cache drop <name>"
43+
exit 1
44+
}
45+
git_cache remote remove $REMOTE
46+
set +ex
47+
}
48+
49+
_check_commit() {
50+
git_cache cat-file -e ${1}^{commit}
51+
}
52+
53+
clone() {
54+
set -ex
55+
local REMOTE="${1}"
56+
local SHA1="${2}"
57+
local REMOTE_NAME="$(basename $REMOTE)"
58+
local TARGET_PATH="${3:-${REMOTE_NAME}}"
59+
60+
if _check_commit $2 2>&1; then
61+
git init "${TARGET_PATH}"
62+
git_cache tag commit$SHA1 $SHA1 || true # ignore possibly already existing tag
63+
git -C "${TARGET_PATH}" fetch --depth=1 "${GIT_CACHE_DIR}" refs/tags/commit$SHA1
64+
git -C "${TARGET_PATH}" checkout FETCH_HEAD
65+
else
66+
git clone "${REMOTE}" "${TARGET_PATH}"
67+
git -C "${TARGET_PATH}" checkout $SHA1
68+
fi
69+
set +ex
70+
}
71+
72+
usage() {
73+
echo "git cache uses a bare git repository containing all objects from multiple"
74+
echo "upstream git repositories."
75+
echo ""
76+
echo "usage:"
77+
echo ""
78+
echo " git cache init initialize git cache"
79+
echo " git cache add <name> <url> add repository <url> with name <name>"
80+
echo " git cache list list cached repositories"
81+
echo " git cache drop <name> drop repo from cache"
82+
echo " git cache update [<name>] fetch repo named <name> (or all)"
83+
echo " git cache clone <url> <SHA1> clone repository <url> from cache"
84+
echo " git cache show-path print's the path that can be used as "
85+
echo " '--reference' parameter"
86+
echo ""
87+
echo "To retrieve objects from cache (will use remote repository if needed):"
88+
echo ' git clone --reference $(git cache show-path) <repo>'
89+
}
90+
91+
ACTION=$1
92+
shift
93+
94+
export GIT_CACHE_DIR=${GIT_CACHE_DIR:-${HOME}/.gitcache}
95+
96+
case $ACTION in
97+
init)
98+
init $*
99+
;;
100+
add)
101+
add $*
102+
;;
103+
update)
104+
update $*
105+
;;
106+
list)
107+
list $*
108+
;;
109+
drop)
110+
drop $*
111+
;;
112+
show-path)
113+
echo ${GIT_CACHE_DIR}
114+
;;
115+
clone)
116+
clone $*
117+
;;
118+
*)
119+
usage
120+
;;
121+
esac

0 commit comments

Comments
 (0)