-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpatch.py
More file actions
63 lines (49 loc) · 1.58 KB
/
Copy pathpatch.py
File metadata and controls
63 lines (49 loc) · 1.58 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2019 Netronome Systems, Inc.
""" Patch representation """
# TODO: document
import re
from email import message_from_string
import core
class Patch:
"""Patch class
Class representing a patch with references to postings etc.
Attributes
----------
raw_patch : str
The entire patch as a string, including commit message, diff, etc.
title : str
The Subject line/first line of the commit message of the patch.
Methods
-------
write_out(fp)
Write the raw patch into the given file pointer.
"""
PATCH_ID_GEN = 0
def __init__(self, raw_patch, ident=None, title="", series=None):
self.raw_patch = raw_patch
self.title = title
self.subject = ""
self.series = series
# Whether the patch is first in the series, set by series.add_patch()
self.first_in_series = None
msg = message_from_string(raw_patch)
self.subject = msg['Subject'] or ""
if not self.title:
subj = re.search(r'\[.*\](.*)', self.subject)
if subj:
self.title = subj.group(1).strip()
else:
self.title = self.subject
core.log_open_sec("Patch init: " + self.title)
core.log_end_sec()
if ident is not None:
self.id = ident
else:
Patch.PATCH_ID_GEN += 1
self.id = Patch.PATCH_ID_GEN
def write_out(self, fp):
""" Write patch contents to a file """
fp.write(self.raw_patch.encode('utf-8'))
fp.flush()