#NEWLINE# def find_git_mtimes( self , context , silent_build ) : #NEWLINE# #INDENT# '\n        Use git to find the mtimes of the files we care about\n        ' #NEWLINE# if ( not context . use_git_timestamps ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# parent_dir = context . parent_dir #NEWLINE# root_folder = context . git_root #NEWLINE# if ( context . use_git_timestamps and os . path . exists ( os . path . join ( root_folder , '.git' , 'shallow' ) ) ) : #NEWLINE# #INDENT# raise HarpoonError ( "Can't get git timestamps from a shallow clone" , directory = parent_dir ) #NEWLINE# #UNINDENT# git = Repo ( root_folder ) #NEWLINE# mtimes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# all_files = set ( git . open_index ( ) ) #NEWLINE# use_files = set ( ) #NEWLINE# use_files_relpaths = set ( ) #NEWLINE# for filename in all_files : #NEWLINE# #INDENT# relpath = os . path . relpath ( os . path . join ( root_folder , filename . decode ( 'utf-8' ) ) , context . parent_dir ) #NEWLINE# if relpath . startswith ( '../' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( context . use_git_timestamps and ( type ( context . use_git_timestamps ) is not bool ) ) : #NEWLINE# #INDENT# match = False #NEWLINE# for line in context . use_git_timestamps : #NEWLINE# #INDENT# if fnmatch . fnmatch ( relpath , line ) : #NEWLINE# #INDENT# match = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not match ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# matched = ( context . exclude or ( not any ( [ context . exclude , context . include ] ) ) ) #NEWLINE# if context . exclude : #NEWLINE# #INDENT# for line in context . exclude : #NEWLINE# #INDENT# if fnmatch . fnmatch ( relpath , line ) : #NEWLINE# #INDENT# matched = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if context . include : #NEWLINE# #INDENT# for line in context . include : #NEWLINE# #INDENT# if fnmatch . fnmatch ( relpath , line ) : #NEWLINE# #INDENT# matched = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if matched : #NEWLINE# #INDENT# use_files . add ( filename ) #NEWLINE# use_files_relpaths . add ( relpath ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not silent_build ) : #NEWLINE# #INDENT# log . info ( 'Finding modified times for %s/%s git controlled files in %s' , len ( use_files ) , len ( all_files ) , root_folder ) #NEWLINE# #UNINDENT# first_commit = None #NEWLINE# ( cached_commit , cached_mtimes ) = self . get_cached_mtimes ( root_folder , use_files_relpaths ) #NEWLINE# for entry in git . get_walker ( ) : #NEWLINE# #INDENT# if ( first_commit is None ) : #NEWLINE# #INDENT# first_commit = entry . commit . id . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# if ( cached_commit and ( entry . commit . id . decode ( 'utf-8' ) == cached_commit ) ) : #NEWLINE# #INDENT# new_mtimes = cached_mtimes #NEWLINE# new_mtimes . update ( mtimes ) #NEWLINE# mtimes = new_mtimes #NEWLINE# break #NEWLINE# #UNINDENT# date = entry . commit . author_time #NEWLINE# added = False #NEWLINE# for changes in entry . changes ( ) : #NEWLINE# #INDENT# if ( type ( changes ) is not list ) : #NEWLINE# #INDENT# changes = [ changes ] #NEWLINE# #UNINDENT# for change in changes : #NEWLINE# #INDENT# path = change . new . path #NEWLINE# if ( root_folder and change . new . path and context . parent_dir ) : #NEWLINE# #INDENT# if ( path in use_files ) : #NEWLINE# #INDENT# new_relpath = os . path . relpath ( os . path . join ( root_folder , change . new . path . decode ( 'utf-8' ) ) , context . parent_dir ) . encode ( 'utf-8' ) #NEWLINE# if ( not new_relpath . decode ( 'utf-8' ) . startswith ( '../' ) ) : #NEWLINE# #INDENT# if ( mtimes . get ( new_relpath , 0 ) < date ) : #NEWLINE# #INDENT# mtimes [ new_relpath ] = date #NEWLINE# added = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if added : #NEWLINE# #INDENT# if ( len ( ( use_files - set ( mtimes ) ) ) == 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# mtimes = dict ( ( ( ( fn . decode ( 'utf-8' ) if hasattr ( fn , 'decode' ) else fn ) , mtime ) for ( fn , mtime ) in mtimes . items ( ) ) ) #NEWLINE# if ( first_commit != cached_commit ) : #NEWLINE# #INDENT# self . set_cached_mtimes ( root_folder , first_commit , mtimes , use_files_relpaths ) #NEWLINE# #UNINDENT# return mtimes