Skip to content

Commit 67782ea

Browse files
committed
Rename repository -> repo, encapsulate use of Grit
1 parent 73bbef1 commit 67782ea

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

git-wiki.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
module GitWiki
1010
class << self
1111
attr_accessor :wiki_path, :root_page, :extension, :link_pattern
12-
attr_reader :wiki_name, :repository
12+
attr_reader :wiki_name, :repo
1313
def wiki_path=(path)
1414
@wiki_name = File.basename(path)
15-
@repository = Grit::Repo.new(path)
15+
@repo = Grit::Repo.new(path)
1616
end
1717
def all_page_blobs
18-
@repository.head.commit.tree.contents.select do |obj|
18+
@repo.head.commit.tree.contents.select do |obj|
1919
obj.kind_of?(Grit::Blob) && obj.name.end_with?(@extension)
2020
end
2121
end
22+
def create_blob(path)
23+
Grit::Blob.create(@repo, :name => path)
24+
end
2225
def file_path(name)
2326
(name.empty? ? @root_page : name) + @extension
2427
end
@@ -42,9 +45,9 @@ def self.find_all
4245

4346
def self.find_or_create(name, rev=nil)
4447
path = GitWiki.file_path(name)
45-
commit = rev ? GitWiki.repository.commit(rev) : GitWiki.repository.head.commit
48+
commit = rev ? GitWiki.repo.commit(rev) : GitWiki.repo.head.commit
4649
blob = commit.tree/path
47-
new(blob || Grit::Blob.create(GitWiki.repository, :name => path))
50+
new(blob || GitWiki.create_blob(path))
4851
end
4952

5053
def initialize(blob)
@@ -68,16 +71,16 @@ def to_html
6871
end
6972

7073
def log
71-
head = GitWiki.repository.head.name
72-
GitWiki.repository.log(head, @blob.name).map {|commit| commit.to_hash }
74+
head = GitWiki.repo.head.name
75+
GitWiki.repo.log(head, @blob.name).map {|commit| commit.to_hash }
7376
end
7477

7578
def save!(data, msg)
7679
msg = "web commit: #{name}" if msg.empty?
77-
Dir.chdir(GitWiki.repository.working_dir) do
80+
Dir.chdir(GitWiki.repo.working_dir) do
7881
File.open(@blob.name, 'w') {|f| f.puts(data.gsub("\r\n", "\n")) }
79-
GitWiki.repository.add(@blob.name)
80-
GitWiki.repository.commit_index(msg)
82+
GitWiki.repo.add(@blob.name)
83+
GitWiki.repo.commit_index(msg)
8184
end
8285
end
8386
end

0 commit comments

Comments
 (0)