@@ -322,58 +322,55 @@ async def log(self, current_path, history_count=10):
322
322
323
323
async def detailed_log (self , selected_hash , current_path ):
324
324
"""
325
- Execute git log -1 --stat -- numstat --oneline -z command (used to get
325
+ Execute git log -1 --numstat --oneline -z command (used to get
326
326
insertions & deletions per file) & return the result.
327
327
"""
328
- cmd = ["git" , "log" , "-1" , "--stat" , "-- numstat" , "--oneline" , "-z" , selected_hash ]
328
+ cmd = ["git" , "log" , "-1" , "--numstat" , "--oneline" , "-z" , selected_hash ]
329
329
code , my_output , my_error = await execute (
330
330
cmd , cwd = os .path .join (self .root_dir , current_path ),
331
331
)
332
332
333
333
if code != 0 :
334
334
return {"code" : code , "command" : " " .join (cmd ), "message" : my_error }
335
335
336
+ total_insertions = 0
337
+ total_deletions = 0
336
338
result = []
337
- note = [0 ] * 3
338
- count = 0
339
- temp = ""
340
- line_array = re .split ("\x00 |\n |\r \n |\r " , my_output )
341
- length = len (line_array )
342
- INSERTION_INDEX = 0
343
- DELETION_INDEX = 1
344
- MODIFIED_FILE_PATH_INDEX = 2
345
- if length > 1 :
346
- temp = line_array [length - 1 ]
347
- words = temp .split ()
348
- for i in range (0 , len (words )):
349
- if words [i ].isdigit ():
350
- note [count ] = words [i ]
351
- count += 1
352
- for num in range (1 , int (length / 2 )):
353
- line_info = line_array [num ].split ('\t ' , maxsplit = 2 )
354
- words = line_info [2 ].split ("/" )
355
- length = len (words )
356
- result .append (
357
- {
358
- "modified_file_path" : line_info [MODIFIED_FILE_PATH_INDEX ],
359
- "modified_file_name" : words [length - 1 ],
360
- "insertion" : line_info [INSERTION_INDEX ],
361
- "deletion" : line_info [DELETION_INDEX ],
362
- }
363
- )
339
+ line_iterable = iter (self .strip_and_split (my_output )[1 :])
340
+ for line in line_iterable :
341
+ insertions , deletions , file = line .split ('\t ' )
364
342
365
- if note [2 ] == 0 and length > 1 :
366
- if "-" in temp :
367
- exchange = note [1 ]
368
- note [1 ] = note [2 ]
369
- note [2 ] = exchange
343
+ if file == '' :
344
+ # file was renamed or moved
345
+ # we need next two lines of output
346
+ from_path = next (line_iterable )
347
+ to_path = next (line_iterable )
348
+ modified_file_name = from_path + " ⮕ " + to_path
349
+ modified_file_path = to_path
350
+ else :
351
+ modified_file_name = file .split ("/" )[- 1 ]
352
+ modified_file_path = file
353
+
354
+ result .append ({
355
+ "modified_file_path" : modified_file_path ,
356
+ "modified_file_name" : modified_file_name ,
357
+ "insertion" : insertions ,
358
+ "deletion" : deletions ,
359
+ })
360
+ total_insertions += int (insertions )
361
+ total_deletions += int (deletions )
362
+
363
+ modified_file_note = "{num_files} files changed, {insertions} insertions(+), {deletions} deletions(-)" .format (
364
+ num_files = len (result ),
365
+ insertions = total_insertions ,
366
+ deletions = total_deletions )
370
367
371
368
return {
372
369
"code" : code ,
373
- "modified_file_note" : temp ,
374
- "modified_files_count" : note [ 0 ] ,
375
- "number_of_insertions" : note [ 1 ] ,
376
- "number_of_deletions" : note [ 2 ] ,
370
+ "modified_file_note" : modified_file_note ,
371
+ "modified_files_count" : str ( len ( result )) ,
372
+ "number_of_insertions" : str ( total_insertions ) ,
373
+ "number_of_deletions" : str ( total_deletions ) ,
377
374
"modified_files" : result ,
378
375
}
379
376
0 commit comments