forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
depvers.sh
executable file
·66 lines (56 loc) · 1.68 KB
/
depvers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# Output the revision control version information (git/hg SHA) for the
# current directory's dependencies. If multiple packages are contained
# within the same git/hg repo we only output the top-level repo and
# SHA once.
#
# The output is sorted by package name:
# <package-repo-root>:<sha>
set -eo pipefail
dirs=()
function visit() {
local dir="$1"
for dir in "${dirs[@]}"; do
if test "${dir}" = "${toplevel}"; then
return 0
fi
done
dirs+=("${toplevel}")
return 1
}
# List the current package and all of the dependencies which are not
# part of the standard library (i.e. packages that contain a least one
# dot in the first component of their name).
pkgs=$(go list -f '{{printf "%s\n" .ImportPath}}{{range .Deps}}{{printf "%s\n" .}}{{end}}' . 2>/dev/null | \
sort -u | egrep '[^/]+\.[^/]+/')
# For each package, list the package directory and package root.
pkginfo=($(go list -f '{{.Dir}} {{.Root}}' ${pkgs} 2>/dev/null))
# Loop over the package info which comes in pairs in the pkginfo
# array.
for (( i=0; i < ${#pkginfo[@]}; i+=2 )); do
dir=${pkginfo[$i]}
if ! test -d "${dir}"; then
continue
fi
toplevel=$(git -C "${dir}" rev-parse --show-toplevel 2>/dev/null)
git=1
if test "${toplevel}" = ""; then
toplevel=$(hg --cwd "${dir}" root 2>/dev/null)
if test "${toplevel}" = ""; then
# TODO(pmattis): Handle subversion/bazaar.
continue
fi
git=0
fi
if visit "${toplevel}"; then
continue
fi
if test "${git}" -eq 1; then
vers=$(git -C "${dir}" rev-parse HEAD 2>/dev/null )
else
vers=$(hg --cwd "${dir}" parent --template '{node}')
fi
root=${pkginfo[$i+1]}
echo ${toplevel#$root/src/}:${vers}
done