Skip to content

Commit

Permalink
Use POSIX test(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Jan 18, 2013
1 parent 29e4ab1 commit 08aea3c
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions autorevision
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ while getopts ":t:o:s:Vf" OPTION; do
esac
done

if [[ ! -z "${VAROUT}" ]] && [[ ! -z "${AFILETYPE}" ]]; then
if [ ! -z "${VAROUT}" ] && [ ! -z "${AFILETYPE}" ]; then
# If both -s and -t are specified:
echo "error: Improper argument combination." 1>&2
exit 1
elif [[ -z "${VAROUT}" ]] && [[ -z "${AFILETYPE}" ]]; then
elif [ -z "${VAROUT}" ] && [ -z "${AFILETYPE}" ]; then
# If neither -s or -t are specified:
arUsage
elif [[ -z "${CACHEFILE}" ]] && [[ "${CACHEFORCE}" = "1" ]]; then
elif [ -z "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then
# If -f is specified without -o:
arUsage
fi
Expand All @@ -102,7 +102,7 @@ gitRepo() {

# Enumeration of changesets
VCS_NUM="$(git rev-list --count HEAD 2>/dev/null)"
if [[ -z "${VCS_NUM}" ]]; then
if [ -z "${VCS_NUM}" ]; then
echo "warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it." 1>&2
VCS_NUM="$(git rev-list HEAD | wc -l)"
fi
Expand All @@ -123,7 +123,7 @@ gitRepo() {
VCS_TAG="$(echo "${DESCRIPTION}" | sed -e "s:-g${VCS_SHORT_HASH}\$::" | sed -e 's:-[0-9]*$::')"

# Distance to last tag or an alias of VCS_NUM if there is no tag
if [[ ! -z "${DESCRIPTION}" ]]; then
if [ ! -z "${DESCRIPTION}" ]; then
VCS_TICK="$(echo "${DESCRIPTION}" | sed -e "s:${VCS_TAG}-::" -e "s:-g${VCS_SHORT_HASH}::")"
else
VCS_TICK="${VCS_NUM}"
Expand Down Expand Up @@ -158,15 +158,15 @@ hgRepo() {
# or branch if no bookmark
VCS_BRANCH="$(hg id -B | cut -d ' ' -f 1)"
# Fall back to the branch if there are no bookmarks
if [[ -z "${VCS_BRANCH}" ]]; then
if [ -z "${VCS_BRANCH}" ]; then
VCS_BRANCH="$(hg id -b)"
fi

# Current or last tag ancestor (excluding auto tags, empty if no tags)
VCS_TAG="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttag}\n' 2>/dev/null | sed -e 's:qtip::' -e 's:tip::' -e 's:qbase::' -e 's:qparent::' -e "s:$(hg --config 'extensions.color=' --color never qtop 2>/dev/null)::" | cut -d ' ' -f 1)"

# Distance to last tag or an alias of VCS_NUM if there is no tag
if [[ ! -z "${VCS_TAG}" ]]; then
if [ ! -z "${VCS_TAG}" ]; then
VCS_TICK="$(hg log -r "${VCS_NUM}" -l 1 --template '{latesttagdistance}\n' 2>/dev/null)"
else
VCS_TICK="${VCS_NUM}"
Expand Down Expand Up @@ -204,7 +204,7 @@ bzrRepo() {
VCS_TAG="$(bzr tags --sort=time | sed '/?$/d' | tail -n1 | cut -d ' ' -f1)"

# Distance to last tag or an alias of VCS_NUM if there is no tag
if [[ ! -z "${VCS_TAG}" ]]; then
if [ ! -z "${VCS_TAG}" ]; then
VCS_TICK="$(bzr log --line -r "tag:${VCS_TAG}.." | tail -n +2 | wc -l | sed -e 's:^ *::')"
else
VCS_TICK="${VCS_NUM}"
Expand All @@ -215,17 +215,17 @@ bzrRepo() {
}

# For svn repos
function svnRepo {
svnRepo() {
VCS_TYPE="svn"

case "${PWD}" in
/*trunk*|/*branches*|/*tags*)
fn="${PWD}"
while [[ "$(basename "${fn}")" != 'trunk' ]] && [[ "$(basename "${fn}")" != 'branches' ]] && [[ "$(basename "${fn}")" != 'tags' ]] && [[ "$(basename "${fn}")" != '/' ]]; do
while [ "$(basename "${fn}")" != 'trunk' ] && [ "$(basename "${fn}")" != 'branches' ] && [ "$(basename "${fn}")" != 'tags' ] && [ "$(basename "${fn}")" != '/' ]; do
fn="$(dirname "${fn}")"
done
fn="$(dirname "${fn}")"
if [[ "${fn}" == '/' ]]; then
if [ "${fn}" == '/' ]; then
VCS_BASENAME="$(basename "${PWD}")"
else
VCS_BASENAME="$(basename "${fn}")"
Expand Down Expand Up @@ -261,13 +261,13 @@ function svnRepo {
while :
do
base="$(basename "${fn}")"
if [[ "${base}" = 'trunk' ]]; then
if [ "${base}" = 'trunk' ]; then
VCS_BRANCH='trunk'
break
elif [[ "${base}" = 'branches' ]] || [[ "${base}" = 'tags' ]]; then
elif [ "${base}" = 'branches' ] || [ "${base}" = 'tags' ]; then
VCS_BRANCH="${lastbase}"
break
elif [[ "${base}" = '/' ]]; then
elif [ "${base}" = '/' ]; then
VCS_BRANCH=""
break
fi
Expand Down Expand Up @@ -598,18 +598,18 @@ EOF


# Detect and collect repo data.
if [[ -f "${CACHEFILE}" ]] && [[ "${CACHEFORCE}" = "1" ]]; then
if [ -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then
# When requested only read from the cache to populate our symbols.
source "${CACHEFILE}"
elif [[ ! -z "$(git rev-parse HEAD 2>/dev/null)" ]]; then
elif [ ! -z "$(git rev-parse HEAD 2>/dev/null)" ]; then
gitRepo
elif [[ ! -z "$(hg root 2>/dev/null)" ]]; then
elif [ ! -z "$(hg root 2>/dev/null)" ]; then
hgRepo
elif [[ ! -z "$(bzr root 2>/dev/null)" ]]; then
elif [ ! -z "$(bzr root 2>/dev/null)" ]; then
bzrRepo
elif [[ ! -z "$(svn info 2>/dev/null)" ]]; then
elif [ ! -z "$(svn info 2>/dev/null)" ]; then
svnRepo
elif [[ -f "${CACHEFILE}" ]]; then
elif [ -f "${CACHEFILE}" ]; then
# We are not in a repo; try to use a previously generated cache to populate our symbols.
source "${CACHEFILE}"
else
Expand All @@ -619,56 +619,56 @@ fi


# -s output is handled here.
if [[ ! -z "${VAROUT}" ]]; then
if [[ "${VAROUT}" = "VCS_TYPE" ]]; then
if [ ! -z "${VAROUT}" ]; then
if [ "${VAROUT}" = "VCS_TYPE" ]; then
echo "${VCS_TYPE}"
elif [[ "${VAROUT}" = "VCS_BASENAME" ]]; then
elif [ "${VAROUT}" = "VCS_BASENAME" ]; then
echo "${VCS_BASENAME}"
elif [[ "${VAROUT}" = "VCS_NUM" ]]; then
elif [ "${VAROUT}" = "VCS_NUM" ]; then
echo "${VCS_NUM}"
elif [[ "${VAROUT}" = "VCS_DATE" ]]; then
elif [ "${VAROUT}" = "VCS_DATE" ]; then
echo "${VCS_DATE}"
elif [[ "${VAROUT}" = "VCS_BRANCH" ]]; then
elif [ "${VAROUT}" = "VCS_BRANCH" ]; then
echo "${VCS_BRANCH}"
elif [[ "${VAROUT}" = "VCS_TAG" ]]; then
elif [ "${VAROUT}" = "VCS_TAG" ]; then
echo "${VCS_TAG}"
elif [[ "${VAROUT}" = "VCS_TICK" ]]; then
elif [ "${VAROUT}" = "VCS_TICK" ]; then
echo "${VCS_TICK}"
elif [[ "${VAROUT}" = "VCS_FULL_HASH" ]]; then
elif [ "${VAROUT}" = "VCS_FULL_HASH" ]; then
echo "${VCS_FULL_HASH}"
elif [[ "${VAROUT}" = "VCS_SHORT_HASH" ]]; then
elif [ "${VAROUT}" = "VCS_SHORT_HASH" ]; then
echo "${VCS_SHORT_HASH}"
elif [[ "${VAROUT}" = "VCS_WC_MODIFIED" ]]; then
elif [ "${VAROUT}" = "VCS_WC_MODIFIED" ]; then
echo "${VCS_WC_MODIFIED}"
fi
fi


# Detect requested output type and use it.
if [[ ! -z "${AFILETYPE}" ]]; then
if [[ "${AFILETYPE}" = "h" ]]; then
if [ ! -z "${AFILETYPE}" ]; then
if [ "${AFILETYPE}" = "h" ]; then
hOutput
elif [[ "${AFILETYPE}" = "xcode" ]]; then
elif [ "${AFILETYPE}" = "xcode" ]; then
xcodeOutput
elif [[ "${AFILETYPE}" = "sh" ]]; then
elif [ "${AFILETYPE}" = "sh" ]; then
shOutput
elif [[ "${AFILETYPE}" = "py" ]]; then
elif [ "${AFILETYPE}" = "py" ]; then
pyOutput
elif [[ "${AFILETYPE}" = "pl" ]]; then
elif [ "${AFILETYPE}" = "pl" ]; then
plOutput
elif [[ "${AFILETYPE}" = "lua" ]]; then
elif [ "${AFILETYPE}" = "lua" ]; then
luaOutput
elif [[ "${AFILETYPE}" = "php" ]]; then
elif [ "${AFILETYPE}" = "php" ]; then
phpOutput
elif [[ "${AFILETYPE}" = "ini" ]]; then
elif [ "${AFILETYPE}" = "ini" ]; then
iniOutput
elif [[ "${AFILETYPE}" = "js" ]]; then
elif [ "${AFILETYPE}" = "js" ]; then
jsOutput
elif [[ "${AFILETYPE}" = "java" ]]; then
elif [ "${AFILETYPE}" = "java" ]; then
javaOutput
elif [[ "${AFILETYPE}" = "javaprop" ]]; then
elif [ "${AFILETYPE}" = "javaprop" ]; then
javapropOutput
elif [[ "${AFILETYPE}" = "tex" ]]; then
elif [ "${AFILETYPE}" = "tex" ]; then
texOutput
else
echo "error: Not a valid output type." 1>&2
Expand All @@ -678,7 +678,7 @@ fi


# If requested, make a cache file.
if [[ ! -z "${CACHEFILE}" ]] && [[ ! "${CACHEFORCE}" = "1" ]]; then
if [ ! -z "${CACHEFILE}" ] && [ ! "${CACHEFORCE}" = "1" ]; then
TARGETFILE="${CACHEFILE}"
shOutput
fi

0 comments on commit 08aea3c

Please sign in to comment.