Merge branch 'master' of git://github.com/github/gollum

This commit is contained in:
Eston Bond
2010-12-21 02:36:43 -08:00
3 changed files with 6 additions and 60 deletions
-49
View File
@@ -72,23 +72,6 @@ module Gollum
end
end
# Public: Gets a list of Git commits.
#
# *shas - An Array of String SHAs.
#
# Returns an Array of Grit::Commit instances.
def commits(*shas)
shas.flatten!
cached_commits = multi_get(:commit, shas)
missing_shas = shas.select do |sha|
!cached_commits.key?(sha)
end
multi_commit!(missing_shas, cached_commits) if !missing_shas.empty?
shas.map { |sha| cached_commits[sha] }
end
# Public: Clears all of the cached data that this GitAccess is tracking.
#
# Returns nothing.
@@ -136,21 +119,6 @@ module Gollum
#
attr_reader :commit_map
# Raw method for fetching a list of Git commits.
#
# shas - An Array of String SHAs.
# hash - Optional Hash to store the found commits, indexed by their SHA.
#
# Returns the same Hash instance.
def multi_commit!(shas, hash = {})
shas.each_slice(500) do |slice|
@repo.batch(slice).each do |commit|
hash[commit.id] = commit
end
end
hash
end
# Checks to see if the given String is a 40 character hex SHA.
#
# str - Possible String SHA.
@@ -230,23 +198,6 @@ module Gollum
cache[key] = value || :_nil
end
# Gets multiple values from the cache in a single call.
#
# name - The cache prefix used in building the full cache key.
# keys - Array of cache key names to fetch.
#
# Returns a Hash of the objects that were found in the cache, indexed by
# the cache key.
def multi_get(name, keys)
value = instance_variable_get("@#{name}_map")
keys.inject({}) do |memo, key|
if v = value[key]
memo[key] = v
end
memo
end
end
# Parses a line of output from the `ls-tree` command.
#
# line - A String line of output:
+6 -3
View File
@@ -17,6 +17,7 @@ module Gollum
@tagmap = {}
@codemap = {}
@texmap = {}
@premap = {}
end
# Render the content with Gollum wiki syntax on top of the file's own
@@ -31,7 +32,7 @@ module Gollum
@wiki.history_sanitizer :
@wiki.sanitizer
data = extract_tex(@data)
data = extract_tex(@data.dup)
data = extract_code(data)
data = extract_tags(data)
begin
@@ -115,7 +116,7 @@ module Gollum
#
# Returns the placeholder'd String data.
def extract_tags(data)
data.gsub(/(.?)\[\[(.+?)\]\]([^\[]?)/m) do
data.gsub!(/(.?)\[\[(.+?)\]\]([^\[]?)/m) do
if $1 == "'" && $3 != "'"
"[[#{$2}]]#{$3}"
elsif $2.include?('][')
@@ -126,6 +127,7 @@ module Gollum
"#{$1}#{id}#{$3}"
end
end
data
end
# Process all tags from the tagmap and replace the placeholders with the
@@ -357,7 +359,7 @@ module Gollum
#
# Returns the placeholder'd String data.
def extract_code(data)
data.gsub(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
id = Digest::SHA1.hexdigest($2)
cached = check_cache(:code, id)
@codemap[id] = cached ?
@@ -365,6 +367,7 @@ module Gollum
{ :lang => $1, :code => $2 }
id
end
data
end
# Process all code from the codemap and replace the placeholders with the