contrib/phab-refresh-stack.sh
author Manuel Jacob <me@manueljacob.de>
Thu, 15 Sep 2022 01:48:38 +0200
changeset 49494 c96ed4029fda
parent 48697 fba2d7fab11e
permissions -rwxr-xr-x
templates: add filter to reverse list The filter supports only lists because for lists, it’s straightforward to implement. Reversing text doesn’t seem very useful and is hard to implement. Reversing the bytes would break multi-bytes encodings. Reversing the code points would break characters consisting of multiple code points. Reversing graphemes is non-trivial without using a library not included in the standard library.

#!/bin/bash
set -eu

if [[ "$PHABRICATOR_TOKEN" == "NO-PHAB" ]]; then
    echo 'Skipping Phabricator Step' >&2
    exit 0
fi

revision_in_stack=`hg log \
    --rev '.#stack and ::. and topic()' \
    -T '\nONE-REV\n' \
    | grep 'ONE-REV' | wc -l`
revision_on_phab=`hg log \
    --rev '.#stack and ::. and topic() and desc("re:\nDifferential Revision: [^\n]+D\d+$")'\
    -T '\nONE-REV\n' \
    | grep 'ONE-REV' | wc -l`

if [[ $revision_in_stack -eq 0 ]]; then
    echo "stack is empty" >&2
    exit 0
fi

if [[ $revision_on_phab -eq 0 ]]; then
    echo "no tracked diff in this stack" >&2
    exit 0
fi

if [[ $revision_on_phab -lt $revision_in_stack ]]; then
    echo "not all stack changesets (${revision_in_stack}) have matching Phabricator Diff (${revision_on_phab})" >&2
    exit 2
fi

if [[ "$PHABRICATOR_TOKEN" == "" ]]; then
    echo 'missing $PHABRICATOR_TOKEN variable' >&2
    echo '(use PHABRICATOR_TOKEN="NO-PHAB" to disable this step)' >&2
    exit 2
fi

hg \
--config extensions.phabricator= \
--config phabricator.url=https://phab.mercurial-scm.org/ \
--config phabricator.callsign=HG \
--config auth.phabricator.schemes=https \
--config auth.phabricator.prefix=phab.mercurial-scm.org \
--config auth.phabricator.phabtoken=$PHABRICATOR_TOKEN \
phabsend --rev '.#stack and ::. and topic()' \
"$@"