<s> import os <EOL> import re <EOL> import subprocess <EOL> import decorators <EOL> import time <EOL> from collections import Counter <EOL> def get_files ( repository_path , argv ) : <EOL> os . chdir ( repository_path ) <EOL> parameters = [ '<STR_LIT>' , '<STR_LIT>' , argv . path ] <EOL> files = subprocess . check_output ( parameters , universal_newlines = True ) <EOL> return files . split ( ) <EOL> @ decorators . null_logger <EOL> def blame ( repository_path , file , argv , logger = None ) : <EOL> os . chdir ( repository_path ) <EOL> if is_binary ( file , logger ) and not argv . force_binaries : <EOL> logger . info ( '<STR_LIT>' . format ( file ) ) <EOL> return '<STR_LIT>' <EOL> logger . debug ( '<STR_LIT>' . format ( file ) ) <EOL> try : <EOL> parameters = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , file ] <EOL> blame = subprocess . check_output ( parameters , universal_newlines = True ) <EOL> except subprocess . CalledProcessError as e : <EOL> logger . error ( e ) <EOL> return '<STR_LIT>' <EOL> return blame <EOL> @ decorators . null_logger <EOL> def is_binary ( file , logger = None ) : <EOL> parameters = [ '<STR_LIT:file>' , '<STR_LIT>' , file ] <EOL> try : <EOL> mime = subprocess . check_output ( parameters , universal_newlines = True ) <EOL> match = re . search ( '<STR_LIT>' , mime ) <EOL> except UnicodeDecodeError as e : <EOL> logger . warning ( file ) <EOL> logger . warning ( e ) <EOL> match = True <EOL> return match is not None <EOL> @ decorators . null_logger <EOL> def commit ( repository_path , argv , logger = None ) : <EOL> start_time = time . time ( ) <EOL> accumulator = Counter ( ) <EOL> for file in get_files ( repository_path , argv ) : <EOL> porcelain_blame = blame ( repository_path , file , argv , logger ) <EOL> counter = process_blame ( porcelain_blame , argv , logger ) <EOL> accumulator = accumulator + counter <EOL> elapsed_time = time . time ( ) - start_time <EOL> logger . debug ( '<STR_LIT>' . format ( elapsed_time ) ) <EOL> logger . debug ( '<STR_LIT>' ) <EOL> logger . debug ( accumulator ) <EOL> return ( accumulator , elapsed_time ) <EOL> @ decorators . null_logger <EOL> def process_blame ( blame , argv , logger = None ) : <EOL> pattern = '<STR_LIT>' . format ( argv . identifier ) <EOL> regex = re . compile ( pattern , re . MULTILINE ) <EOL> matches = regex . findall ( blame ) <EOL> counter = Counter ( matches ) <EOL> logger . debug ( counter ) <EOL> return counter </s>
