@@ -846,35 +846,30 @@ def tree_entry(commit, path)
846846 # comparing commit trees, but lets us use Rugged::Diff#find_similar to
847847 # detect file renames.
848848 def touches_path_diff? ( commit , path )
849- if commit . parents . empty?
850- diff = commit . diff
851- else
852- diff = commit . parents [ 0 ] . diff ( commit )
853- diff . find_similar!
854- end
849+ diff = commit . diff ( reverse : true , paths : [ path ] ,
850+ disable_pathspec_match : true )
851+
852+ return false if diff . deltas . empty?
853+
854+ # If +path+ is a filename, not a directory, then we should only have
855+ # one delta. We don't need to follow renames for directories.
856+ return true if diff . deltas . length > 1
857+
858+ # Detect renames
859+ delta = diff . deltas . first
860+ if delta . added?
861+ full_diff = commit . diff ( reverse : true )
862+ full_diff . find_similar!
855863
856- # Check the commit's deltas to see if it touches the :path
857- # argument
858- diff . each_delta do |d |
859- if path_matches? ( path , d . old_file [ :path ] , d . new_file [ :path ] )
860- if d . renamed? && path == d . new_file [ :path ]
864+ full_diff . each_delta do |full_delta |
865+ if full_delta . renamed? && path == full_delta . new_file [ :path ]
861866 # Look for the old path in ancestors
862- path . replace ( d . old_file [ :path ] )
867+ path . replace ( full_delta . old_file [ :path ] )
863868 end
864-
865- return true
866869 end
867870 end
868871
869- false
870- end
871-
872- # Returns true if any of the strings in +*paths+ begins with the
873- # +path_to_match+ argument
874- def path_matches? ( path_to_match , *paths )
875- paths . any? do |p |
876- p . match ( /^#{ Regexp . escape ( path_to_match ) } / )
877- end
872+ true
878873 end
879874
880875 def archive_to_file ( treeish = 'master' , prefix = nil , filename = 'archive.tar.gz' , format = nil , compress_cmd = %W( gzip ) )
0 commit comments