def cached_commits(range)
      commits = []

      direction = nil
      if @commits.key? range.last
        current_commits = [@commits[range.last]]
        direction = :parents
      elsif @commits.key? range.first
        current_commits = [@commits[range.first]]
        direction = :children
      end

      unless direction.nil?
        while !current_commits.empty? do
          new_commits = []
          current_commits.each do |commit|
            new_commits += commit.send direction
            commits << commit if commit.id != range.first
            if direction == :parents && new_commits.include?(range.first)
              new_commits = []
              break
            end
          end
          unless new_commits.include? range.first
            current_commits = new_commits.uniq.map do |commit|
              commit = @commits[commit]
              commits.include?(commit) ? nil : commit
            end.compact
          end
        end
      end

      commits.sort_by { |c| c.committed_date }.reverse
    end
def cached_commits(range)
      commits = []

      direction = nil
      if @commits.key? range.last
        current_commits = [@commits[range.last]]
        direction = :parents
      elsif @commits.key? range.first
        current_commits = [@commits[range.first]]
        direction = :children
      end

      unless direction.nil?
        while !current_commits.empty? do
          new_commits = []
          current_commits.each do |commit|
            new_commits += commit.send direction
            commits << commit if commit.id != range.first
            if direction == :parents && new_commits.include?(range.first)
              new_commits = []
              break
            end
          end
          unless new_commits.include? range.first
            current_commits = new_commits.uniq.map do |commit|
              commit = @commits[commit]
              commits.include?(commit) ? nil : commit
            end.compact
          end
        end
      end

      commits.sort_by { |c| c.committed_date }.reverse
    end
Tries to retrieve as many commits as possible in the given commit range
 from the commit cache

 This method calls itself recursively to walk the given commit range
 either from the start to the end or vice versa depending on which commit
 could be found in the cache.

 @param [Range] range The range of commits which should be retrieved from
        the cache. This may be given a range of commit IDs
        (`'master'..'development'`).
 @return [Array<Commit>] A list of commit objects that could be retrieved
         from the cache
 @see Commit#children