blob: 6c9a031fa8b69ca7b140a5408597a47874b9925b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# The path from one directory to a file, expressed relative to that directory.
#
# The pre-receive hook is this same binary reached through a symlink, because
# that is how git's core.hooksPath finds it. An absolute symlink would be a
# hook that works at exactly one prefix; a relative one survives a staged
# install (DESTDIR), a prefix built elsewhere, and a container image that moves
# /usr/local around - and `ls -l` still says what the hook is.
BEGIN {
n = split(from, f, "/")
m = split(to, t, "/")
i = 1
while (i <= n && i <= m && f[i] == t[i])
i++
rel = ""
for (k = i; k <= n; k++)
rel = rel (rel == "" ? "" : "/") ".."
for (k = i; k <= m; k++)
rel = rel (rel == "" ? "" : "/") t[k]
if (rel == "")
rel = "."
print rel
}
|