From dc689be9fe29b5a6bbd777220e49eef01c522f57 Mon Sep 17 00:00:00 2001 From: Daniel Vetter <daniel.vetter@ffwll.ch> Date: Fri, 8 Feb 2019 11:43:45 +0100 Subject: [PATCH] dim: basic Fixes: check Somewhat inspired by Stephen Rotwell's code, but because random unfriendly encounters with bash it ended up looking quite a bit different. Also only really checks sha1 for now, but that should be good enough. v2: Actually forward the error code from the subshell (which was automatically created because of the pipeline, now I made it explicit). Spotted by shellcheck, somehow I didn't notice that my checks didn't actually abort the pull in my testing. v3: - quiet some noise in the output - also check sha1 length and whether the subject matches. That latter check is a bit more strict than what sfr uses, but matches what dim cite produces. Cc: Dave Airlie <airlied@linux.ie> Acked-by: Dave Airlie <airlied@linux.ie> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> --- dim | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/dim b/dim index 4ee94fc..10f8232 100755 --- a/dim +++ b/dim @@ -795,6 +795,66 @@ function dim_rebuild_tip commit_rerere_cache } +function checkpatch_fixes_tag +{ + local sha1 fixes_lines cite rv fline + + sha1=$1 + rv=0 + fixes_lines=$(git log -1 --format='%B' "$sha1" | grep -i '^[[:space:]]*Fixes:') + cite=$(dim_cite $sha1) + + echo "$fixes_lines" | ( local rv; rv=0 ; while read -r fline; do + local fixes_sha1 fixes_subject orig_subject + if [[ -z "$fline" ]] ; then + continue + fi + + [[ "$fline" =~ ^[[:space:]]*[Ff][Ii][Xx][Ee][Ss]:[[:space:]]*(.*)$ ]] + fline="${BASH_REMATCH[1]}" + + if [[ ! "$fline" =~ ^[[:space:]]*([[:xdigit:]]{5,})[[:space:]]*(.*)$ ]]; then + echoerr "$cite: Malformed fixes line:" + echoerr " $fline" + rv=1 + continue + fi + fixes_sha1="${BASH_REMATCH[1]}" + fixes_subject="${BASH_REMATCH[2]}" + + if ! git rev-parse --verify -q $fixes_sha1 > /dev/null ; then + echoerr "$cite: SHA1 in fixes line not found:" + echoerr " $fline" + rv=1 + continue + fi + if ! git merge-base --is-ancestor $fixes_sha1 $sha1 ; then + echoerr "$cite: Fixes: SHA1 in not pointing at an ancestor:" + echoerr " $fline" + rv=1 + continue + fi + if ! echo $fixes_sha1 | grep -q '[[:xdigit:]]\{12\}' ; then + echoerr "$cite: Fixes: SHA1 needs at least 12 digits:" + echoerr " $fline" + rv=1 + continue + fi + orig_subject=$(git show -s $fixes_sha1 --format="format:%s") + if [[ "$fixes_subject" != "(\"$orig_subject\")" ]] ; then + echoerr "$cite: Subject in fixes line doesn't match referenced commit:" + echoerr " $fline" + rv=1 + continue + fi + + done ; exit $rv ) + + rv=$? + + return $rv +} + # additional patch checks before pushing, e.g. for r-b tags function checkpatch_commit_push { @@ -844,6 +904,10 @@ function checkpatch_commit_push rv=1 fi + if ! checkpatch_fixes_tag $sha1 ; then + rv=1 + fi + return $rv } -- GitLab