path: root/
diff options
authorYang Zhao <>2019-12-13 23:52:46 (GMT)
committerJunio C Hamano <>2020-01-15 20:53:40 (GMT)
commitce425eb4e16e5038ffc322cbafc80d641b0ad5eb (patch)
treef44e17fb001d8d1b99fae4658d3242c056d8624d /
parent2e2aa8d9032ccdfdecaab51c60c5bada517f60bc (diff)
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 <> Reviewed-by: Ben Keene <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to '')
1 files changed, 6 insertions, 7 deletions
diff --git a/ b/
index b7e31d4..3af8df9 100755
--- a/
+++ b/
@@ -544,12 +544,7 @@ def getGitTags():
return gitTags
-def diffTreePattern():
- # 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
+_diff_tree_pattern = None
def parseDiffTreeEntry(entry):
"""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."""
- 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:
return {