@@ -67,12 +67,15 @@ def collect_commit_range_diff_documents(
6767 commit_documents_to_scan = []
6868
6969 repo = git_proxy .get_repo (path )
70- total_commits_count = int (repo .git .rev_list ('--count' , commit_range ))
71- logger .debug ('Calculating diffs for %s commits in the commit range %s' , total_commits_count , commit_range )
70+
71+ normalized_commit_range = normalize_commit_range (commit_range , path )
72+
73+ total_commits_count = int (repo .git .rev_list ('--count' , normalized_commit_range ))
74+ logger .debug ('Calculating diffs for %s commits in the commit range %s' , total_commits_count , normalized_commit_range )
7275
7376 progress_bar .set_section_length (ScanProgressBarSection .PREPARE_LOCAL_FILES , total_commits_count )
7477
75- for scanned_commits_count , commit in enumerate (repo .iter_commits (rev = commit_range )):
78+ for scanned_commits_count , commit in enumerate (repo .iter_commits (rev = normalized_commit_range )):
7679 if _does_reach_to_max_commits_to_scan_limit (commit_ids_to_scan , max_commits_count ):
7780 logger .debug ('Reached to max commits to scan count. Going to scan only %s last commits' , max_commits_count )
7881 progress_bar .update (ScanProgressBarSection .PREPARE_LOCAL_FILES , total_commits_count - scanned_commits_count )
@@ -96,7 +99,12 @@ def collect_commit_range_diff_documents(
9699
97100 logger .debug (
98101 'Found all relevant files in commit %s' ,
99- {'path' : path , 'commit_range' : commit_range , 'commit_id' : commit_id },
102+ {
103+ 'path' : path ,
104+ 'commit_range' : commit_range ,
105+ 'normalized_commit_range' : normalized_commit_range ,
106+ 'commit_id' : commit_id ,
107+ },
100108 )
101109
102110 logger .debug ('List of commit ids to scan, %s' , {'commit_ids' : commit_ids_to_scan })
@@ -428,8 +436,8 @@ def get_pre_commit_modified_documents(
428436 return git_head_documents , pre_committed_documents , diff_documents
429437
430438
431- def parse_commit_range (commit_range : str , path : str ) -> tuple [Optional [str ], Optional [str ]]:
432- """Parses a git commit range string and returns the full SHAs for the 'from' and 'to' commits.
439+ def parse_commit_range (commit_range : str , path : str ) -> tuple [Optional [str ], Optional [str ], Optional [ str ] ]:
440+ """Parses a git commit range string and returns the full SHAs for the 'from' and 'to' commits as well as the separator .
433441
434442 Supports:
435443 - 'from..to'
@@ -442,8 +450,10 @@ def parse_commit_range(commit_range: str, path: str) -> tuple[Optional[str], Opt
442450
443451 if '...' in commit_range :
444452 from_spec , to_spec = commit_range .split ('...' , 1 )
453+ separator = '...'
445454 elif '..' in commit_range :
446455 from_spec , to_spec = commit_range .split ('..' , 1 )
456+ separator = '..'
447457 else :
448458 # Git commands like 'git diff <commit>' compare against HEAD.
449459 from_spec = commit_range
@@ -459,7 +469,32 @@ def parse_commit_range(commit_range: str, path: str) -> tuple[Optional[str], Opt
459469 # Use rev_parse to resolve each specifier to its full commit SHA
460470 from_commit_rev = repo .rev_parse (from_spec ).hexsha
461471 to_commit_rev = repo .rev_parse (to_spec ).hexsha
462- return from_commit_rev , to_commit_rev
472+ return from_commit_rev , to_commit_rev , separator
463473 except git_proxy .get_git_command_error () as e :
464474 logger .warning ("Failed to parse commit range '%s'" , commit_range , exc_info = e )
465- return None , None
475+ return None , None , None
476+
477+ def normalize_commit_range (commit_range : str , path : str ) -> str :
478+ """Normalize a commit range string to handle various formats consistently with all scan types.
479+
480+ Returns:
481+ A normalized commit range string suitable for Git operations (e.g., 'full_sha1..full_sha2')
482+ """
483+ from_commit_rev , to_commit_rev , separator = parse_commit_range (commit_range , path )
484+ if from_commit_rev is None or to_commit_rev is None :
485+ logger .warning (
486+ 'Failed to parse commit range "%s", falling back to raw string. This may cause unexpected behavior.' ,
487+ commit_range
488+ )
489+ # Fall back to using the raw commit_range string
490+ return commit_range
491+
492+ # Construct a normalized range string using the original separator for iter_commits
493+ # This preserves the semantics of two-dot vs three-dot syntax
494+ normalized_commit_range = f'{ from_commit_rev } { separator } { to_commit_rev } '
495+ logger .debug (
496+ 'Normalized commit range "%s" to "%s"' ,
497+ commit_range ,
498+ normalized_commit_range ,
499+ )
500+ return normalized_commit_range
0 commit comments