mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +02:00
precompile regex patterns
This commit is contained in:
@ -148,6 +148,8 @@ import re
|
|||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
import jc.utils
|
import jc.utils
|
||||||
|
|
||||||
|
hash_pattern = re.compile(r'([0-9]|[a-f])+')
|
||||||
|
changes_pattern = re.compile(r'\s(?P<files>\d+)\s+(files? changed),\s+(?P<insertions>\d+)\s(insertions?\(\+\))?(,\s+)?(?P<deletions>\d+)?(\s+deletions?\(\-\))?')
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
@ -194,8 +196,7 @@ def _is_commit_hash(hash_string: str) -> bool:
|
|||||||
if len(hash_string) != 40:
|
if len(hash_string) != 40:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hash_pattern = r'([0-9]|[a-f])+'
|
if hash_pattern.match(hash_string):
|
||||||
if re.match(hash_pattern, hash_string):
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -304,8 +305,7 @@ def parse(
|
|||||||
|
|
||||||
if line.startswith(' ') and 'changed, ' in line:
|
if line.startswith(' ') and 'changed, ' in line:
|
||||||
# this is the stat summary
|
# this is the stat summary
|
||||||
changes_pattern = r'\s(?P<files>\d+)\s+(files? changed),\s+(?P<insertions>\d+)\s(insertions?\(\+\))?(,\s+)?(?P<deletions>\d+)?(\s+deletions?\(\-\))?'
|
changes = changes_pattern.match(line)
|
||||||
changes = re.match(changes_pattern, line)
|
|
||||||
if changes:
|
if changes:
|
||||||
files = changes['files']
|
files = changes['files']
|
||||||
insertions = changes['insertions']
|
insertions = changes['insertions']
|
||||||
|
Reference in New Issue
Block a user