git-object-browser 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +17 -0
- data/htdocs/{css → common/css}/angular-ui.min.css +0 -0
- data/htdocs/{css → common/css}/bootstrap-responsive.css +0 -0
- data/htdocs/{css → common/css}/bootstrap-responsive.min.css +0 -0
- data/htdocs/{css → common/css}/bootstrap.css +0 -0
- data/htdocs/{css → common/css}/bootstrap.min.css +0 -0
- data/htdocs/{css → common/css}/font-awesome-ie7.css +0 -0
- data/htdocs/{css → common/css}/font-awesome.css +0 -0
- data/htdocs/{css → common/css}/main.css +0 -0
- data/htdocs/{font → common/font}/fontawesome-webfont.eot +0 -0
- data/htdocs/{font → common/font}/fontawesome-webfont.svg +0 -0
- data/htdocs/{font → common/font}/fontawesome-webfont.ttf +0 -0
- data/htdocs/{font → common/font}/fontawesome-webfont.woff +0 -0
- data/htdocs/{img → common/img}/glyphicons-halflings-white.png +0 -0
- data/htdocs/{img → common/img}/glyphicons-halflings.png +0 -0
- data/htdocs/common/js/main.js +495 -0
- data/htdocs/{js → common/js}/vendor/angular-bootstrap-prettify.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-bootstrap.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-cookies.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-loader.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-resource.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-sanitize.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-ui-ieshiv.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular-ui.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular.js +0 -0
- data/htdocs/{js → common/js}/vendor/angular.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/bootstrap.js +0 -0
- data/htdocs/{js → common/js}/vendor/bootstrap.min.js +0 -0
- data/htdocs/{js → common/js}/vendor/html5shiv.js +0 -0
- data/htdocs/{js → common/js}/vendor/jquery-1.8.2.min.js +0 -0
- data/htdocs/{templates → common/templates}/directory.html +2 -2
- data/htdocs/common/templates/error.html +6 -0
- data/htdocs/{templates → common/templates}/file.html +0 -0
- data/htdocs/{templates → common/templates}/git.html +0 -0
- data/htdocs/{templates → common/templates}/index.html +1 -1
- data/htdocs/{templates → common/templates}/index_entry.html +0 -0
- data/htdocs/{templates → common/templates}/info_refs.html +2 -2
- data/htdocs/{templates → common/templates}/loading.html +0 -0
- data/htdocs/{templates → common/templates}/notfound.html +1 -2
- data/htdocs/{templates → common/templates}/object.html +1 -1
- data/htdocs/{templates → common/templates}/objects.html +3 -3
- data/htdocs/{templates → common/templates}/pack_file.html +1 -1
- data/htdocs/common/templates/pack_index.html +39 -0
- data/htdocs/{templates → common/templates}/packed_object.html +4 -4
- data/htdocs/{templates → common/templates}/packed_refs.html +2 -2
- data/htdocs/{templates → common/templates}/ref.html +0 -0
- data/htdocs/common/templates/reflog.html +29 -0
- data/htdocs/config.js +6 -0
- data/htdocs/default.js +7 -0
- data/htdocs/index.html +52 -20
- data/lib/git-object-browser.rb +12 -4
- data/lib/git-object-browser/dumper/directories_dumper.rb +42 -0
- data/lib/git-object-browser/dumper/index_dumper.rb +20 -7
- data/lib/git-object-browser/dumper/info_refs_dumper.rb +37 -0
- data/lib/git-object-browser/dumper/main.rb +188 -81
- data/lib/git-object-browser/dumper/objects_dumper.rb +46 -0
- data/lib/git-object-browser/dumper/pack_indexes_dumper.rb +85 -0
- data/lib/git-object-browser/dumper/packed_objects_dumper.rb +36 -0
- data/lib/git-object-browser/dumper/packed_refs_dumper.rb +37 -0
- data/lib/git-object-browser/dumper/plain_files_dumper.rb +74 -0
- data/lib/git-object-browser/dumper/refs_dumper.rb +46 -0
- data/lib/git-object-browser/main.rb +22 -6
- data/lib/git-object-browser/models/directory.rb +5 -3
- data/lib/git-object-browser/models/git_date.rb +26 -0
- data/lib/git-object-browser/models/git_object.rb +1 -1
- data/lib/git-object-browser/models/pack_file.rb +1 -1
- data/lib/git-object-browser/models/pack_index.rb +139 -25
- data/lib/git-object-browser/models/packed_object.rb +1 -1
- data/lib/git-object-browser/models/reflog.rb +54 -0
- data/lib/git-object-browser/models/wrapped_object.rb +40 -0
- data/lib/git-object-browser/server/git_servlet.rb +130 -100
- data/lib/git-object-browser/server/main.rb +1 -1
- data/lib/git-object-browser/version.rb +1 -1
- metadata +62 -50
- data/htdocs/js/main.js +0 -285
- data/htdocs/templates/pack_index.html +0 -37
- data/lib/git-object-browser/dumper/object_dumper.rb +0 -20
- data/lib/git-object-browser/dumper/pack_index_dumper.rb +0 -21
- data/lib/git-object-browser/dumper/packed_object_dumper.rb +0 -19
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
module GitObjectBrowser
|
|
3
|
+
|
|
4
|
+
module Models
|
|
5
|
+
|
|
6
|
+
class Reflog
|
|
7
|
+
def initialize(input)
|
|
8
|
+
@in = input
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse
|
|
12
|
+
@entries = []
|
|
13
|
+
@content = @in.read(nil)
|
|
14
|
+
@content = @content.force_encoding('UTF-8')
|
|
15
|
+
unless @content.valid_encoding?
|
|
16
|
+
@content = '(not UTF-8)'
|
|
17
|
+
return self
|
|
18
|
+
end
|
|
19
|
+
parse_logs
|
|
20
|
+
self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def parse_logs
|
|
24
|
+
@content.split(/\n/).each do |line|
|
|
25
|
+
log = {}
|
|
26
|
+
(data, log[:message]) = line.split(/\t/, 2)
|
|
27
|
+
if data.to_s =~ /\A([0-9a-f]{40}) ([0-9a-f]{40}) (.+)/
|
|
28
|
+
log[:sha1_from] = $1
|
|
29
|
+
log[:sha1_to] = $2
|
|
30
|
+
data = $3
|
|
31
|
+
if data =~ /(.*) <(.*)> (\d+)(?: ((?:(?:\+|-)(?:\d{4}|\d{2}:\d{2}))|Z))?\z/
|
|
32
|
+
log[:name] = $1
|
|
33
|
+
log[:email] = $2
|
|
34
|
+
log[:unixtime] = $3
|
|
35
|
+
log[:timezone] = $4
|
|
36
|
+
log[:date] = GitDate.new($3, $4).to_s
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
@entries << log
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
private :parse_logs
|
|
43
|
+
|
|
44
|
+
def to_hash
|
|
45
|
+
return { :content => @content, :entries => @entries }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.path?(relpath)
|
|
49
|
+
return relpath =~ %r{\Alogs/.+}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
module GitObjectBrowser
|
|
3
|
+
|
|
4
|
+
module Models
|
|
5
|
+
|
|
6
|
+
class WrappedObject < Hash
|
|
7
|
+
|
|
8
|
+
def initialize(root, path, obj)
|
|
9
|
+
super()
|
|
10
|
+
self[:type] = {
|
|
11
|
+
Directory => 'directory',
|
|
12
|
+
PlainFile => 'file',
|
|
13
|
+
Index => 'index',
|
|
14
|
+
GitObject => 'object',
|
|
15
|
+
Ref => 'ref',
|
|
16
|
+
Reflog => 'reflog',
|
|
17
|
+
PackIndex => 'pack_index',
|
|
18
|
+
PackFile => 'pack_file',
|
|
19
|
+
PackedObject => 'packed_object',
|
|
20
|
+
InfoRefs => 'info_refs',
|
|
21
|
+
PackedRefs => 'packed_refs',
|
|
22
|
+
}[obj.class]
|
|
23
|
+
|
|
24
|
+
self[:object] = obj.to_hash
|
|
25
|
+
self[:root] = root
|
|
26
|
+
self[:path] = path
|
|
27
|
+
self[:working_dir] = File.basename(File.dirname(root.to_s))
|
|
28
|
+
|
|
29
|
+
case(self[:type])
|
|
30
|
+
when 'packed_object'
|
|
31
|
+
sha1 = self[:object][:object][:sha1]
|
|
32
|
+
unpacked_file = File.join(root.to_s, 'objects', sha1[0..1], sha1[2..-1]).to_s
|
|
33
|
+
self[:unpacked] = File.exist?(unpacked_file)
|
|
34
|
+
when 'pack_index'
|
|
35
|
+
self.merge!(obj.page_data)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -1,49 +1,76 @@
|
|
|
1
|
-
|
|
2
1
|
module GitObjectBrowser
|
|
3
2
|
|
|
4
3
|
module Server
|
|
5
4
|
|
|
6
5
|
class GitServlet < WEBrick::HTTPServlet::AbstractServlet
|
|
6
|
+
|
|
7
|
+
SEARCH_PACKED_OBJECT = true
|
|
8
|
+
|
|
7
9
|
def initialize(server, target)
|
|
8
10
|
@target = File.expand_path(target)
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def do_GET(request, response)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
unless path =~ %r{/.git(?:/(.*))?}
|
|
14
|
+
@params = parse_params(request, response)
|
|
15
|
+
unless @params
|
|
15
16
|
not_found(response)
|
|
16
17
|
return
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
unless File.exist?(path)
|
|
22
|
-
not_found(response) unless redirect_to_packed_object(response)
|
|
20
|
+
unless File.exist?(@params[:abspath])
|
|
21
|
+
not_found unless redirect_to_packed_object
|
|
23
22
|
return
|
|
24
23
|
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
[:response_directory,
|
|
26
|
+
:response_index,
|
|
27
|
+
:response_object,
|
|
28
|
+
:response_ref,
|
|
29
|
+
:response_reflog,
|
|
30
|
+
:response_packed_object,
|
|
31
|
+
:response_pack_file,
|
|
32
|
+
:response_pack_index,
|
|
33
|
+
:response_info_refs,
|
|
34
|
+
:response_packed_refs,
|
|
35
|
+
:response_file
|
|
36
|
+
].each { |action| return if send(action) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def parse_params(request, response)
|
|
43
|
+
params = { :request => request, :response => response }
|
|
44
|
+
|
|
45
|
+
path = request.path
|
|
46
|
+
return nil unless path =~ %r{\A/json/(.+)\.json\z}
|
|
47
|
+
params[:relpath] = $1.to_s
|
|
48
|
+
|
|
49
|
+
pack_rex = 'objects/pack/pack-[0-9a-f]{40}'
|
|
50
|
+
if params[:relpath] == '_git'
|
|
51
|
+
params[:relpath] = ''
|
|
52
|
+
elsif params[:relpath] =~ %r{\A(#{ pack_rex }\.pack)/\d{2}/\d{2}/(\d+)\z}
|
|
53
|
+
params[:relpath] = $1
|
|
54
|
+
params[:offset] = $2.to_i
|
|
55
|
+
elsif params[:relpath] =~ %r{\A(#{ pack_rex }\.idx)\z}
|
|
56
|
+
params[:relpath] = $1
|
|
57
|
+
params[:order] = 'digest'
|
|
58
|
+
elsif params[:relpath] =~ %r{\A(#{ pack_rex }\.idx)/(sha1|offset)/(\d+)\z}
|
|
59
|
+
params[:relpath] = $1
|
|
60
|
+
params[:order] = $2
|
|
61
|
+
params[:page] = $3.to_i
|
|
29
62
|
end
|
|
63
|
+
return nil if params[:relpath] =~ /\.\./
|
|
30
64
|
|
|
31
|
-
|
|
32
|
-
return if response_index(response)
|
|
33
|
-
return if response_object(response)
|
|
34
|
-
return if response_ref(response)
|
|
35
|
-
return if response_packed_object(response, request.query["offset"])
|
|
36
|
-
return if response_pack_file(response)
|
|
37
|
-
return if response_pack_index(response)
|
|
38
|
-
return if response_info_refs(response)
|
|
39
|
-
return if response_packed_refs(response)
|
|
65
|
+
params[:abspath] = File.join(@target, params[:relpath])
|
|
40
66
|
|
|
41
|
-
|
|
67
|
+
return params
|
|
42
68
|
end
|
|
43
69
|
|
|
44
|
-
def redirect_to_packed_object
|
|
45
|
-
return false unless
|
|
46
|
-
|
|
70
|
+
def redirect_to_packed_object
|
|
71
|
+
return false unless SEARCH_PACKED_OBJECT
|
|
72
|
+
return false unless GitObjectBrowser::Models::GitObject.path?(@params[:relpath])
|
|
73
|
+
sha1 = @params[:relpath].gsub(%r{\A.*/([0-9a-f]{2})/([0-9a-f]{38})\z}, '\1\2')
|
|
47
74
|
|
|
48
75
|
Dir.chdir(@target) do
|
|
49
76
|
Dir.glob('objects/pack/*.idx') do |path|
|
|
@@ -52,8 +79,9 @@ module GitObjectBrowser
|
|
|
52
79
|
result = index.find(sha1)
|
|
53
80
|
unless result.nil?
|
|
54
81
|
packfile = path.sub(/\.idx\z/, '.pack')
|
|
55
|
-
response.status = 302
|
|
56
|
-
|
|
82
|
+
@params[:response].status = 302
|
|
83
|
+
ostr = "0000#{ result[:offset] }"
|
|
84
|
+
@params[:response]['Location'] = "/json/#{ packfile }/#{ ostr[-2,2] }/#{ ostr[-4,2] }/#{ result[:offset] }.json"
|
|
57
85
|
return true
|
|
58
86
|
end
|
|
59
87
|
end
|
|
@@ -62,153 +90,155 @@ module GitObjectBrowser
|
|
|
62
90
|
false
|
|
63
91
|
end
|
|
64
92
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
hash = {}
|
|
68
|
-
hash[:type] = type
|
|
69
|
-
hash[:object] = obj.to_hash
|
|
70
|
-
hash[:root] = @target
|
|
71
|
-
hash[:path] = @relpath
|
|
72
|
-
hash[:wroking_dir] = File.basename(File.dirname(@target))
|
|
73
|
-
|
|
74
|
-
if type == 'packed_object'
|
|
75
|
-
sha1 = hash[:object][:object][:sha1]
|
|
76
|
-
hash[:unpacked] = File.exist?(File.join(@target, 'objects', sha1[0..1], sha1[2..-1]).to_s)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
response.body = ::JSON.generate(hash)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def response_directory(response)
|
|
83
|
-
return false unless File.directory?(File.join(@target, @relpath))
|
|
93
|
+
def response_directory
|
|
94
|
+
return false unless File.directory?(@params[:abspath])
|
|
84
95
|
|
|
85
|
-
obj = GitObjectBrowser::Models::Directory.new(@target, @relpath)
|
|
86
|
-
response_wrapped_object(
|
|
96
|
+
obj = GitObjectBrowser::Models::Directory.new(@target, @params[:relpath])
|
|
97
|
+
response_wrapped_object(obj)
|
|
87
98
|
return true
|
|
88
99
|
end
|
|
89
100
|
|
|
90
|
-
def response_index
|
|
91
|
-
return false unless @relpath ==
|
|
101
|
+
def response_index
|
|
102
|
+
return false unless @params[:relpath] == 'index'
|
|
92
103
|
|
|
93
104
|
obj = {}
|
|
94
|
-
File.open(
|
|
105
|
+
File.open(@params[:abspath]) do |input|
|
|
95
106
|
obj = GitObjectBrowser::Models::Index.new(input).parse
|
|
96
107
|
end
|
|
97
|
-
response_wrapped_object(
|
|
108
|
+
response_wrapped_object(obj)
|
|
98
109
|
return true
|
|
99
110
|
end
|
|
100
111
|
|
|
101
|
-
def response_object
|
|
102
|
-
return false unless GitObjectBrowser::Models::GitObject.path?(@relpath)
|
|
112
|
+
def response_object
|
|
113
|
+
return false unless GitObjectBrowser::Models::GitObject.path?(@params[:relpath])
|
|
103
114
|
|
|
104
115
|
obj = {}
|
|
105
|
-
File.open(
|
|
116
|
+
File.open(@params[:abspath]) do |input|
|
|
106
117
|
obj = GitObjectBrowser::Models::GitObject.new(input).parse
|
|
107
118
|
end
|
|
108
|
-
response_wrapped_object(
|
|
119
|
+
response_wrapped_object(obj)
|
|
109
120
|
return true
|
|
110
121
|
end
|
|
111
122
|
|
|
112
|
-
def response_ref
|
|
113
|
-
return false unless GitObjectBrowser::Models::Ref.path?(@relpath)
|
|
123
|
+
def response_ref
|
|
124
|
+
return false unless GitObjectBrowser::Models::Ref.path?(@params[:relpath])
|
|
114
125
|
|
|
115
126
|
obj = {}
|
|
116
|
-
File.open(
|
|
127
|
+
File.open(@params[:abspath]) do |input|
|
|
117
128
|
obj = GitObjectBrowser::Models::Ref.new(input)
|
|
118
129
|
end
|
|
119
|
-
response_wrapped_object(
|
|
130
|
+
response_wrapped_object(obj)
|
|
120
131
|
return true
|
|
121
132
|
end
|
|
122
133
|
|
|
123
|
-
def
|
|
124
|
-
return false unless GitObjectBrowser::Models::
|
|
134
|
+
def response_reflog
|
|
135
|
+
return false unless GitObjectBrowser::Models::Reflog.path?(@params[:relpath])
|
|
136
|
+
|
|
125
137
|
obj = {}
|
|
126
|
-
File.open(
|
|
127
|
-
obj = GitObjectBrowser::Models::
|
|
128
|
-
end
|
|
129
|
-
File.open(index_to_pack_path) do |input|
|
|
130
|
-
obj.load_object_types(input)
|
|
138
|
+
File.open(@params[:abspath]) do |input|
|
|
139
|
+
obj = GitObjectBrowser::Models::Reflog.new(input).parse
|
|
131
140
|
end
|
|
132
|
-
response_wrapped_object(
|
|
141
|
+
response_wrapped_object(obj)
|
|
133
142
|
return true
|
|
134
143
|
end
|
|
135
144
|
|
|
136
|
-
def
|
|
137
|
-
return false unless GitObjectBrowser::Models::
|
|
145
|
+
def response_pack_index
|
|
146
|
+
return false unless GitObjectBrowser::Models::PackIndex.path?(@params[:relpath])
|
|
138
147
|
obj = {}
|
|
139
|
-
File.open(
|
|
140
|
-
obj = GitObjectBrowser::Models::
|
|
148
|
+
File.open(@params[:abspath]) do |input|
|
|
149
|
+
obj = GitObjectBrowser::Models::PackIndex.new(input).parse(@params[:order], @params[:page])
|
|
141
150
|
end
|
|
142
|
-
|
|
151
|
+
if @params[:order] != 'digest'
|
|
152
|
+
File.open(index_to_pack_path) do |input|
|
|
153
|
+
obj.load_object_types(input)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
response_wrapped_object(obj)
|
|
143
157
|
return true
|
|
144
158
|
end
|
|
145
159
|
|
|
146
|
-
def
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
def response_pack_file
|
|
161
|
+
return false unless GitObjectBrowser::Models::PackFile.path?(@params[:relpath])
|
|
162
|
+
obj = {}
|
|
163
|
+
File.open(@params[:abspath]) do |input|
|
|
164
|
+
obj = GitObjectBrowser::Models::PackFile.new(input).parse
|
|
165
|
+
end
|
|
166
|
+
response_wrapped_object(obj)
|
|
167
|
+
return true
|
|
152
168
|
end
|
|
153
169
|
|
|
154
|
-
def response_packed_object
|
|
155
|
-
return false if offset.nil?
|
|
156
|
-
return false unless GitObjectBrowser::Models::PackedObject.path?(@relpath)
|
|
170
|
+
def response_packed_object
|
|
171
|
+
return false if @params[:offset].nil?
|
|
172
|
+
return false unless GitObjectBrowser::Models::PackedObject.path?(@params[:relpath])
|
|
157
173
|
obj = {}
|
|
158
|
-
|
|
159
174
|
File.open(pack_to_index_path) do |index_input|
|
|
160
175
|
index = GitObjectBrowser::Models::PackIndex.new(index_input)
|
|
161
|
-
File.open(
|
|
162
|
-
obj = GitObjectBrowser::Models::PackedObject.new(index, input).parse(offset
|
|
176
|
+
File.open(@params[:abspath]) do |input|
|
|
177
|
+
obj = GitObjectBrowser::Models::PackedObject.new(index, input).parse(@params[:offset])
|
|
163
178
|
end
|
|
164
179
|
end
|
|
165
|
-
response_wrapped_object(
|
|
180
|
+
response_wrapped_object(obj)
|
|
166
181
|
return true
|
|
167
182
|
end
|
|
168
183
|
|
|
169
|
-
def response_info_refs
|
|
170
|
-
return false unless GitObjectBrowser::Models::InfoRefs.path?(@relpath)
|
|
184
|
+
def response_info_refs
|
|
185
|
+
return false unless GitObjectBrowser::Models::InfoRefs.path?(@params[:relpath])
|
|
171
186
|
|
|
172
187
|
obj = {}
|
|
173
|
-
File.open(
|
|
188
|
+
File.open(@params[:abspath]) do |input|
|
|
174
189
|
obj = GitObjectBrowser::Models::InfoRefs.new(input)
|
|
175
190
|
end
|
|
176
|
-
response_wrapped_object(
|
|
191
|
+
response_wrapped_object(obj)
|
|
177
192
|
return true
|
|
178
193
|
end
|
|
179
194
|
|
|
180
|
-
def response_packed_refs
|
|
181
|
-
return false unless GitObjectBrowser::Models::PackedRefs.path?(@relpath)
|
|
195
|
+
def response_packed_refs
|
|
196
|
+
return false unless GitObjectBrowser::Models::PackedRefs.path?(@params[:relpath])
|
|
182
197
|
|
|
183
198
|
obj = {}
|
|
184
|
-
File.open(
|
|
199
|
+
File.open(@params[:abspath]) do |input|
|
|
185
200
|
obj = GitObjectBrowser::Models::PackedRefs.new(input)
|
|
186
201
|
end
|
|
187
|
-
response_wrapped_object(
|
|
202
|
+
response_wrapped_object(obj)
|
|
188
203
|
return true
|
|
189
204
|
end
|
|
190
205
|
|
|
191
|
-
def response_file
|
|
192
|
-
path = File.join(@target, @relpath)
|
|
206
|
+
def response_file
|
|
193
207
|
obj = {}
|
|
194
|
-
File.open(
|
|
208
|
+
File.open(@params[:abspath]) do |input|
|
|
195
209
|
obj = GitObjectBrowser::Models::PlainFile.new(input).parse
|
|
196
210
|
end
|
|
197
|
-
response_wrapped_object(
|
|
211
|
+
response_wrapped_object(obj)
|
|
198
212
|
return true
|
|
199
213
|
end
|
|
200
214
|
|
|
201
|
-
|
|
215
|
+
|
|
216
|
+
def response_wrapped_object(obj)
|
|
217
|
+
wrapped = GitObjectBrowser::Models::WrappedObject.new(@target, @params[:relpath], obj)
|
|
218
|
+
@params[:response].body = ::JSON.generate(wrapped)
|
|
219
|
+
ok
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def ok(response = nil)
|
|
223
|
+
response ||= @params[:response]
|
|
202
224
|
response.status = 200
|
|
203
225
|
response['Content-Type'] = 'application/json'
|
|
204
226
|
end
|
|
205
227
|
|
|
206
|
-
def not_found(response)
|
|
228
|
+
def not_found(response = nil)
|
|
229
|
+
response ||= @params[:response]
|
|
207
230
|
response.status = 404
|
|
208
231
|
response['Content-Type'] = 'application/json'
|
|
209
232
|
response.body = '{}'
|
|
210
233
|
end
|
|
234
|
+
|
|
235
|
+
def index_to_pack_path
|
|
236
|
+
File.join(@target, @params[:relpath].sub(/\.idx\z/, '.pack'))
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def pack_to_index_path
|
|
240
|
+
File.join(@target, @params[:relpath].sub(/\.pack\z/, '.idx'))
|
|
241
|
+
end
|
|
211
242
|
end
|
|
212
243
|
end
|
|
213
244
|
end
|
|
214
|
-
|
|
@@ -15,7 +15,7 @@ module GitObjectBrowser
|
|
|
15
15
|
root = File.expand_path(File.join(root, "htdocs"))
|
|
16
16
|
opts = { :BindAddress => host, :Port => port, :DocumentRoot => root }
|
|
17
17
|
server = WEBrick::HTTPServer.new(opts)
|
|
18
|
-
server.mount('
|
|
18
|
+
server.mount('/json', GitServlet, @target)
|
|
19
19
|
trap 'INT' do
|
|
20
20
|
server.shutdown
|
|
21
21
|
end
|