@@ -353,7 +353,7 @@ def __strip_snippets(self, file: str, wfp: str) -> str:
353
353
self .print_debug (f'Stripped snippet ids from { file } ' )
354
354
return wfp
355
355
356
- def __detect_line_endings (self , contents : bytes ) -> Tuple [bool , bool , bool , bool ]:
356
+ def __detect_line_endings (self , contents : bytes ) -> Tuple [bool , bool , bool ]:
357
357
"""Detect the types of line endings present in file contents.
358
358
359
359
Args:
@@ -369,11 +369,7 @@ def __detect_line_endings(self, contents: bytes) -> Tuple[bool, bool, bool, bool
369
369
# For CR detection, we need to find CR that's not part of CRLF
370
370
has_standalone_cr = b'\r ' in content_without_crlf
371
371
372
- # Check if we have mixed line endings
373
- line_ending_count = sum ([has_crlf , has_standalone_lf , has_standalone_cr ])
374
- has_mixed = line_ending_count > 1
375
-
376
- return has_crlf , has_standalone_lf , has_standalone_cr , has_mixed
372
+ return has_crlf , has_standalone_lf , has_standalone_cr
377
373
378
374
def __calculate_opposite_line_ending_hash (self , contents : bytes ):
379
375
"""Calculate hash for contents with opposite line endings.
@@ -387,7 +383,7 @@ def __calculate_opposite_line_ending_hash(self, contents: bytes):
387
383
Returns:
388
384
Hash with opposite line endings as hex string, or None if no line endings detected.
389
385
"""
390
- has_crlf , has_standalone_lf , has_standalone_cr , has_mixed = self .__detect_line_endings (contents )
386
+ has_crlf , has_standalone_lf , has_standalone_cr = self .__detect_line_endings (contents )
391
387
392
388
if not has_crlf and not has_standalone_lf and not has_standalone_cr :
393
389
return None
@@ -405,21 +401,6 @@ def __calculate_opposite_line_ending_hash(self, contents: bytes):
405
401
406
402
return hashlib .md5 (opposite_contents ).hexdigest ()
407
403
408
- def __should_generate_opposite_hash (self , contents : bytes ) -> bool :
409
- """Determine if an opposite line ending hash (fh2) should be generated.
410
-
411
- Args:
412
- contents: File contents as bytes.
413
-
414
- Returns:
415
- True if fh2 hash should be generated, False otherwise.
416
- """
417
- has_crlf , has_standalone_lf , has_standalone_cr = self .__detect_line_endings (contents )
418
-
419
- # Generate fh2 hash when file has any line endings (CRLF, LF, or CR)
420
- # This allows us to always produce the opposite hash
421
- return has_crlf or has_standalone_lf or has_standalone_cr
422
-
423
404
def wfp_for_contents (self , file : str , bin_file : bool , contents : bytes ) -> str : # noqa: PLR0912, PLR0915
424
405
"""
425
406
Generate a Winnowing fingerprint (WFP) for the given file contents
@@ -451,7 +432,7 @@ def wfp_for_contents(self, file: str, bin_file: bool, contents: bytes) -> str:
451
432
wfp = 'file={0},{1},{2}\n ' .format (file_md5 , content_length , wfp_filename )
452
433
453
434
# Add opposite line ending hash based on line ending analysis
454
- if not bin_file and self . __should_generate_opposite_hash ( contents ) :
435
+ if not bin_file :
455
436
opposite_hash = self .__calculate_opposite_line_ending_hash (contents )
456
437
if opposite_hash is not None :
457
438
wfp += f'fh2={ opposite_hash } \n '
0 commit comments