public
Fork of sr/git-wiki
Description: A wiki engine that uses a Git repository as its data store.
Homepage: http://atonie.org/2008/02/git-wiki
Clone URL: git://github.com/al3x/git-wiki.git
Search Repo:
moved entire app to ruby-git from grit
schacon (author)
Thu Mar 06 15:38:46 -0800 2008
commit  b0f4475857c54a55d030ea14f04137c96a771023
tree    6d5cce86ad1226e575772f1c18c6e214edf17a92
parent  3e835ce51f6057c356854bf80a5c2eb23b12f6c7
0
...
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -4,6 +4,18 @@
0
   * deleting pages
0
   * pushing repo
0
 
0
+= CHACON IDEAS
0
+ * download tarball
0
+ * branching (clean/derivative)
0
+ * inter-branch links
0
+ * remotes (add / fetch)
0
+ * merge branches (local and remotes)
0
+ * tagging
0
+ * cherry-picked branches (read-tree/write-tree)
0
+ * git-less version (read-only)
0
+ * push?
0
+ * users (email/name/ip - use for commits)
0
+
0
 = LATER/MAYBE
0
   * repo stats/info/maintenance page
0
   * backlinks (trivial syntax, ideally)
...
2
3
4
5
 
6
7
8
9
10
11
12
13
14
15
 
16
17
 
18
19
20
 
...
2
3
4
 
5
6
7
8
9
 
10
11
12
 
 
13
14
 
15
16
17
 
18
0
@@ -2,20 +2,18 @@
0
 require 'extensions'
0
 require 'page'
0
 
0
-%w(grit redcloth rubypants uv).each do |gem|
0
+%w(git redcloth rubypants uv).each do |gem|
0
   require_gem_with_feedback gem
0
 end
0
 
0
 GIT_REPO = ARGV[0] || ENV['HOME'] + '/wiki'
0
-GIT_DIR = File.join(GIT_REPO, '.git')
0
 HOMEPAGE = 'Home'
0
 UV_THEME = 'idle'
0
 
0
-unless File.exists?(GIT_DIR) && File.directory?(GIT_DIR)
0
- FileUtils.mkdir_p(GIT_DIR)
0
+unless File.exists?(GIT_REPO) && File.directory?(GIT_REPO)
0
   puts "Initializing repository in #{GIT_REPO}..."
0
- `/usr/bin/env git --git-dir #{GIT_DIR} init`
0
+ Git.init(GIT_REPO)
0
 end
0
 
0
-$repo = Grit::Repo.new(GIT_REPO)
0
+$repo = Git.open(GIT_REPO)
...
29
30
31
32
33
34
35
36
37
 
38
39
40
...
29
30
31
 
 
 
 
 
 
32
33
34
35
0
@@ -29,12 +29,7 @@
0
 get('/_app.js') { header 'Content-Type' => 'application/x-javascript'; File.read(File.join(File.dirname(__FILE__), 'javascripts', "application.js")) }
0
 
0
 get '/_list' do
0
- if $repo.commits.empty?
0
- @pages = []
0
- else
0
- @pages = $repo.commits.first.tree.contents.map { |blob| Page.new(blob.name) }
0
- end
0
-
0
+ @pages = $repo.log.first.gtree.children.map { |name, blob| Page.new(name) } rescue []
0
   show(:list, 'Listing pages')
0
 end
0
 
...
19
20
21
22
 
23
24
25
26
27
 
28
29
30
31
32
33
34
35
36
37
38
39
...
33
34
35
36
 
 
37
38
39
40
41
 
 
 
 
 
42
43
44
45
46
 
47
48
49
50
 
51
52
53
54
 
55
56
57
58
 
59
60
61
62
 
63
64
65
66
67
 
 
68
69
70
71
72
 
73
74
75
76
77
 
78
79
...
19
20
21
 
22
23
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
38
39
...
33
34
35
 
36
37
38
39
40
 
 
41
42
43
44
45
46
47
48
49
 
50
51
52
53
 
54
55
56
57
 
58
59
60
61
 
62
63
64
65
 
66
67
68
69
 
 
70
71
72
73
74
75
 
76
77
78
79
80
 
81
82
83
0
@@ -19,12 +19,12 @@
0
   end
0
 
0
   def updated_at
0
- commit.committed_date
0
+ commit.committer_date
0
   end
0
 
0
   def raw_body
0
     if @rev
0
- @raw_body ||= blob.data
0
+ @raw_body ||= blob.contents
0
     else
0
       @raw_body ||= File.exists?(@filename) ? File.read(@filename) : ''
0
     end
0
0
0
0
0
0
0
0
0
0
@@ -33,48 +33,52 @@
0
   def body=(content)
0
     File.open(@filename, 'w') { |f| f << content }
0
     message = tracked? ? "edited #{@name}" : "created #{@name}"
0
- `cd #{GIT_REPO} && git add #{@name} && git commit -m "#{message}"`
0
+ $repo.add(@name)
0
+ $repo.commit(message)
0
   end
0
 
0
   def tracked?
0
- return false if $repo.commits.empty?
0
- $repo.commits.first.tree.contents.map { |b| b.name }.include?(@name)
0
+ begin
0
+ $repo.gtree('HEAD').children.keys.include?(@name)
0
+ rescue
0
+ false
0
+ end
0
   end
0
 
0
   def history
0
     return nil unless tracked?
0
- @history ||= $repo.log('master', @name)
0
+ @history ||= $repo.log.path(@name)
0
   end
0
 
0
   def delta(rev)
0
- $repo.diff(previous_commit, rev, @name)
0
+ $repo.diff(previous_commit, rev).path(@name).patch
0
   end
0
   
0
   def commit
0
- @commit ||= $repo.log(@rev || 'master', @name, {"max-count" => 1}).first
0
+ @commit ||= $repo.log.object(@rev || 'master').path(@name).first
0
   end
0
 
0
   def previous_commit
0
- @previous_commit ||= $repo.log(@rev || 'master', @name, {"max-count" => 2})[1]
0
+ @previous_commit ||= $repo.log(2).object(@rev || 'master').path(@name).to_a[1]
0
   end
0
 
0
   def next_commit
0
- if self.history[0].to_s == self.commit.to_s
0
+ if (self.history.first.sha == self.commit.sha)
0
       @next_commit ||= nil
0
     else
0
       matching_index = nil
0
- history.each_with_index { |c, i| matching_index = i if c.to_s == self.commit.to_s }
0
- @next_commit ||= history[matching_index - 1]
0
+ history.each_with_index { |c, i| matching_index = i if c.sha == self.commit.sha }
0
+ @next_commit ||= history.to_a[matching_index - 1]
0
     end
0
   end
0
 
0
   def version(rev)
0
- data = blob.data
0
+ data = blob.contents
0
     RubyPants.new(RedCloth.new(data).to_html).to_html.wiki_linked
0
   end
0
 
0
   def blob
0
- @blob ||= ($repo.tree(@rev)/@name)
0
+ @blob ||= ($repo.gblob(@rev + ':' + @name))
0
   end
0
 end
...
9
10
11
12
13
14
15
 
 
 
 
16
17
18
...
9
10
11
 
 
 
 
12
13
14
15
16
17
18
0
@@ -9,10 +9,10 @@
0
   <ul>
0
     <% @page.history.each do |c| %>
0
       <li>
0
- <%= c.committed_date %> &mdash;
0
- <a href="/h/<%= @page.name %>/<%= c.id %>"><%= c.message %></a>
0
- <% unless @page.history.last == c %>
0
- &bull; <a href="/d/<%= @page.name %>/<%= c.id %>">diff</a>
0
+ <%= c.committer_date %> &mdash;
0
+ <a href="/h/<%= @page.name %>/<%= c.sha %>"><%= c.message %></a>
0
+ <% unless @page.history.first == c %>
0
+ &bull; <a href="/d/<%= @page.name %>/<%= c.sha %>">diff</a>
0
         <% end %>
0
       </li>
0
     <% end %>

Comments

    No one has commented yet.