Revision d4d015664fa1a42285d206791a7bf2dd788f4f4e authored by toivoh on 01 March 2016, 18:08:35 UTC, committed by Tony Kelman on 13 March 2016, 23:46:30 UTC
They are still given to the user in macro arguments, otherwise LineNumberNode seems to be used consistently. (cherry picked from commit 3a16b19eb6c03a89d58a92d7623e60a83b21c3d8) ref #15309
1 parent 6fffa59
relative_path.sh
#!/usr/bin/env bash
# This file is a part of Julia. License is MIT: http://julialang.org/license
# both $1 and $2 are absolute paths beginning with /
# returns relative path to $2/$target from $1/$source
# Source copied from http://stackoverflow.com/a/12498485/230778
source=$1
target=$2
if [[ ! "$source" == /* ]] || [[ ! "$target" == /* ]]; then
echo "ERROR: paths must be absolute paths, they must start with a forward slash!"
exit 1
fi
common_part=$source # for now
result="" # for now
while [[ "${target#$common_part}" == "${target}" ]]; do
# no match, means that candidate common part is not correct
# go up one level (reduce common part)
common_part="$(dirname $common_part)"
# and record that we went back, with correct / handling
if [[ -z $result ]]; then
result=".."
else
result="../$result"
fi
done
if [[ $common_part == "/" ]]; then
# special case for root (no common path)
result="$result/"
fi
# since we now have identified the common part,
# compute the non-common part
forward_part="${target#$common_part}"
# and now stick all parts together
if [[ -n $result ]] && [[ -n $forward_part ]]; then
result="$result$forward_part"
elif [[ -n $forward_part ]]; then
# extra slash removal
result="${forward_part:1}"
fi
echo $result
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...