Subject: Re: [PATCH net v1 2/6] net: dsa: microchip: ksz8: fix ksz8_fdb_dump() to extract all 1024 entries

From: Jakub Kicinski <[email-masked]>
Date: Fri, 24 Mar 2023 09:38:12 -0700

On Fri, 24 Mar 2023 06:35:12 +0100 Oleksij Rempel wrote:
> > Any reason you didn't CC Arun, just an omission or they're no longer
> > @microchip?  
> 
> He is not in MAINTAINERS for drivers/net/dsa/microchip/* even if he is
> practically maintaining it  .. :)

get_maintainer is occasionally useful in pointing out people who wrote
the code but mostly the authors of code under Fixes. I use this little
script usually:

#!/usr/bin/env python3

import argparse
import fileinput
import subprocess
import tempfile
import sys
import os
import re

emailpat = re.compile(r'([^ <"]*@[^ >"]*)')
skip = [email-masked]',
        [email-masked]',
        [email-masked]',
        [email-masked]',
        [email-masked]',
        [email-masked]'}

def do(lines):
    ret = ['---']

    for line in lines:
        line = line.strip()
        if not line:
            continue

        ret.append('# ' + line)

        if "moderated" in line:
            ret.append('# skip, moderated')
            continue

        match = emailpat.search(line)
        if match:
            addr = match.group(1)
            if addr in skip:
                ret.append('# skip, always-cc')

            else:
                ret.append('CC: ' + addr)
        else:
            ret.append('# Bad line')

    return ret

def run(cmd):
    p = subprocess.run(cmd, capture_output=True, check=True)
    return p.stdout.decode("utf-8").strip()

def git_commit_msg():
    return run(["git", "show", "--format=%B", "--no-patch"])

def git_commit(filename):
    return run(["git", "commit", "--amend", "-F", filename])

def git_patch_format():
    return run(["git", "format-patch", "HEAD~", "-o", "/tmp/"])

def get_maint(patch_file):
    return run(["./scripts/get_maintainer.pl",
                "--git-min-percent", "30", patch_file])

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--stdin',
                        help="Read the get_maintainer output from stdin",
                        action='store_true')
    parser.add_argument('--inline', help="Amend HEAD directly",
                        action='store_true')
    args = parser.parse_args()

    if args.stdin:
        out = do(sys.stdin.readlines())
    elif args.inline:
        msg = git_commit_msg()

        patch_file = git_patch_format()
        maint = get_maint(patch_file)
        os.unlink(patch_file)

        out = do(maint.split("\n"))
        out = [l for l in out if l[0] != '#']

        tmpf = tempfile.NamedTemporaryFile(mode='w+', encoding="utf-8")
        tmpf.write(msg + '\n')
        tmpf.write('\n'.join(out))
        tmpf.flush()
        git_commit(tmpf.name)
        tmpf.close()
        out = ["Updated inline: " + msg.split("\n")[0]]
    else:
        patch_file = git_patch_format()
        maint = get_maint(patch_file)
        os.remove(patch_file)

        out = do(maint.split("\n"))

    print('\n'.join(out))

if __name__ == '__main__':
    sys.exit(main())