aboutsummaryrefslogtreecommitdiffstats
path: root/find-orig-patch
blob: bc0188143417abf211b20ce6f3b67fea825ee3bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright 2023 Google LLC

import argparse

from stable_utils import *

parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=
"""Finds the original patch email from a git commit.  Uses the message ID from
the commit message if possible, otherwise falls back to a search of
lore.kernel.org by commit title.""")
parser.add_argument('commit_id')
parser.add_argument('--msgid', action='store_true',
                    help='just output the message ID')
parser.add_argument('--link', action='store_true',
                    help='just output a lore link')
args = parse_args(parser)

commit = Commit(args.commit_id)
message_id = commit.find_original_email()
if not message_id:
    error(f'Cannot find original patch for {commit}')

if args.msgid:
    print(message_id)
elif args.link:
    print(f'{config.lore}/r/{message_id}')
else:
    raw_message = fetch_raw_message(message_id)
    sys.stdout.buffer.write(raw_message)