#!/bin/bash

# set -e

START=2021-01-01
END=2026-01-01

HASHES_W_FIX=$(git log --no-merges --before=2026-01-01 --after=2021-01-01 --grep Fixes: --format='%h' drivers/staging/)

for HASH in $HASHES_W_FIX ; do
    # I don't care about Kconfigs
    if ! git log -1 --name-only --format='' $HASH | egrep -q '\.[ch]' ; then
        continue
    fi

    # head -n1 so we only look at the first hash (lazy)
    LINE=$(git log -1 $HASH | egrep '    Fixes:' | head -n1)

    TAG=$(echo $LINE | cut -d : -f 2 | cut -d '(' -f 1)
    # a couple tags are bad.  check if they exist
    if ! git cat-file -e $TAG 2> /dev/null ; then
        continue
    fi

    AUTHOR=$(git log -1 --format='%an' $TAG)

    if git log -1 --name-status $TAG | grep ^A | egrep '\.[ch]$' | grep -q "A" ; then
        echo NEW $HASH $LINE
    else
        echo OLD $HASH $LINE
    fi
done


