Skip to content

Commit 6d634d7

Browse files
author
scott Chacon
committed
can now remove repos and clone/pull from the url
1 parent 303ffc8 commit 6d634d7

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

camping/gitweb.rb

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# install dependencies
77
# sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
88
#
9+
# todo
10+
# - diff/patch between any two objects
11+
#
912
# author : scott chacon
1013
#
1114

@@ -26,13 +29,7 @@ def self.up
2629
end
2730

2831
module GitWeb::Controllers
29-
class Index < R '/'
30-
def get
31-
@repos = Repository.find :all
32-
render :index
33-
end
34-
end
35-
32+
3633
class Stylesheet < R '/css/highlight.css'
3734
def get
3835
@headers['Content-Type'] = 'text/css'
@@ -48,21 +45,14 @@ def get
4845
end
4946
end
5047

51-
class View < R '/view/(\d+)'
52-
def get repo_id
53-
@repo = Repository.find repo_id
54-
@git = Git.bare(@repo.path)
55-
render :view
56-
end
57-
end
5848

59-
class Fetch < R '/git/(\d+)'
60-
def get repo_id
61-
@repo = Repository.find repo_id
62-
@git = Git.bare(@repo.path)
49+
class Index < R '/'
50+
def get
51+
@repos = Repository.find :all
52+
render :index
6353
end
6454
end
65-
55+
6656
class Add < R '/add'
6757
def get
6858
@repo = Repository.new
@@ -77,7 +67,33 @@ def post
7767
end
7868
end
7969
end
80-
70+
71+
class RemoveRepo < R '/remove/(\d+)'
72+
def get repo_id
73+
@repo = Repository.find repo_id
74+
@repo.destroy
75+
@repos = Repository.find :all
76+
render :index
77+
end
78+
end
79+
80+
81+
class View < R '/view/(\d+)'
82+
def get repo_id
83+
@repo = Repository.find repo_id
84+
@git = Git.bare(@repo.path)
85+
render :view
86+
end
87+
end
88+
89+
class Fetch < R '/git/(\d+)/(.*)'
90+
def get repo_id, path
91+
@repo = Repository.find repo_id
92+
@git = Git.bare(@repo.path)
93+
File.read(File.join(@git.repo.path, path))
94+
end
95+
end
96+
8197
class Commit < R '/commit/(\d+)/(\w+)'
8298
def get repo_id, sha
8399
@repo = Repository.find repo_id
@@ -181,14 +197,16 @@ def layout
181197
end
182198
end
183199

200+
# git repo views
201+
184202
def view
185203
h1 @repo.name
186204
h2 @repo.path
187205

188206
@tags = {}
189207
@git.tags.each { |tag| @tags[tag.sha] ||= []; @tags[tag.sha] << tag.name }
190208

191-
url = 'http:' + URL(Fetch, @repo.id).to_s
209+
url = 'http:' + URL(Fetch, @repo.id, '').to_s
192210

193211
h3 'info'
194212
table.info do
@@ -323,11 +341,7 @@ def diff
323341
end
324342
end
325343

326-
327-
def cycle(v1, v2)
328-
(@value == v1) ? @value = v2 : @value = v1
329-
@value
330-
end
344+
# repo management views
331345

332346
def add
333347
_form(@repo)
@@ -352,12 +366,22 @@ def _form(repo)
352366
def index
353367
@repos.each do | repo |
354368
h1 repo.name
369+
a 'remove', :href => R(RemoveRepo, repo.id)
370+
span.space ' '
355371
a repo.path, :href => R(View, repo.id)
356372
end
357373
br
358374
br
359375
a 'add new repo', :href => R(Add)
360376
end
377+
378+
# convenience functions
379+
380+
def cycle(v1, v2)
381+
(@value == v1) ? @value = v2 : @value = v1
382+
@value
383+
end
384+
361385
end
362386

363387
def GitWeb.create

0 commit comments

Comments
 (0)