<s> """<STR_LIT>""" <EOL> import os . path <EOL> import subprocess <EOL> import gitlint . utils as utils <EOL> def repository_root ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> root = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stderr = subprocess . STDOUT ) . strip ( ) <EOL> return root . decode ( '<STR_LIT:utf-8>' ) <EOL> except subprocess . CalledProcessError : <EOL> return None <EOL> def last_commit ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> root = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stderr = subprocess . STDOUT ) . strip ( ) <EOL> return root . decode ( '<STR_LIT:utf-8>' ) <EOL> except subprocess . CalledProcessError : <EOL> return None <EOL> def _remove_filename_quotes ( filename ) : <EOL> """<STR_LIT>""" <EOL> if filename . startswith ( '<STR_LIT:">' ) and filename . endswith ( '<STR_LIT:">' ) : <EOL> return filename [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return filename <EOL> def modified_files ( root , tracked_only = False , commit = None ) : <EOL> """<STR_LIT>""" <EOL> assert os . path . isabs ( root ) , "<STR_LIT>" % root <EOL> if commit : <EOL> return _modified_files_with_commit ( root , commit ) <EOL> status_lines = subprocess . check_output ( [ <EOL> '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) . decode ( '<STR_LIT:utf-8>' ) . split ( os . linesep ) <EOL> modes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if not tracked_only : <EOL> modes . append ( r'<STR_LIT>' ) <EOL> modes_str = '<STR_LIT:|>' . join ( modes ) <EOL> modified_file_status = utils . filter_lines ( <EOL> status_lines , <EOL> r'<STR_LIT>' % modes_str , <EOL> groups = ( '<STR_LIT:filename>' , '<STR_LIT>' ) ) <EOL> return dict ( ( os . path . join ( root , _remove_filename_quotes ( filename ) ) , mode ) <EOL> for filename , mode in modified_file_status ) <EOL> def _modified_files_with_commit ( root , commit ) : <EOL> status_lines = subprocess . check_output ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> commit ] ) . decode ( '<STR_LIT:utf-8>' ) . split ( os . linesep ) <EOL> modified_file_status = utils . filter_lines ( <EOL> status_lines , <EOL> r'<STR_LIT>' , <EOL> groups = ( '<STR_LIT:filename>' , '<STR_LIT>' ) ) <EOL> return dict ( ( os . path . join ( root , _remove_filename_quotes ( filename ) ) , <EOL> mode + '<STR_LIT:U+0020>' ) for filename , mode in modified_file_status ) <EOL> def modified_lines ( filename , extra_data , commit = None ) : <EOL> """<STR_LIT>""" <EOL> if extra_data is None : <EOL> return [ ] <EOL> if extra_data not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return None <EOL> if commit is None : <EOL> commit = '<STR_LIT:0>' * <NUM_LIT> <EOL> commit = commit . encode ( '<STR_LIT:utf-8>' ) <EOL> blame_lines = subprocess . check_output ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , filename ] ) . split ( <EOL> os . linesep . encode ( '<STR_LIT:utf-8>' ) ) <EOL> modified_line_numbers = utils . filter_lines ( <EOL> blame_lines , <EOL> commit + br'<STR_LIT>' , <EOL> groups = ( '<STR_LIT>' , ) ) <EOL> return list ( map ( int , modified_line_numbers ) ) </s>
