33import os
44import re
55import sys
6+ from itertools import islice
67from typing import Any
78
89from commitizen import factory , git , out
@@ -34,7 +35,6 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
3435 self .max_msg_length : int = arguments .get ("message_length_limit" , 0 )
3536
3637 # we need to distinguish between None and [], which is a valid value
37-
3838 allowed_prefixes = arguments .get ("allowed_prefixes" )
3939 self .allowed_prefixes : list [str ] = (
4040 allowed_prefixes
@@ -44,7 +44,7 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
4444
4545 self ._valid_command_argument ()
4646
47- self .config : BaseConfig = config
47+ self .config = config
4848 self .encoding = config .settings ["encoding" ]
4949 self .cz = factory .committer_factory (self .config )
5050
@@ -73,11 +73,9 @@ def __call__(self):
7373
7474 pattern = self .cz .schema_pattern ()
7575 displayed_msgs_content = "\n " .join (
76- [
77- f'commit "{ commit .rev } ": "{ commit .message } "'
78- for commit in commits
79- if not self .validate_commit_message (commit .message , pattern )
80- ]
76+ f'commit "{ commit .rev } ": "{ commit .message } "'
77+ for commit in commits
78+ if not self .validate_commit_message (commit .message , pattern )
8179 )
8280 if displayed_msgs_content :
8381 raise InvalidCommitMessageError (
@@ -126,14 +124,18 @@ def _filter_comments(msg: str) -> str:
126124 Returns:
127125 The filtered commit message without comments.
128126 """
129-
130- lines = []
131- for line in msg .split ("\n " ):
132- if "# ------------------------ >8 ------------------------" in line :
133- break
134- if not line .startswith ("#" ):
135- lines .append (line )
136- return "\n " .join (lines )
127+ msg_lines = msg .split ("\n " )
128+ cutoff = next (
129+ (
130+ i
131+ for i , line in enumerate (msg_lines )
132+ if "# ------------------------ >8 ------------------------" in line
133+ ),
134+ len (msg_lines ),
135+ )
136+ return "\n " .join (
137+ line for line in islice (msg_lines , cutoff ) if not line .startswith ("#" )
138+ )
137139
138140 def validate_commit_message (self , commit_msg : str , pattern : str ) -> bool :
139141 if not commit_msg :
0 commit comments