forked from cncf/gitdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatterns.py
executable file
·61 lines (58 loc) · 2.56 KB
/
patterns.py
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
#
# -*- coding:utf-8 -*-
# Pull together regular expressions used in multiple places.
#
# This code is part of the LWN git data miner.
#
# Copyright 2007-11 Eklektix, Inc.
# Copyright 2007-11 Jonathan Corbet <[email protected]>
# Copyright 2011 Germán Póo-Caamaño <[email protected]>
#
# This file may be distributed under the terms of the GNU General
# Public License, version 2.
#
import re
#
# Some people, when confronted with a problem, think "I know, I'll use regular
# expressions." Now they have two problems.
# -- Jamie Zawinski
#
_pemail = r'\s+"?([^<"]+)"?\s<([^>]+)>' # just email addr + name
# LG: added re.I in some cases (need to ignore case)
patterns = {
'email_encode': re.compile(r'[^\s@]+@[^\s@]+'),
'email_decode': re.compile(r'[^\s!]+![^\s!]+'),
'tagcommit': re.compile (r'^commit ([\da-f]+) .*tag: (v[0-9]\.\d(\.\d\d?)?)'), # LG: allow versions v[0-9].n[...]
'commit': re.compile (r'^commit ([0-9a-f ]+)'),
'author': re.compile (r'^Author:' + _pemail + '$', re.I),
'date': re.compile (r'^Date: '),
'signed-off-by': re.compile (r'^\s+Signed-off-by:' + _pemail + '.*$', re.I),
'merge': re.compile (r'^Merge:.*$'),
'add': re.compile (r'^\+[^+].*$'),
'rem': re.compile (r'^-[^-].*$'),
'date': re.compile (r'^(Commit)?Date:\s+(.*)$'),
# filea, fileb are used only in 'parche mode' (-p)
'filea': re.compile (r'^---\s+(.*)$'),
'fileb': re.compile (r'^\+\+\+\s+(.*)$'),
'reviewed-by': re.compile (r'^\s+Reviewed-by:' + _pemail+ '.*$', re.I),
'tested-by': re.compile (r'^\s+tested-by:' + _pemail + '.*$', re.I),
'reported-by': re.compile (r'^\s+Reported-by:' + _pemail + '.*$', re.I),
'reported-and-tested-by': re.compile (r'^\s+reported-and-tested-by:' + _pemail + '.*$', re.I),
#
# Merges are described with a variety of lines.
#
'ExtMerge': re.compile(r'^ +Merge( branch .* of)? ([^ ]+:[^ ]+)\n$'),
'IntMerge': re.compile(r'^ +(Merge|Pull) .* into .*$'),
# PIntMerge2 = re.compile(r"^ +Merge branch(es)? '.*$"),
'IntMerge2': re.compile(r"^ +Merge .*$"),
# Another way to get the statistics (per file).
# It implies --numstat
'numstat': re.compile('^(\d+|-)\s+(\d+|-)\s+(.*)$'),
'rename' : re.compile('(.*)\{(.*) => (.*)\}(.*)'),
# Detect errors on svn conversions
'svn-tag': re.compile("^svn path=/tags/(.*)/?; revision=([0-9]+)$"),
}
def email_encode(line):
return re.sub(patterns['email_encode'], lambda email: email.group().replace('@', '!'), line)
def email_decode(line):
return re.sub(patterns['email_decode'], lambda email: email.group().replace('!', '@'), line)