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
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. # Public: Clears all of the cached data that this GitAccess is tracking.
# #
# Returns nothing. # Returns nothing.
@@ -136,21 +119,6 @@ module Gollum
# #
attr_reader :commit_map 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. # Checks to see if the given String is a 40 character hex SHA.
# #
# str - Possible String SHA. # str - Possible String SHA.
@@ -230,23 +198,6 @@ module Gollum
cache[key] = value || :_nil cache[key] = value || :_nil
end 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. # Parses a line of output from the `ls-tree` command.
# #
# line - A String line of output: # line - A String line of output:
+6 -3
View File
@@ -17,6 +17,7 @@ module Gollum
@tagmap = {} @tagmap = {}
@codemap = {} @codemap = {}
@texmap = {} @texmap = {}
@premap = {}
end end
# Render the content with Gollum wiki syntax on top of the file's own # Render the content with Gollum wiki syntax on top of the file's own
@@ -31,7 +32,7 @@ module Gollum
@wiki.history_sanitizer : @wiki.history_sanitizer :
@wiki.sanitizer @wiki.sanitizer
data = extract_tex(@data) data = extract_tex(@data.dup)
data = extract_code(data) data = extract_code(data)
data = extract_tags(data) data = extract_tags(data)
begin begin
@@ -115,7 +116,7 @@ module Gollum
# #
# Returns the placeholder'd String data. # Returns the placeholder'd String data.
def extract_tags(data) def extract_tags(data)
data.gsub(/(.?)\[\[(.+?)\]\]([^\[]?)/m) do data.gsub!(/(.?)\[\[(.+?)\]\]([^\[]?)/m) do
if $1 == "'" && $3 != "'" if $1 == "'" && $3 != "'"
"[[#{$2}]]#{$3}" "[[#{$2}]]#{$3}"
elsif $2.include?('][') elsif $2.include?('][')
@@ -126,6 +127,7 @@ module Gollum
"#{$1}#{id}#{$3}" "#{$1}#{id}#{$3}"
end end
end end
data
end end
# Process all tags from the tagmap and replace the placeholders with the # Process all tags from the tagmap and replace the placeholders with the
@@ -357,7 +359,7 @@ module Gollum
# #
# Returns the placeholder'd String data. # Returns the placeholder'd String data.
def extract_code(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) id = Digest::SHA1.hexdigest($2)
cached = check_cache(:code, id) cached = check_cache(:code, id)
@codemap[id] = cached ? @codemap[id] = cached ?
@@ -365,6 +367,7 @@ module Gollum
{ :lang => $1, :code => $2 } { :lang => $1, :code => $2 }
id id
end end
data
end end
# Process all code from the codemap and replace the placeholders with the # Process all code from the codemap and replace the placeholders with the
-8
View File
@@ -14,14 +14,6 @@ context "GitAccess" do
assert_equal actual.message, @access.commit_map[actual.id].message assert_equal actual.message, @access.commit_map[actual.id].message
end end
test "#commits uses commit_map" do
actual = @access.repo.commits.first
@access.commit_map['abc'] = 1
commits = @access.commits('abc', actual.id)
assert_equal 1, commits[0]
assert_equal actual.message, commits[1].message
end
test "#tree_map_for caches ref and tree" do test "#tree_map_for caches ref and tree" do
assert @access.ref_map.empty? assert @access.ref_map.empty?
assert @access.tree_map.empty? assert @access.tree_map.empty?