Skip to content

Commit ce425eb

Browse files
yangskyboxlabsgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Ben Keene <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e2aa8d commit ce425eb

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

git-p4.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,7 @@ def getGitTags():
544544
gitTags.add(tag)
545545
return gitTags
546546

547-
def diffTreePattern():
548-
# This is a simple generator for the diff tree regex pattern. This could be
549-
# a class variable if this and parseDiffTreeEntry were a part of a class.
550-
pattern = re.compile(':(\d+) (\d+) (\w+) (\w+) ([A-Z])(\d+)?\t(.*?)((\t(.*))|$)')
551-
while True:
552-
yield pattern
547+
_diff_tree_pattern = None
553548

554549
def parseDiffTreeEntry(entry):
555550
"""Parses a single diff tree entry into its component elements.
@@ -570,7 +565,11 @@ def parseDiffTreeEntry(entry):
570565
571566
If the pattern is not matched, None is returned."""
572567

573-
match = diffTreePattern().next().match(entry)
568+
global _diff_tree_pattern
569+
if not _diff_tree_pattern:
570+
_diff_tree_pattern = re.compile(':(\d+) (\d+) (\w+) (\w+) ([A-Z])(\d+)?\t(.*?)((\t(.*))|$)')
571+
572+
match = _diff_tree_pattern.match(entry)
574573
if match:
575574
return {
576575
'src_mode': match.group(1),

0 commit comments

Comments
 (0)