git-p4: simplify regex pattern generation for parsing diff-tree
It is not clear why a generator was used to create the regex used to parse git-diff-tree output; I assume an early implementation required it, but is not part of the mainline change. Simply use a lazily initialized global instead. Signed-off-by: Yang Zhao <yang.zhao@skyboxlabs.com> Reviewed-by: Ben Keene <seraphire@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2e2aa8d903
commit
ce425eb4e1
13
git-p4.py
13
git-p4.py
@ -544,12 +544,7 @@ def getGitTags():
|
|||||||
gitTags.add(tag)
|
gitTags.add(tag)
|
||||||
return gitTags
|
return gitTags
|
||||||
|
|
||||||
def diffTreePattern():
|
_diff_tree_pattern = None
|
||||||
# This is a simple generator for the diff tree regex pattern. This could be
|
|
||||||
# a class variable if this and parseDiffTreeEntry were a part of a class.
|
|
||||||
pattern = re.compile(':(\d+) (\d+) (\w+) (\w+) ([A-Z])(\d+)?\t(.*?)((\t(.*))|$)')
|
|
||||||
while True:
|
|
||||||
yield pattern
|
|
||||||
|
|
||||||
def parseDiffTreeEntry(entry):
|
def parseDiffTreeEntry(entry):
|
||||||
"""Parses a single diff tree entry into its component elements.
|
"""Parses a single diff tree entry into its component elements.
|
||||||
@ -570,7 +565,11 @@ def parseDiffTreeEntry(entry):
|
|||||||
|
|
||||||
If the pattern is not matched, None is returned."""
|
If the pattern is not matched, None is returned."""
|
||||||
|
|
||||||
match = diffTreePattern().next().match(entry)
|
global _diff_tree_pattern
|
||||||
|
if not _diff_tree_pattern:
|
||||||
|
_diff_tree_pattern = re.compile(':(\d+) (\d+) (\w+) (\w+) ([A-Z])(\d+)?\t(.*?)((\t(.*))|$)')
|
||||||
|
|
||||||
|
match = _diff_tree_pattern.match(entry)
|
||||||
if match:
|
if match:
|
||||||
return {
|
return {
|
||||||
'src_mode': match.group(1),
|
'src_mode': match.group(1),
|
||||||
|
Loading…
Reference in New Issue
Block a user