#!/usr/bin/env bash
declare -A proj2repo=(
["phabricator"]="P"
["arcanist"]="ARC"
)
PHAB_INSTALL=/opt/phabricator/phabricator
PHAB_REPOS=/var/lib/phabricator/repos
PHAB_CTAGS=/var/lib/phabricator/ctags
rm ${PHAB_CTAGS}/*
for PROJ in "${!proj2repo[@]}" ; do
REPO=${proj2repo["$PROJ"]}
TMP_REPO=/tmp/${REPO}
mkdir -p ${TMP_REPO}
chown -R www-data:www-data ${TMP_REPO}
cd ${TMP_REPO}
export GIT_DIR=${PHAB_REPOS}/${REPO}
export GIT_WORK_TREE=${TMP_REPO}
sudo -u www-data git reset --hard master
sudo -u www-data git clean -fdx
find . -name '*.py' | ${PHAB_INSTALL}/scripts/symbols/generate_ctags_symbols.php > ${PHAB_CTAGS}/${PROJ}
find . -name '*.scala' | ${PHAB_INSTALL}/scripts/symbols/generate_ctags_symbols.php >> ${PHAB_CTAGS}/${PROJ}
find . -name '*.go' | ${PHAB_INSTALL}/scripts/symbols/generate_ctags_symbols.php >> ${PHAB_CTAGS}/${PROJ}
${PHAB_INSTALL}/scripts/symbols/import_project_symbols.php ${PROJ} < ${PHAB_CTAGS}/${PROJ}
done