Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Install Python programs
run: pip install ruff
- name: Install shellcheck and checkbashisms
run: sudo apt install shellcheck devscripts
run: sudo apt install shfmt shellcheck devscripts
- name: Check style
run: make check-style
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ test:
clean:
${MAKE} -C tests clean

check-style: check-python-style shell-script-style
check-style: python-style-check shell-style-check

PYTHON_FILES=$(wildcard *.py)

python-style:
python-style-fix:
ruff format ${PYTHON_FILES}
ruff check ${PYTHON_FILES} --fix

check-python-style:
python-style-check:
ruff format ${PYTHON_FILES}
ruff check ${PYTHON_FILES} --fix

SH_SCRIPTS = $(shell grep -r -l '^\#!/bin/sh' * | grep -v .git | grep -v "~" | grep -v cronic-orig)
BASH_SCRIPTS = $(shell grep -r -l '^\#!/bin/bash' * | grep -v .git | grep -v "~" | grep -v cronic-orig)

shell-script-style:
shellcheck --format=gcc ${SH_SCRIPTS} ${BASH_SCRIPTS}
checkbashisms ${SH_SCRIPTS}
shell-style-fix:
shfmt -w -i 2 -ci -bn ${SH_SCRIPTS} ${BASH_SCRIPTS}
shellcheck -x -P SCRIPTDIR --format=diff ${SH_SCRIPTS} ${BASH_SCRIPTS} | patch -p1

shell-style-check:
shfmt -d -i 2 -ci -bn ${SH_SCRIPTS} ${BASH_SCRIPTS}
shellcheck -x -P SCRIPTDIR --format=gcc ${SH_SCRIPTS} ${BASH_SCRIPTS}
checkbashisms -l ${SH_SCRIPTS} /dev/null

showvars:
@echo "PYTHON_FILES=${PYTHON_FILES}"
Expand Down
41 changes: 19 additions & 22 deletions ediff-merge-script
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@
_EMACSCLIENT=emacs
# _EMACSCLIENT=emacsclient


# This script is originally from
# http://stackoverflow.com/questions/1817370/using-ediff-as-git-mergetool
# I have extended so it handles both emacs and emacsclient,
# and made other improvements.


# test args
if [ ! ${#} -ge 3 ]; then
echo 1>&2 "Error: ${0} requires 4 arguments, got ${#}"
echo 1>&2 "Usage: ${0} LOCAL REMOTE MERGED BASE"
echo 1>&2 " (LOCAL, REMOTE, MERGED, BASE can be provided by \`git mergetool'.)"
exit 1
echo 1>&2 "Error: ${0} requires 4 arguments, got ${#}"
echo 1>&2 "Usage: ${0} LOCAL REMOTE MERGED BASE"
echo 1>&2 " (LOCAL, REMOTE, MERGED, BASE can be provided by \`git mergetool'.)"
exit 1
fi

# tools
Expand All @@ -41,13 +39,13 @@ _MKTEMP="/bin/mktemp"
_LOCAL=${1}
_REMOTE=${2}
_MERGED=${3}
if [ -r "${4}" ] ; then
_BASE=${4}
_EDIFF=ediff-merge-files-with-ancestor
_EVAL="(${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" \"${_BASE}\" nil \"${_MERGED}\")"
if [ -r "${4}" ]; then
_BASE=${4}
_EDIFF=ediff-merge-files-with-ancestor
_EVAL="(${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" \"${_BASE}\" nil \"${_MERGED}\")"
else
_EDIFF=ediff-merge-files
_EVAL="(${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" nil \"${_MERGED}\")"
_EDIFF=ediff-merge-files
_EVAL="(${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" nil \"${_MERGED}\")"
fi

_EVAL_PREFIX="(defun ediff-write-merge-buffer ()\
Expand All @@ -62,10 +60,10 @@ if [[ $_EMACSCLIENT == *"emacsclient"* ]]; then
## emacsclient only, not emacs
# console vs. X
if [ "${TERM}" = "linux" ]; then
unset DISPLAY
_EMACSCLIENTOPTS='-t -a \"\"'
unset DISPLAY
_EMACSCLIENTOPTS='-t -a \"\"'
else
_EMACSCLIENTOPTS="-c -a \"\""
_EMACSCLIENTOPTS="-c -a \"\""
fi
else
## emacs only, not emacsclient
Expand All @@ -77,15 +75,14 @@ fi
# echo "${_EMACSCLIENT}" "${_EMACSCLIENTOPTS}" --eval "(progn ${_EVAL_PREFIX} ${_EVAL_PREFIX2} ${_EVAL})"
"${_EMACSCLIENT}" "${_EMACSCLIENTOPTS}" --eval "(progn ${_EVAL_PREFIX} ${_EVAL_PREFIX2} ${_EVAL})" 2>&1


# check modified file
if [ ! "$("${_EGREP}" -c '^(<<<<<<<|=======|>>>>>>>|####### Ancestor)$' "${_MERGED}")" = 0 ]; then
_MERGEDSAVE=$(${_MKTEMP} --tmpdir "$(${_BASENAME} "${_MERGED}").XXXXXXXXXX")
${_CP} "${_MERGED}" "${_MERGEDSAVE}"
echo 1>&2 "Oops! Conflict markers detected in $_MERGED."
echo 1>&2 "Saved your changes to ${_MERGEDSAVE}"
echo 1>&2 "Exiting with code 1."
exit 1
_MERGEDSAVE=$(${_MKTEMP} --tmpdir "$(${_BASENAME} "${_MERGED}").XXXXXXXXXX")
${_CP} "${_MERGED}" "${_MERGEDSAVE}"
echo 1>&2 "Oops! Conflict markers detected in $_MERGED."
echo 1>&2 "Saved your changes to ${_MERGEDSAVE}"
echo 1>&2 "Exiting with code 1."
exit 1
fi

# It would not be appropriate for this script to do the merge, because
Expand Down
68 changes: 34 additions & 34 deletions git-authors
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
# --texinfo Use Texinfo escape sequences for accented characters

while :; do
case $1 in
--punctuation)
punctuation=1
;;
--html)
html=1
;;
--latex)
latex=1
;;
--texinfo)
texinfo=1
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
case $1 in
--punctuation)
punctuation=1
;;
--html)
html=1
;;
--latex)
latex=1
;;
--texinfo)
texinfo=1
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break ;;
esac

shift
shift
done

# shellcheck disable=SC2091 # Result is "true" or "false", surround with $(...) to interpret it.
Expand All @@ -44,13 +44,13 @@ if $(git rev-parse --is-shallow-repository); then
git fetch --unshallow --quiet
fi
# shellcheck disable=SC2015 # sed won't fail.
git log | grep '^\(Author\| Co-authored-by\):' | \
sed -E 's/(Author| Co-authored-by): (.*)/\2/' | sed -E 's/(.*) <.*>/\1/' | \
grep -v '^renovate\[bot\]$' | \
LC_ALL=C sort -u | \
sed -f "$(dirname "$0")"/git-authors.sed | LC_ALL=C sort -u | \
( [ -n "${html+x}" ] && sed -e "s/á/\\&aacute;/" -e "s/é/\\&eacute;/" -e "s/ß/\\&szlig;/" || cat ) | \
( [ -n "${latex+x}" ] && sed -e "s/á/\\\\'a/" -e "s/é/\\\\'e/" -e "s/ß/\\\\ss /" || cat ) | \
( [ -n "${texinfo+x}" ] && sed -e "s/á/@'a/" -e "s/é/@'e/" -e "s/ß/@ss /" || cat ) | \
( [ -n "${punctuation+x}" ] && sed -e 's/$/,/' -e '$ s/,$/./' || cat ) | \
cat
git log | grep '^\(Author\| Co-authored-by\):' \
| sed -E 's/(Author| Co-authored-by): (.*)/\2/' | sed -E 's/(.*) <.*>/\1/' \
| grep -v '^renovate\[bot\]$' \
| LC_ALL=C sort -u \
| sed -f "$(dirname "$0")"/git-authors.sed | LC_ALL=C sort -u \
| ([ -n "${html+x}" ] && sed -e "s/á/\\&aacute;/" -e "s/é/\\&eacute;/" -e "s/ß/\\&szlig;/" || cat) \
| ([ -n "${latex+x}" ] && sed -e "s/á/\\\\'a/" -e "s/é/\\\\'e/" -e "s/ß/\\\\ss /" || cat) \
| ([ -n "${texinfo+x}" ] && sed -e "s/á/@'a/" -e "s/é/@'e/" -e "s/ß/@ss /" || cat) \
| ([ -n "${punctuation+x}" ] && sed -e 's/$/,/' -e '$ s/,$/./' || cat) \
| cat
56 changes: 32 additions & 24 deletions git-clone-related
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
# Fail if any command fails.
set +e

if [ "$1" = "--debug" ] ; then
if [ "$1" = "--debug" ]; then
DEBUG=1
shift
set -x
fi

# FALLBACK_BRANCH may be unset.
if [ "$1" = "--upstream-branch" ] ; then
if [ "$1" = "--upstream-branch" ]; then
shift
FALLBACK_BRANCH=$1
shift
Expand All @@ -61,13 +61,19 @@ if [ "$#" -lt 2 ]; then
exit 1
fi

beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
beginswith() { case $2 in "$1"*) true ;; *) false ;; esac }

UPSTREAM_ORG=$1; shift
REPO_NAME=$1; shift
UPSTREAM_ORG=$1
shift
REPO_NAME=$1
shift
if [ "$#" -ne 0 ] && ! beginswith "-" "$1"; then
DESTINATION=$1; shift
if [ -d "$DESTINATION" ] && [ "$(pwd -P)" = "$(cd "$DESTINATION"; pwd -P)" ]; then
DESTINATION=$1
shift
if [ -d "$DESTINATION" ] && [ "$(pwd -P)" = "$(
cd "$DESTINATION"
pwd -P
)" ]; then
echo "git-clone-related: destination is same as current directory"
exit 1
fi
Expand All @@ -82,7 +88,7 @@ if [ "$#" -eq 0 ]; then
set -- -q --single-branch --depth 1
fi

if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "Entering git-clone-related $UPSTREAM_ORG $REPO_NAME $DESTINATION $*"
fi

Expand All @@ -101,49 +107,49 @@ else
SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)"

CI_INFO="$SCRIPTDIR/../plume-scripts/ci-info"
if [ ! -f "$CI_INFO" ] ; then
if [ ! -f "$CI_INFO" ]; then
CI_INFO="$SCRIPTDIR/../.plume-scripts/ci-info"
fi
if [ ! -f "$CI_INFO" ] ; then
if [ ! -f "$CI_INFO" ]; then
CI_INFO="$SCRIPTDIR/.plume-scripts/ci-info"
fi
if [ ! -f "$CI_INFO" ] ; then
if [ ! -f "$CI_INFO" ]; then
(cd "$SCRIPTDIR" && git clone --depth 1 https://github.com/plume-lib/plume-scripts .plume-scripts)
fi
if [ ! -f "$CI_INFO" ] ; then
if [ ! -f "$CI_INFO" ]; then
echo "CI_INFO does not exist: $CI_INFO"
exit 1
fi

if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "About to run ci-info --debug"
"${CI_INFO}" --debug "${UPSTREAM_ORG}"
echo "Ran ci-info --debug"
echo "About to run ci-info"
fi

eval "$("${CI_INFO}" "${UPSTREAM_ORG}")"
if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "Finished running ci-info"
fi
UPSTREAM_REPO_URL="https://github.com/${UPSTREAM_ORG}/${REPO_NAME}.git"

if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "About to run git-find-fork" "${CI_ORGANIZATION}" "${UPSTREAM_ORG}" "${REPO_NAME}"
fi
# REPO_URL is what will be cloned. It might be the same as UPSTREAM_REPO_URL.
REPO_URL=$("${SCRIPTDIR}"/git-find-fork "${CI_ORGANIZATION}" "${UPSTREAM_ORG}" "${REPO_NAME}")
if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "git-find-fork ${CI_ORGANIZATION} ${UPSTREAM_ORG} ${REPO_NAME} => ${REPO_URL}"
fi
if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "About to run git-find-branch" "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"}
fi
REPO_BRANCH=$("${SCRIPTDIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"})
if [ -n "$DEBUG" ] ; then
if [ -n "$DEBUG" ]; then
echo "git-find-branch ${REPO_URL} ${CI_BRANCH_NAME} => ${REPO_BRANCH}"
fi
if [ "$UPSTREAM_REPO_URL" != "$REPO_URL" ] && [ "$REPO_BRANCH" != "$CI_BRANCH_NAME" ] ; then
if [ "$UPSTREAM_REPO_URL" != "$REPO_URL" ] && [ "$REPO_BRANCH" != "$CI_BRANCH_NAME" ]; then
## Don't use the fallback branch (e.g., master) of the downstream repo
REPO_URL="$UPSTREAM_REPO_URL"
REPO_BRANCH=$("${SCRIPTDIR}"/git-find-branch "${REPO_URL}" "${CI_BRANCH_NAME}" ${FALLBACK_BRANCH:+"$FALLBACK_BRANCH"})
Expand All @@ -152,10 +158,12 @@ else
# Try twice in case of network lossage.
timeout 60 git clone --depth 1 -b "${REPO_BRANCH}" "$@" "${REPO_URL}" "${DESTINATION}" \
|| { echo "Retrying 'git clone ... ${REPO_URL} ${DESTINATION}' after timeout" \
&& rm -rf "${DESTINATION}" \
&& sleep 60 \
&& { timeout 60 git clone --depth 1 -b "${REPO_BRANCH}" "$@" "${REPO_URL}" "${DESTINATION}" \
|| { echo "git-clone-related: failed: git clone --depth 1 -b ${REPO_BRANCH}" "$@" "${REPO_URL} ${DESTINATION}";
exit 2; } } }
&& rm -rf "${DESTINATION}" \
&& sleep 60 \
&& { timeout 60 git clone --depth 1 -b "${REPO_BRANCH}" "$@" "${REPO_URL}" "${DESTINATION}" \
|| {
echo "git-clone-related: failed: git clone --depth 1 -b ${REPO_BRANCH}" "$@" "${REPO_URL} ${DESTINATION}"
exit 2
}; }; }
fi
echo "git-clone-related: ${DESTINATION} is at $(cd "${DESTINATION}" && git rev-parse HEAD)"
8 changes: 4 additions & 4 deletions git-find-branch
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ REPO_URL=$1
shift

for BRANCH in "$@"; do
if (git ls-remote --quiet --exit-code --heads "${REPO_URL}" "${BRANCH}" > /dev/null) ; then
echo "${BRANCH}"
exit 0
fi
if (git ls-remote --quiet --exit-code --heads "${REPO_URL}" "${BRANCH}" >/dev/null); then
echo "${BRANCH}"
exit 0
fi
done

git ls-remote --symref "${REPO_URL}" HEAD | awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}'
15 changes: 7 additions & 8 deletions git-find-fork
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# Often, you can use the `git-clone-related` script instead of this one.

if [ "$#" -ne 3 ]; then
script=$(basename -- "$0")
>&2 echo "Error: $script requires 3 arguments, got $#"
>&2 echo "Usage: $script ORG UPSTREAM_ORG REPONAME"
exit 1
script=$(basename -- "$0")
>&2 echo "Error: $script requires 3 arguments, got $#"
>&2 echo "Usage: $script ORG UPSTREAM_ORG REPONAME"
exit 1
fi

ORG=$1
Expand All @@ -25,10 +25,9 @@ REPONAME=$3
# export GITEXISTS="git ls-remote"
export GITEXISTS="wget -q --spider"


if ( ${GITEXISTS} "https://github.com/${ORG}/${REPONAME}.git" > /dev/null ); then
OWNER="${ORG}"
if (${GITEXISTS} "https://github.com/${ORG}/${REPONAME}.git" >/dev/null); then
OWNER="${ORG}"
else
OWNER="${UPSTREAM_ORG}"
OWNER="${UPSTREAM_ORG}"
fi
echo "https://github.com/${OWNER}/${REPONAME}.git"
Loading