@@ -471,7 +471,8 @@ async def log(self, path, history_count=10, follow_path=None):
471
471
("-%d" % history_count ),
472
472
]
473
473
if is_single_file :
474
- cmd = cmd + [
474
+ cmd += [
475
+ "-z" ,
475
476
"--numstat" ,
476
477
"--follow" ,
477
478
"--" ,
@@ -485,13 +486,19 @@ async def log(self, path, history_count=10, follow_path=None):
485
486
return {"code" : code , "command" : " " .join (cmd ), "message" : my_error }
486
487
487
488
result = []
488
- if is_single_file :
489
- # an extra newline get outputted when --numstat is used
490
- my_output = my_output .replace ("\n \n " , "\n " )
491
489
line_array = my_output .splitlines ()
492
- i = 0
490
+
491
+ if is_single_file :
492
+ parsed_lines = []
493
+ for line in line_array :
494
+ parsed_lines .extend (
495
+ re .sub (r"\t\0|\0" , "\t " , l )
496
+ for l in line .strip ("\0 \t " ).split ("\0 \0 " , maxsplit = 1 )
497
+ )
498
+ line_array = parsed_lines
499
+
493
500
PREVIOUS_COMMIT_OFFSET = 5 if is_single_file else 4
494
- while i < len (line_array ):
501
+ for i in range ( 0 , len (line_array ), PREVIOUS_COMMIT_OFFSET ):
495
502
commit = {
496
503
"commit" : line_array [i ],
497
504
"author" : line_array [i + 1 ],
@@ -503,11 +510,18 @@ async def log(self, path, history_count=10, follow_path=None):
503
510
if is_single_file :
504
511
commit ["is_binary" ] = line_array [i + 4 ].startswith ("-\t -\t " )
505
512
513
+ # [insertions, deletions, previous_file_path?, current_file_path]
514
+ file_info = line_array [i + 4 ].split ()
515
+
516
+ if len (file_info ) == 4 :
517
+ commit ["previous_file_path" ] = file_info [2 ]
518
+ commit ["file_path" ] = file_info [- 1 ]
519
+
506
520
if i + PREVIOUS_COMMIT_OFFSET < len (line_array ):
507
521
commit ["pre_commit" ] = line_array [i + PREVIOUS_COMMIT_OFFSET ]
508
522
509
523
result .append (commit )
510
- i += PREVIOUS_COMMIT_OFFSET
524
+
511
525
return {"code" : code , "commits" : result }
512
526
513
527
async def detailed_log (self , selected_hash , path ):
@@ -530,6 +544,7 @@ async def detailed_log(self, selected_hash, path):
530
544
line_iterable = iter (strip_and_split (my_output )[1 :])
531
545
for line in line_iterable :
532
546
is_binary = line .startswith ("-\t -\t " )
547
+ previous_file_path = ""
533
548
insertions , deletions , file = line .split ("\t " )
534
549
insertions = insertions .replace ("-" , "0" )
535
550
deletions = deletions .replace ("-" , "0" )
@@ -538,21 +553,25 @@ async def detailed_log(self, selected_hash, path):
538
553
# file was renamed or moved, we need next two lines of output
539
554
from_path = next (line_iterable )
540
555
to_path = next (line_iterable )
556
+ previous_file_path = from_path
541
557
modified_file_name = from_path + " => " + to_path
542
558
modified_file_path = to_path
543
559
else :
544
560
modified_file_name = file .split ("/" )[- 1 ]
545
561
modified_file_path = file
546
562
547
- result .append (
548
- {
549
- "modified_file_path" : modified_file_path ,
550
- "modified_file_name" : modified_file_name ,
551
- "insertion" : insertions ,
552
- "deletion" : deletions ,
553
- "is_binary" : is_binary ,
554
- }
555
- )
563
+ file_info = {
564
+ "modified_file_path" : modified_file_path ,
565
+ "modified_file_name" : modified_file_name ,
566
+ "insertion" : insertions ,
567
+ "deletion" : deletions ,
568
+ "is_binary" : is_binary ,
569
+ }
570
+
571
+ if previous_file_path :
572
+ file_info ["previous_file_path" ] = previous_file_path
573
+
574
+ result .append (file_info )
556
575
total_insertions += int (insertions )
557
576
total_deletions += int (deletions )
558
577
0 commit comments