Add basic support for symbolic links.

This commit is contained in:
Charles Pence
2013-03-16 18:19:48 -04:00
parent 44a3cf1934
commit 2a4517ced4
19 changed files with 98 additions and 12 deletions
+1
View File
@@ -6,6 +6,7 @@ require 'ostruct'
# external
require 'grit'
require File.expand_path('../gollum/grit_ext', __FILE__)
require 'github/markup'
require 'sanitize'
+6 -2
View File
@@ -10,10 +10,14 @@ module Gollum
# Gets the Fixnum size of this blob.
attr_reader :size
def initialize(sha, path, size = nil)
# Gets the Fixnum mode of this blob.
attr_reader :mode
def initialize(sha, path, size = nil, mode = nil)
@sha = sha
@path = path
@size = size
@mode = mode
@dir = @name = @blob = nil
end
@@ -34,7 +38,7 @@ module Gollum
# Returns an unbaked Grit::Blob instance.
def blob(repo)
@blob ||= Grit::Blob.create(repo,
:id => @sha, :name => name, :size => @size)
:id => @sha, :name => name, :size => @size, :mode => @mode)
end
# Gets a Page instance for this blob.
+8 -1
View File
@@ -42,7 +42,14 @@ module Gollum
#
# Returns the String data.
def raw_data
@blob && @blob.data
return nil unless @blob
if @blob.is_symlink
new_path = @blob.symlink_target(self.path)
return IO.read(new_path) if new_path
end
@blob.data
end
# Public: The Grit::Commit version of the file.
+1 -1
View File
@@ -229,7 +229,7 @@ module Gollum
# Returns an Array of BlobEntry instances.
def parse_tree_line(line)
mode, type, sha, size, *name = line.split(/\s+/)
BlobEntry.new(sha, name.join(' '), size.to_i)
BlobEntry.new(sha, name.join(' '), size.to_i, mode.to_i(8))
end
# Decode octal sequences (\NNN) in tree path names.
+20
View File
@@ -0,0 +1,20 @@
# ~*~ encoding: utf-8 ~*~
module Grit
class Blob
def is_symlink
self.mode == 0120000
end
def symlink_target(base_path = nil)
target = self.data
new_path = File.expand_path(File.join('..', target), base_path)
if File.file? new_path
return new_path
end
end
nil
end
end
+8 -1
View File
@@ -180,7 +180,14 @@ module Gollum
#
# Returns the String data.
def raw_data
@blob && @blob.data
return nil unless @blob
if @blob.is_symlink
new_path = @blob.symlink_target(::File.join(@wiki.repo.path, self.path))
return IO.read(new_path) if new_path
end
@blob.data
end
# Public: A text data encoded in specified encoding.
+1 -1
View File
@@ -276,7 +276,7 @@ module Gollum
page = @page_class.new(self)
ext = @page_class.format_to_ext(format.to_sym)
name = @page_class.cname(name) + '.' + ext
blob = OpenStruct.new(:name => name, :data => data)
blob = OpenStruct.new(:name => name, :data => data, :is_symlink => false)
page.populate(blob)
page.version = @access.commit('master')
page