recover from bad shas
This commit is contained in:
@@ -47,8 +47,9 @@ module Gollum
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tree(ref)
|
def tree(ref)
|
||||||
sha = ref_to_sha(ref)
|
if sha = ref_to_sha(ref)
|
||||||
get_cache(:tree, sha) { tree!(sha) }
|
get_cache(:tree, sha) { tree!(sha) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def blob(sha)
|
def blob(sha)
|
||||||
@@ -62,9 +63,10 @@ module Gollum
|
|||||||
if sha = get_cache(:ref, ref)
|
if sha = get_cache(:ref, ref)
|
||||||
commit(sha)
|
commit(sha)
|
||||||
else
|
else
|
||||||
cm = commit!(ref)
|
if cm = commit!(ref)
|
||||||
set_cache(:ref, ref, cm.id)
|
set_cache(:ref, ref, cm.id)
|
||||||
set_cache(:commit, cm.id, cm)
|
set_cache(:commit, cm.id, cm)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -95,6 +97,7 @@ module Gollum
|
|||||||
|
|
||||||
def ref_to_sha!(ref)
|
def ref_to_sha!(ref)
|
||||||
@repo.git.rev_list({:max_count=>1}, ref)
|
@repo.git.rev_list({:max_count=>1}, ref)
|
||||||
|
rescue Grit::GitRuby::Repository::NoSuchShaFound
|
||||||
end
|
end
|
||||||
|
|
||||||
def tree!(sha)
|
def tree!(sha)
|
||||||
@@ -119,12 +122,12 @@ module Gollum
|
|||||||
if value.nil? && block_given?
|
if value.nil? && block_given?
|
||||||
set_cache(name, key, value = yield)
|
set_cache(name, key, value = yield)
|
||||||
end
|
end
|
||||||
value
|
value == :_nil ? nil : value
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_cache(name, key, value)
|
def set_cache(name, key, value)
|
||||||
cache = instance_variable_get("@#{name}_map")
|
cache = instance_variable_get("@#{name}_map")
|
||||||
cache[key] = value
|
cache[key] = value || :_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def multi_get(name, keys)
|
def multi_get(name, keys)
|
||||||
|
|||||||
+1
-1
@@ -289,7 +289,7 @@ module Gollum
|
|||||||
#
|
#
|
||||||
# Returns a Gollum::Page or nil if the page could not be found.
|
# Returns a Gollum::Page or nil if the page could not be found.
|
||||||
def find_page_in_tree(map, name, checked_dir = nil)
|
def find_page_in_tree(map, name, checked_dir = nil)
|
||||||
return nil if name.to_s.empty?
|
return nil if !map || name.to_s.empty?
|
||||||
if checked_dir = BlobEntry.normalize_dir(checked_dir)
|
if checked_dir = BlobEntry.normalize_dir(checked_dir)
|
||||||
checked_dir.downcase!
|
checked_dir.downcase!
|
||||||
end
|
end
|
||||||
|
|||||||
+13
-2
@@ -15,7 +15,6 @@ context "GitAccess" do
|
|||||||
|
|
||||||
test "#commits uses commit_map" do
|
test "#commits uses commit_map" do
|
||||||
actual = @access.repo.commits.first
|
actual = @access.repo.commits.first
|
||||||
#@access.commit actual.id
|
|
||||||
@access.commit_map['abc'] = 1
|
@access.commit_map['abc'] = 1
|
||||||
commits = @access.commits('abc', actual.id)
|
commits = @access.commits('abc', actual.id)
|
||||||
assert_equal 1, commits[0]
|
assert_equal 1, commits[0]
|
||||||
@@ -27,7 +26,7 @@ context "GitAccess" do
|
|||||||
assert @access.tree_map.empty?
|
assert @access.tree_map.empty?
|
||||||
@access.tree 'master'
|
@access.tree 'master'
|
||||||
assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @access.ref_map)
|
assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @access.ref_map)
|
||||||
|
|
||||||
map = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b']
|
map = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b']
|
||||||
assert_equal 'Bilbo-Baggins.md', map[0].path
|
assert_equal 'Bilbo-Baggins.md', map[0].path
|
||||||
assert_equal '', map[0].dir
|
assert_equal '', map[0].dir
|
||||||
@@ -45,4 +44,16 @@ context "GitAccess" do
|
|||||||
entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
|
entry = @access.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
|
||||||
assert_equal 'Bilbo-Baggins.md', entry.path
|
assert_equal 'Bilbo-Baggins.md', entry.path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "cannot access commit from invalid ref" do
|
||||||
|
assert_nil @access.commit('foo')
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cannot access sha from invalid ref" do
|
||||||
|
assert_nil @access.ref_to_sha('foo')
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cannot access tree from invalid ref" do
|
||||||
|
assert_nil @access.tree('foo')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user