<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>AUTHORS</filename>
    </added>
    <added>
      <filename>README.textile</filename>
    </added>
    <added>
      <filename>TODO</filename>
    </added>
    <added>
      <filename>environment.rb</filename>
    </added>
    <added>
      <filename>extensions.rb</filename>
    </added>
    <added>
      <filename>images/search.png</filename>
    </added>
    <added>
      <filename>page.rb</filename>
    </added>
    <added>
      <filename>public/app.js</filename>
    </added>
    <added>
      <filename>public/favicon.ico</filename>
    </added>
    <added>
      <filename>public/jeditable.min.js</filename>
    </added>
    <added>
      <filename>public/jquery.min.js</filename>
    </added>
    <added>
      <filename>public/sh_diff.min.js</filename>
    </added>
    <added>
      <filename>public/sh_main.min.js</filename>
    </added>
    <added>
      <filename>public/sh_style.css</filename>
    </added>
    <added>
      <filename>public/style.css</filename>
    </added>
    <added>
      <filename>sinatra</filename>
    </added>
    <added>
      <filename>system/ruby.server.gitwiki.plist</filename>
    </added>
    <added>
      <filename>views/attach.erb</filename>
    </added>
    <added>
      <filename>views/branch_history.erb</filename>
    </added>
    <added>
      <filename>views/branches.erb</filename>
    </added>
    <added>
      <filename>views/delta.erb</filename>
    </added>
    <added>
      <filename>views/edit.erb</filename>
    </added>
    <added>
      <filename>views/history.erb</filename>
    </added>
    <added>
      <filename>views/layout.erb</filename>
    </added>
    <added>
      <filename>views/list.erb</filename>
    </added>
    <added>
      <filename>views/search.erb</filename>
    </added>
    <added>
      <filename>views/show.erb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,3 @@
-[submodule &quot;vendor/sinatra&quot;]
-	path = vendor/sinatra
-	url = git://github.com/sr/sinatra.git
-[submodule &quot;vendor/haml&quot;]
-	path = vendor/haml
-	url = git://github.com/nex3/haml.git
+[submodule &quot;sinatra&quot;]
+	path = sinatra
+	url = git://github.com/bmizerany/sinatra.git</diff>
      <filename>.gitmodules</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,4 @@
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-                    Version 2, December 2004
+The MIT License
 
  Copyright (C) 2004 Sam Hocevar
   14 rue de Plaisance, 75014 Paris, France
@@ -7,8 +6,21 @@
  copies of this license document, and changing it is allowed as long
  as the name is changed.
 
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the &quot;Software&quot;), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
 
-  0. You just DO WHAT THE FUCK YOU WANT TO.
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
 
+=======
+THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.</diff>
      <filename>LICENSE</filename>
    </modified>
    <modified>
      <diff>@@ -1,327 +1,190 @@
 #!/usr/bin/env ruby
-%w(sinatra haml sass rubygems git redcloth yaml).each do |dependency|
-  begin
-    $: &lt;&lt; File.expand_path(File.dirname(__FILE__) + &quot;/vendor/#{dependency}/lib&quot;)
-    require dependency
-  rescue LoadError
-    abort &quot;Unable to load #{dependency}. Did you run 'git submodule init' ? If so install #{dependency}&quot;
-  end
+
+require 'fileutils'
+require 'environment'
+require 'sinatra/lib/sinatra'
+
+get('/') { redirect &quot;/#{HOMEPAGE}&quot; }
+
+# page paths
+
+get '/:page' do
+  @page = Page.new(params[:page])
+  @page.tracked? ? show(:show, @page.name) : redirect('/e/' + @page.name)
 end
 
-#included until http://sinatra.lighthouseapp.com/projects/9779/tickets/16-patch-http-authentication is in a released version
-require File.dirname(__FILE__) + '/sinatra_http_auth'
+get '/:page.txt' do
+  content_type 'text/plain', :charset =&gt; 'utf-8'
+  @page = Page.new(params[:page])
+  @page.raw_body
+end
 
-begin
-  config = YAML.load(File.read(ENV['CONFIG']))
-rescue
-  config = {
-    'username' =&gt;  nil,
-    'password' =&gt;  nil
-  }
+get '/:page/append' do
+  @page = Page.new(params[:page])
+  @page.body = @page.raw_body + &quot;\n\n&quot; + params[:text]
+  redirect '/' + @page.name
 end
 
-class Page
-  class &lt;&lt; self
-    attr_accessor :repo
-  end
+get '/e/:page' do
+  @page = Page.new(params[:page])
+  show :edit, &quot;Editing #{@page.name}&quot;
+end
 
-  def self.find_all
-    return [] if (Page.repo.log.size rescue 0) == 0
-    Page.repo.log.first.gtree.children.map { |name, blob| Page.new(name) }.sort_by { |p| p.name }
-  end
+post '/e/:page' do
+  @page = Page.new(params[:page])
+  @page.update(params[:body], params[:message])
+  redirect '/' + @page.name
+end
 
-  attr_reader :name
+post '/eip/:page' do
+  @page = Page.new(params[:page])
+  @page.update(params[:body])
+  @page.body
+end
 
-  def initialize(name)
-    @name = name
-    @filename = File.join(GIT_REPOSITORY, @name)
-  end
+get '/h/:page' do
+  @page = Page.new(params[:page])
+  show :history, &quot;History of #{@page.name}&quot;
+end
 
-  def body
-    RedCloth.new(raw_body).to_html.
-      gsub(/\b((?:[A-Z]\w+){2,})/) do |page|
-        &quot;&lt;a class='#{Page.new(page).tracked? ? 'exists' : 'unknown'}' href='#{page}'&gt;#{page}&lt;/a&gt;&quot;
-      end
-  end
+get '/h/:page/:rev' do
+  @page = Page.new(params[:page], params[:rev])
+  show :show, &quot;#{@page.name} (version #{params[:rev]})&quot;
+end
 
-  def raw_body
-    File.exists?(@filename) ? File.read(@filename) : ''
-  end
+get '/d/:page/:rev' do
+  @page = Page.new(params[:page])
+  show :delta, &quot;Diff of #{@page.name}&quot;
+end
 
-  def body=(content)
-    return if content == raw_body
-    File.open(@filename, 'w') { |f| f &lt;&lt; content }
-    message = tracked? ? &quot;Edited #{@name}&quot; : &quot;Created #{@name}&quot;
-    Page.repo.add(@name)
-    Page.repo.commit(message)
-  end
+# application paths (/a/ namespace)
 
-  def tracked?
-    Page.repo.ls_files.keys.include?(@name)
-  end
+get '/a/list' do
+  pages = $repo.log.first.gtree.children
+  @pages = pages.select { |f,bl| f[0,1] != '_'}.sort.map { |name, blob| Page.new(name) } rescue []
+  show(:list, 'Listing pages')  
+end
 
-  def to_s
-    @name
-  end
+get '/a/patch/:page/:rev' do
+  @page = Page.new(params[:page])
+  header 'Content-Type' =&gt; 'text/x-diff'
+  header 'Content-Disposition' =&gt; 'filename=patch.diff'
+  @page.delta(params[:rev])
 end
 
-use_in_file_templates!
-
-configure do
-  GIT_REPOSITORY = ENV['WIKI'] || File.join(ENV['HOME'], 'wiki')
-  HOMEPAGE = 'Home'
-  set_option :haml, :format =&gt; :html4
-
-  unless File.exists?(GIT_REPOSITORY) &amp;&amp; File.directory?(GIT_REPOSITORY)
-    puts &quot;Initializing repository in #{GIT_REPOSITORY}&quot;
-    Git.init(GIT_REPOSITORY)
-    File.open(File.join(GIT_REPOSITORY, HOMEPAGE), 'w') do |f|
-      f.write(&lt;&lt;-EOF)
-## Welcome on git-wiki
-Congratulation, you managed to successfuly run git-wiki!   
-Feel free to edit this page (double-clik it) and start to use your wiki.  
-To access the page listing, hit &lt;kbd&gt;CTRL+L&lt;/kbd&gt; and &lt;kbd&gt;CTRL+H&lt;/kbd&gt; to go to the homepage.
-EOF
-    end
+get '/a/tarball' do
+  header 'Content-Type' =&gt; 'application/x-gzip'
+  header 'Content-Disposition' =&gt; 'filename=archive.tgz'
+  archive = $repo.archive('HEAD', nil, :format =&gt; 'tgz', :prefix =&gt; 'wiki/')
+  File.open(archive).read
+end
 
-    repository = Git.open(GIT_REPOSITORY)
-    repository.add(HOMEPAGE)
-    repository.commit('Initial commit')
-  end
+get '/a/branches' do
+  @branches = $repo.branches
+  show :branches, &quot;Branches List&quot;
+end
 
-  Page.repo = repository || Git.open(GIT_REPOSITORY)
+get '/a/branch/:branch' do
+  $repo.checkout(params[:branch])
+  redirect '/' + HOMEPAGE
 end
 
+get '/a/history' do
+  @history = $repo.log
+  show :branch_history, &quot;Branch History&quot;
+end
 
-helpers do
-  def title(title=nil)
-    @title = title unless title.nil?
-    @title
+get '/a/revert_branch/:sha' do
+  $repo.with_temp_index do 
+    $repo.read_tree params[:sha]
+    $repo.checkout_index
+    $repo.commit('reverted branch')
   end
+  redirect '/a/history'
+end
 
-  def list_item(page)
-    &quot;&lt;a class='page_name' href='/#{page}'&gt;#{page}&lt;/a&gt;&amp;nbsp;&lt;a class='edit' href='/e/#{page}'&gt;edit&lt;/a&gt;&quot;
-  end
+get '/a/merge_branch/:branch' do
+  $repo.merge(params[:branch])
+  redirect '/' + HOMEPAGE
 end
 
-before do
-  # unless config['username'].nil? &amp;&amp; config['password'].nil?
-    authenticate_or_request_with_http_basic &quot;GitWiki&quot; do
-      |user, pass| user == config['username'] &amp;&amp; pass == config['password']
-    end
-  # end
-  content_type 'text/html', :charset =&gt; 'utf-8'
+get '/a/delete_branch/:branch' do
+  $repo.branch(params[:branch]).delete
+  redirect '/a/branches'
 end
 
-get('/') { redirect '/' + HOMEPAGE }
+post '/a/new_branch' do
+  $repo.branch(params[:branch]).create
+  $repo.checkout(params[:branch])
+  if params[:type] == 'blank'
+    # clear out the branch
+    $repo.chdir do 
+      Dir.glob(&quot;*&quot;).each do |f|
+        File.unlink(f)
+        $repo.remove(f)
+      end
+      touchfile
+      $repo.commit('clean branch start')
+    end
+  end
+  redirect '/a/branches'
+end
 
-get('/_stylesheet.css') do
-  content_type 'text/css', :charset =&gt; 'utf-8'
-  sass :stylesheet
+post '/a/new_remote' do
+  $repo.add_remote(params[:branch_name], params[:branch_url])
+  $repo.fetch(params[:branch_name])
+  redirect '/a/branches'
 end
 
-get '/_list' do
-  @pages = Page.find_all
-  haml :list
+get '/a/search' do
+  @search = params[:search]
+  @grep = $repo.grep(@search)
+  show :search, 'Search Results'
 end
 
-get '/:page' do
+# file upload attachments
+
+get '/a/file/upload/:page' do
   @page = Page.new(params[:page])
-  @page.tracked? ? haml(:show) : redirect(&quot;/e/#{@page.name}&quot;)
+  show :attach, 'Attach File for ' + @page.name
 end
 
-# Waiting for Black's new awesome route system
-get '/:page.txt' do
+post '/a/file/upload/:page' do
   @page = Page.new(params[:page])
-  throw :halt, [404, &quot;Unknown page #{params[:page]}&quot;] unless @page.tracked?
-  content_type 'text/plain', :charset =&gt; 'utf-8'
-  @page.raw_body
+  @page.save_file(params[:file], params[:name])
+  redirect '/e/' + @page.name
 end
 
-get '/e/:page' do
+get '/a/file/delete/:page/:file.:ext' do
   @page = Page.new(params[:page])
-  haml :edit
+  @page.delete_file(params[:file] + '.' + params[:ext])
+  redirect '/e/' + @page.name
 end
 
-post '/e/:page' do
+get '/_attachment/:page/:file.:ext' do
   @page = Page.new(params[:page])
-  @page.body = params[:body]
-  request.xhr? ? @page.body : redirect(&quot;/#{@page.name}&quot;)
+  send_file(File.join(@page.attach_dir, params[:file] + '.' + params[:ext]))
 end
 
-__END__
-@@ layout
-!!! strict
-%html
-  %head
-    %title= title
-    %link{:rel =&gt; 'stylesheet', :href =&gt; '/_stylesheet.css', :type =&gt; 'text/css'}
-    %script{:src =&gt; '/jquery-1.2.3.min.js', :type =&gt; 'text/javascript'}
-    %script{:src =&gt; '/jquery.jeditable.js', :type =&gt; 'text/javascript'}
-    %script{:src =&gt; '/jquery.autogrow.js', :type =&gt; 'text/javascript'}
-    %script{:src =&gt; '/jquery.hotkeys.js', :type =&gt; 'text/javascript'}
-    :javascript
-      $(document).ready(function() {
-        $('#navigation').hide();
-        $('#edit_link').hide();
-        $.hotkeys.add('Ctrl+h', function() { document.location = '/#{HOMEPAGE}' })
-        $.hotkeys.add('Ctrl+l', function() { document.location = '/_list' })
-      })
-  %body
-    %ul#navigation
-      %li
-        %a{:href =&gt; '/'} Home
-      %li
-        %a{:href =&gt; '/_list'} List
-    #content= yield
-
-@@ show
-- title @page.name
-:javascript
-  $(document).ready(function() {
-    $.editable.addInputType('autogrow', {
-      element : function(settings, original) {
-        var textarea = $('&lt;textarea&gt;');
-        if (settings.rows) {
-          textarea.attr('rows', settings.rows);
-        } else {
-          textarea.height(settings.height);
-        }
-        if (settings.cols) {
-          textarea.attr('cols', settings.cols);
-        } else {
-          textarea.width(settings.width);
-        }
-        $(this).append(textarea);
-        return(textarea);
-      },
-      plugin : function(settings, original) {
-        $('textarea', this).autogrow(settings.autogrow);
-      }
-    });
-
-    $('#page_content').editable('/e/#{@page}', {
-      loadurl: '/#{@page}.txt',
-      submit: '&lt;button class=&quot;submit&quot; type=&quot;submit&quot;&gt;Save as the newest version&lt;/button&gt;',
-      cancel: '&lt;a class=&quot;cancel&quot; href=&quot;&quot; style=&quot;margin-left: 5px;&quot;&gt;cancel&lt;/a&gt;',
-      event: 'dblclick',
-      type: 'autogrow',
-      cols: 84,
-      rows: 20,
-      name: 'body',
-      onblur: 'ignore',
-      tooltip: ' ',
-      indicator: 'Saving...',
-      loadtext: '',
-      cssclass: 'edit_form',
-      callback: function(v, s) {
-        /**notice = $('&lt;p id=&quot;notice&quot;&gt;New version successfuly saved!&lt;/p&gt;').fadeOut('slow')
-        $('#content').prepend(notice.html())*/
-      }
-    })
-  })
-%a#edit_link{:href =&gt; &quot;/e/#{@page}&quot;} edit this page
-%h1= title
-#page_content= @page.body
-
-@@ edit
-- title &quot;Editing #{@page}&quot;
-
-%h1= title
-%form{:method =&gt; 'POST', :action =&gt; &quot;/e/#{@page}&quot;}
-  %p
-    %textarea{:name =&gt; 'body', :rows =&gt; 16, :cols =&gt; 60}= @page.raw_body
-  %p
-    %input.submit{:type =&gt; :submit, :value =&gt; 'Save as the newest version'}
-    or
-    %a.cancel{:href=&gt;&quot;/#{@page}&quot;} cancel
-
-@@ list
-- title &quot;Listing pages&quot;
-
-%h1 All pages
-- if @pages.empty?
-%p No pages found.
-- else
-  %ul#pages_list
-  - @pages.each_with_index do |page, index|
-    - if (index % 2) == 0
-      %li.odd= list_item(page)
-    - else
-      %li.even= list_item(page)
-  - end
-
-@@ stylesheet
-body
-  :font
-    family: &quot;Lucida Grande&quot;, Verdana, Arial, Bitstream Vera Sans, Helvetica, sans-serif
-    size: 14px
-    color: black
-  line-height: 160%
-  background-color: white
-  margin: 0
-  padding: 0
-
-#navigation
-  padding-left: 2em
-  margin: 0
-  li
-    list-style-type: none
-    display: inline
-
-#content
-  padding: 2em
-.notice
-  background-color: #ffc
-  padding: 6px
-
-a
-  padding: 2px
-  color: blue
-  &amp;.exists
-    &amp;:hover
-      background-color: blue
-      text-decoration: none
-      color: white
-  &amp;.unknown
-    color: gray
-    &amp;:hover
-      background-color: gray
-      color: white
-      text-decoration: none
-
-textarea
-  font-family: courrier
-  padding: 5px
-  font-size: 14px
-  line-height: 18px
-
-.edit_link
-  display: block
-  background-color: #ffc
-  font-weight: bold
-  text-decoration: none
-  color: black
-  &amp;:hover
-    color: white
-    background-color: red
-
-.submit
-  font-weight: bold
-
-.cancel
-  color: red
-  &amp;:hover
-    text-decoration: none
-    background-color: red
-    color: white
-ul#pages_list
-  list-style-type: none
-  margin: 0
-  padding: 0
-  li
-    padding: 5px
-    a.edit
-      display: none 
-    &amp;.odd
-      background-color: #D3D3D3
+# support methods
+
+def page_url(page)
+  &quot;#{request.env[&quot;rack.url_scheme&quot;]}://#{request.env[&quot;HTTP_HOST&quot;]}/#{page}&quot;
+end
+
+private
+
+  def show(template, title)
+    @title = title
+    erb(template)
+  end
+
+  def touchfile
+    # adds meta file to repo so we have somthing to commit initially
+    $repo.chdir do
+      f = File.new(&quot;.meta&quot;,  &quot;w+&quot;)
+      f.puts($repo.current_branch)
+      f.close
+      $repo.add('.meta')
+    end
+  end</diff>
      <filename>git-wiki.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1786144a30eab355df675d39123b1e5eda41a820</id>
    </parent>
    <parent>
      <id>9e6c6a09b013a9143afc3414b8eeabd20279deff</id>
    </parent>
  </parents>
  <author>
    <name>Jesse Newland</name>
    <email>jnewland@gmail.com</email>
  </author>
  <url>http://github.com/bmizerany/git-wiki/commit/69b32fd2e377c170788c7d7428f509a6ea1bdd48</url>
  <id>69b32fd2e377c170788c7d7428f509a6ea1bdd48</id>
  <committed-date>2008-05-14T19:31:48-07:00</committed-date>
  <authored-date>2008-05-14T19:31:48-07:00</authored-date>
  <message>merge al3x/master</message>
  <tree>9a6b3f75df4f481cd6491f0689529ffaed57b5f3</tree>
  <committer>
    <name>Jesse Newland</name>
    <email>jnewland@gmail.com</email>
  </committer>
</commit>
