@@ -278,10 +278,23 @@ def log(options)
278278 options [ :offset ] ||= 0
279279 actual_ref = options [ :ref ] || root_ref
280280 sha = sha_from_ref ( actual_ref )
281- build_log ( sha , options )
282- rescue Rugged ::OdbError , Rugged ::InvalidError , Rugged ::ReferenceError
283- # Return an empty array if the ref wasn't found
284- [ ]
281+ repo = options [ :repo ]
282+
283+ cmd = %W( git -C #{ path } log )
284+ cmd << %W( -n #{ options [ :limit ] . to_i } )
285+ cmd << %W( --skip=#{ options [ :offset ] . to_i } )
286+ cmd << %W( --follow ) if options [ :follow ]
287+ cmd << %W( --no-merges ) if options [ :skip_merges ]
288+ cmd << sha
289+ cmd << %W( -- #{ options [ :path ] } ) if options [ :path ]
290+
291+ raw_output = IO . popen ( cmd . flatten ) { |io | io . read }
292+
293+ log = raw_output . scan ( /commit\ ([0-9a-f]{40})/ ) . flatten . map do |c |
294+ Rugged ::Commit . new ( rugged , c )
295+ end
296+
297+ log . is_a? ( Array ) ? log : [ ]
285298 end
286299
287300 def sha_from_ref ( ref )
@@ -837,46 +850,6 @@ def parse_gitmodules(commit, content)
837850 results
838851 end
839852
840- # Return an array of log commits, given an SHA hash and a hash of
841- # options.
842- def build_log ( sha , options )
843- # Instantiate a Walker and add the SHA hash
844- walker = Rugged ::Walker . new ( rugged )
845- walker . push ( sha )
846-
847- commits = [ ]
848- skipped = 0
849- current_path = options [ :path ]
850- current_path = nil if current_path == ''
851-
852- limit = options [ :limit ] . to_i
853- offset = options [ :offset ] . to_i
854- skip_merges = options [ :skip_merges ]
855-
856- walker . sorting ( Rugged ::SORT_DATE )
857- walker . each do |c |
858- break if limit > 0 && commits . length >= limit
859-
860- if skip_merges
861- # Skip merge commits
862- next if c . parents . length > 1
863- end
864-
865- if !current_path ||
866- commit_touches_path? ( c , current_path , options [ :follow ] , walker )
867-
868- # This is a commit we care about, unless we haven't skipped enough
869- # yet
870- skipped += 1
871- commits . push ( c ) if skipped > offset
872- end
873- end
874-
875- walker . reset
876-
877- commits
878- end
879-
880853 # Returns true if +commit+ introduced changes to +path+, using commit
881854 # trees to make that determination. Uses the history simplification
882855 # rules that `git log` uses by default, where a commit is omitted if it
0 commit comments