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.

Cc: Dave Airlie <airl...@linux.ie>
Signed-off-by: Daniel Vetter <daniel.vet...@intel.com>
---
 dim | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/dim b/dim
index 8e1bfa968e4a..879b74311698 100755
--- a/dim
+++ b/dim
@@ -795,6 +795,50 @@ 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" | while read -r fline; do
+               local fixes_sha1 fixes_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 ; 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
+       done
+
+       return $rv
+}
+
 # additional patch checks before pushing, e.g. for r-b tags
 function checkpatch_commit_push
 {
@@ -837,6 +881,10 @@ function checkpatch_commit_push
                rv=1
        fi
 
+       if ! checkpatch_fixes_tag $sha1 ; then
+               rv=1
+       fi
+
        return $rv
 }
 
-- 
2.20.1

_______________________________________________
dim-tools mailing list
dim-tools@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dim-tools

Reply via email to