diff options
Diffstat (limited to 'build/relpath.awk')
| -rw-r--r-- | build/relpath.awk | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/build/relpath.awk b/build/relpath.awk new file mode 100644 index 0000000..6c9a031 --- /dev/null +++ b/build/relpath.awk @@ -0,0 +1,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 +} |
