From 6dab4f7fe62ea166fead2220b736b4cd3e16f0ba Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 30 Aug 2010 17:41:35 -0700 Subject: [PATCH] Wiki#pages uses the treemap --- lib/gollum/blob_entry.rb | 18 +++++++++++++++++- lib/gollum/page.rb | 2 +- lib/gollum/wiki.rb | 37 +++++++++++++------------------------ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/gollum/blob_entry.rb b/lib/gollum/blob_entry.rb index 23c92084..14ef59b9 100644 --- a/lib/gollum/blob_entry.rb +++ b/lib/gollum/blob_entry.rb @@ -22,11 +22,27 @@ module Gollum @name ||= ::File.basename(@path) end - # Gets the Grit::Blob instance for this blob. + # Gets a Grit::Blob instance for this blob. + # + # repo - Grit::Repo instance for the Grit::Blob. + # + # Returns an unbaked Grit::Blob instance. def blob(repo) @blob ||= Grit::Blob.create(repo, :id => @sha, :name => @name) end + # Gets a Page instance for this blob. + # + # wiki - Gollum::Wiki instance for the Gollum::Page + # + # Returns a Gollum::Page instance. + def page(wiki, commit) + blob = self.blob(wiki.repo) + page = wiki.page_class.new(wiki).populate(blob, self.dir) + page.version = commit + page + end + # Normalizes a given directory name for searching through tree paths. # Ensures that a directory begins with a slash, or # diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index 7ac45bdb..f2b7f1c2 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -271,7 +271,7 @@ module Gollum map.each do |entry| next unless checked_dir.nil? || entry.dir.downcase == checked_dir next unless page_match(name, entry.name) - return self.class.new(@wiki).populate(entry.blob(@wiki.repo), entry.dir) + return entry.page(@wiki, @version) end return nil # nothing was found diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index af92cbba..440e967d 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -207,12 +207,7 @@ module Gollum # # Returns an Array of Gollum::Page instances. def pages(treeish = nil) - treeish ||= 'master' - if commit = @repo.commit(treeish) - tree_list(commit) - else - [] - end + tree_list(treeish || 'master') end # Public: All of the versions that have touched the Page. @@ -256,6 +251,12 @@ module Gollum # Returns the Hash cache. attr_reader :tree_map + # Gets the page class used by all instances of this Wiki. + attr_reader :page_class + + # Gets the file class used by all instances of this Wiki. + attr_reader :file_class + # Normalize the data. # # data - The String data to be normalized. @@ -267,27 +268,15 @@ module Gollum # Fill an array with a list of pages. # - # commit - The Grit::Commit - # tree - The Grit::Tree to start with. - # sub_tree - Optional String specifying the parent path of the Page. + # ref - A String ref that is either a commit SHA or references one. # # Returns a flat Array of Gollum::Page instances. - def tree_list(commit, tree = commit.tree, sub_tree = nil) - list = [] - path = tree.name ? "#{sub_tree}/#{tree.name}" : '' - tree.contents.each do |item| - case item - when Grit::Blob - if @page_class.valid_page_name?(item.name) - page = @page_class.new(self).populate(item, path) - page.version = commit - list << page - end - when Grit::Tree - list.push *tree_list(commit, item, path) - end + def tree_list(ref) + tree_map_for(ref).inject([]) do |list, entry| + next list unless @page_class.valid_page_name?(entry.name) + sha = ref_map[ref] + list << entry.page(self, @repo.commit(sha)) end - list end # Determine if a given page path is scheduled to be deleted in the next