git-object-browser 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/htdocs/js/main.js CHANGED
@@ -157,16 +157,15 @@ function GitCtrl($scope, $location, $routeParams, GitResource, PackedObjectResou
157
157
  'assume_valid_flag',
158
158
  'extended_flag',
159
159
  'stage',
160
- 'path'
160
+ 'name_length'
161
161
  ]
162
-
163
- if (version == 3) {
162
+ if (version > 2) {
164
163
  keys = keys.concat([
165
164
  'skip_worktree',
166
165
  'intent_to_add',
167
166
  ]);
168
167
  }
169
- keys.push('name_length');
168
+ keys.push('path')
170
169
 
171
170
  return keys;
172
171
  };
@@ -30,8 +30,10 @@ require "git-object-browser/models/plain_file"
30
30
  require "git-object-browser/server/main"
31
31
  require "git-object-browser/server/git_servlet"
32
32
 
33
- require "git-object-browser/dumper"
34
- require "git-object-browser/object_dumper"
35
- require "git-object-browser/index_dumper"
33
+ require "git-object-browser/dumper/main"
34
+ require "git-object-browser/dumper/object_dumper"
35
+ require "git-object-browser/dumper/index_dumper"
36
+ require "git-object-browser/dumper/pack_index_dumper"
37
+ require "git-object-browser/dumper/packed_object_dumper"
36
38
 
37
39
  GitObjectBrowser::Main.new().execute if __FILE__ == $0
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module GitObjectBrowser
4
+
5
+ module Dumper
6
+
7
+ class IndexDumper
8
+
9
+ def initialize(input, output)
10
+ @index = GitObjectBrowser::Models::Index.new(input)
11
+ @out = output
12
+ end
13
+
14
+ def dump
15
+ @out << JSON.pretty_generate(@index.parse.to_hash)
16
+
17
+ # template = File.join(GitObjectBrowser::Dumper::TEMPLATES_DIR, 'index.txt.erb')
18
+ # index = @index.parse.to_hash
19
+ # @out << ERB.new(File.read(template), nil, '-').result(binding)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,124 @@
1
+ module GitObjectBrowser
2
+ module Dumper
3
+
4
+ # TEMPLATES_DIR = File.join(File.dirname(__FILE__), '../../../templates/dumper')
5
+
6
+ class Main
7
+
8
+ def self.execute(target)
9
+ new(target).dump
10
+ end
11
+
12
+ def initialize(target)
13
+ @target = target
14
+ @outdir = File.join(target, "dump")
15
+ end
16
+
17
+ def dump
18
+ Dir.mkdir(@outdir) unless File.exist?(@outdir)
19
+ dump_index
20
+ dump_objects
21
+ dump_packed
22
+ end
23
+
24
+ def dump_index
25
+ index_file = File.join(@target, "index")
26
+ out_file = File.join(@outdir, "index")
27
+
28
+ return unless File.exist?(index_file)
29
+
30
+ STDERR << "Write: .git/dump/index\n"
31
+ File.open(index_file) do |input|
32
+ File.open(out_file, "w") do |output|
33
+ dumper = GitObjectBrowser::Dumper::IndexDumper.new(input, output)
34
+ dumper.dump
35
+ end
36
+ end
37
+ end
38
+
39
+ def dump_objects
40
+ obj_files = []
41
+ Dir.chdir(@target) do
42
+ Dir.glob("objects/**/*") do |path|
43
+ obj_files << path if File.file?(path) && path =~ %r{/[a-z0-9]{38}$}
44
+ end
45
+ end
46
+ return if obj_files.empty?
47
+
48
+ obj_dir = File.join(@outdir, "objects")
49
+ Dir.mkdir(obj_dir) unless File.exist?(obj_dir)
50
+
51
+ obj_files.each do |path|
52
+ outfile = File.join(@outdir, path)
53
+ next if File.exist?(outfile)
54
+
55
+ parent = File.dirname(outfile)
56
+ Dir.mkdir(parent) unless File.exist?(parent)
57
+
58
+ STDERR << "Write: .git/dump/objects/#{path}\n"
59
+ obj_file = File.join(@target, path)
60
+ File.open(obj_file) do |input|
61
+ File.open(outfile, "w") do |output|
62
+ dumper = GitObjectBrowser::Dumper::ObjectDumper.new(input, output)
63
+ dumper.dump
64
+ end
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ def dump_packed
71
+ files = []
72
+ Dir.chdir(@target) do
73
+ Dir.glob("objects/pack/*.idx") do |path|
74
+ files << path
75
+ end
76
+ end
77
+ return if files.empty?
78
+
79
+ obj_dir = File.join(@outdir, "objects")
80
+ Dir.mkdir(obj_dir) unless File.exist?(obj_dir)
81
+ pack_dir = File.join(@outdir, "objects/pack")
82
+ Dir.mkdir(pack_dir) unless File.exist?(pack_dir)
83
+
84
+ files.each do |path|
85
+ outfile = File.join(@outdir, path)
86
+ packpath = path.gsub(/\.idx\z/, '.pack')
87
+
88
+ STDERR << "Write: .git/dump/#{path}\n"
89
+ index_file = File.join(@target, path)
90
+ File.open(index_file) do |input|
91
+ File.open(outfile, "w") do |output|
92
+ dumper = GitObjectBrowser::Dumper::PackIndexDumper.new(input, output)
93
+ dumper.dump
94
+ index = dumper.pack_index
95
+ entries = index.to_hash[:entries]
96
+
97
+ File.open(File.join(@target, packpath)) do |pack_input|
98
+ object_dumper = GitObjectBrowser::Dumper::PackedObjectDumper.new(pack_input, index)
99
+ entries.each do |entry|
100
+ dump_packed_object(object_dumper, entry)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ def dump_packed_object(dumper, entry)
109
+ sha1_1 = entry[:sha1][0..1]
110
+ sha1_2 = entry[:sha1][2..-1]
111
+ obj_dir = File.join(@outdir, "objects", sha1_1)
112
+ Dir.mkdir(obj_dir) unless File.exist?(obj_dir)
113
+
114
+ outfile = File.join(obj_dir, sha1_2)
115
+ STDERR << "Write: .git/dump/objects/#{sha1_1}/#{sha1_2}\n"
116
+
117
+ File.open(outfile, "w") do |output|
118
+ dumper.dump(output, entry[:offset])
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module GitObjectBrowser
4
+
5
+ module Dumper
6
+
7
+ class ObjectDumper
8
+
9
+ def initialize(input, output)
10
+ @object = GitObjectBrowser::Models::GitObject.new(input)
11
+ @out = output
12
+ end
13
+
14
+ def dump
15
+ @out << JSON.pretty_generate(@object.parse.to_hash)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module GitObjectBrowser
4
+
5
+ module Dumper
6
+
7
+ class PackIndexDumper
8
+ attr_reader :pack_index
9
+
10
+ def initialize(input, output)
11
+ @pack_index = GitObjectBrowser::Models::PackIndex.new(input)
12
+ @out = output
13
+ end
14
+
15
+ def dump
16
+ @out << JSON.pretty_generate(@pack_index.parse.to_hash)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module GitObjectBrowser
4
+
5
+ module Dumper
6
+
7
+ class PackedObjectDumper
8
+
9
+ def initialize(input, index)
10
+ @object = GitObjectBrowser::Models::PackedObject.new(index, input)
11
+ end
12
+
13
+ def dump(output, offset)
14
+ output << JSON.pretty_generate(@object.parse(offset).to_hash)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -4,16 +4,16 @@ module GitObjectBrowser
4
4
  def execute
5
5
  host = '127.0.0.1'
6
6
  port = 8080
7
+ dump = false
7
8
  opts = OptionParser.new do |opts|
8
- opts.on('-p', '--port=PORT', 'port number') do |value|
9
+ opts.on('-p', '--port PORT', 'port number') do |value|
9
10
  port = value.to_i if 0 < value.to_i
10
11
  end
11
- opts.on('-b', '--bind=HOST', 'address to bind') do |value|
12
+ opts.on('-b', '--bind HOST', 'address to bind') do |value|
12
13
  host = value
13
14
  end
14
- opts.on('-d', '--dump', 'dump objects') do
15
- puts 'not implemented yet'
16
- exit
15
+ opts.on('-d', '--dump', 'dump objects') do |value|
16
+ dump = true
17
17
  end
18
18
  opts.on_tail("-h", "--help", "show this help.") do
19
19
  puts opts
@@ -25,9 +25,12 @@ module GitObjectBrowser
25
25
  end
26
26
  opts.parse!(ARGV)
27
27
  end
28
-
29
28
  target = find_target(ARGV[0])
30
- Server::Main.execute(target, host, port)
29
+ if dump
30
+ GitObjectBrowser::Dumper::Main.execute(target)
31
+ else
32
+ GitObjectBrowser::Server::Main.execute(target, host, port)
33
+ end
31
34
  end
32
35
 
33
36
  def find_target(target = nil, git_dir_name = '.git')
@@ -36,15 +36,13 @@ module GitObjectBrowser
36
36
  (@properties, @message) = parse_contents
37
37
  end
38
38
 
39
- @content = @content.force_encoding('UTF-8')
40
- @content = '(not UTF-8)' unless @content.valid_encoding?
39
+ @content = force_utf8(@content)
41
40
  @content = @content[0, 3000] + "\n..." if @content.length > 3000
42
41
  end
43
42
 
44
43
  self
45
44
  end
46
45
 
47
-
48
46
  def to_hash
49
47
  return {
50
48
  :type => @type,
@@ -71,7 +69,7 @@ module GitObjectBrowser
71
69
  entry = {}
72
70
  entry[:mode] = find_char ' '
73
71
  break if entry[:mode].empty?
74
- entry[:filename] = find_char "\0"
72
+ entry[:filename] = force_utf8(find_char("\0"))
75
73
  entry[:sha1] = hex(20)
76
74
  @content += "#{entry[:mode]} #{entry[:filename]}\\0\\#{entry[:sha1]}\n"
77
75
  entries << entry
@@ -96,20 +94,19 @@ module GitObjectBrowser
96
94
  # couldn't find the spec...
97
95
  prop[:value].to_s =~ /\A(.*) <(.*)> (\d+)(?: ((?:(?:\+|-)(?:\d{4}|\d{2}:\d{2}))|Z))?\z/
98
96
  prop[:type] = 'user'
99
- prop[:name] = $1.force_encoding("UTF-8")
100
- prop[:name] = '(not UTF-8)' unless prop[:name].valid_encoding?
101
- prop[:email] = $2.force_encoding("UTF-8")
102
- prop[:email] = '(not UTF-8)' unless prop[:email].valid_encoding?
97
+ prop[:name] = force_utf8($1)
98
+ prop[:email] = force_utf8($2)
103
99
  prop[:unixtime] = $3
104
100
  prop[:timezone] = $4
105
101
  prop[:date] = epoch($3.to_i, $4).iso8601
102
+
103
+ prop[:value] = force_utf8(prop[:value])
106
104
  else
107
105
  prop[:type] = 'text'
108
106
  end
109
107
  properties << prop
110
108
  end
111
- message = lines.join("\n").force_encoding("UTF-8")
112
- message = '(not UTF-8)' unless message.valid_encoding?
109
+ message = force_utf8(lines.join("\n"))
113
110
 
114
111
  [properties, message]
115
112
  end
@@ -124,6 +121,12 @@ module GitObjectBrowser
124
121
  Rational($2.to_i, 24) + Rational($3, 60) * (($1 == '-') ? -1 : 1)
125
122
  end
126
123
 
124
+ def force_utf8(str)
125
+ str = str.force_encoding('UTF-8')
126
+ str.valid_encoding? ? str : '(not UTF-8)'
127
+ end
128
+ private :force_utf8
129
+
127
130
  end
128
131
  end
129
132
  end
@@ -30,7 +30,7 @@ module GitObjectBrowser
30
30
  @gid = int # 36
31
31
  @size = int # 40
32
32
  @sha1 = hex(20) # 60
33
- parse_flags # 62
33
+ parse_flags # 62 (+2)
34
34
  parse_path
35
35
  end
36
36
 
@@ -48,8 +48,8 @@ module GitObjectBrowser
48
48
  @extended_flag = flags[1..1].to_i
49
49
  @stage = flags[2..3]
50
50
  @name_length = ["0000" + flags[4..15]].pack("B*").unpack("n")[0]
51
- if @version == 3 && @extended_flag == 1
52
- exended = binstr(2)
51
+ if @version > 2 && @extended_flag == 1
52
+ extended = binstr(2)
53
53
  reserved = extended[0..0]
54
54
  @skip_worktree = extended[1..1]
55
55
  @intent_to_add = extended[2..2]
@@ -68,7 +68,7 @@ module GitObjectBrowser
68
68
 
69
69
  # path: 2 + 8 * n bytes (nul pannding)
70
70
  def parse_path_v2
71
- token = raw(2) # 64 bytes
71
+ token = raw(@extended_flag == 1 ? 8 : 2)
72
72
  @path = ""
73
73
  begin
74
74
  @path += token.unpack("Z*").first
@@ -1,3 +1,3 @@
1
1
  module GitObjectBrowser
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -53,6 +53,20 @@ module GitObjectBrowser::Models
53
53
  expect = ['test.txt', 'test2.txt', 'test3.txt']
54
54
  entries.map {|entry| entry[:path]}.should eq expect
55
55
  end
56
+
57
+ it 'should parse extended data' do
58
+ index = subject.parse.to_hash
59
+
60
+ entry = index[:entries][1]
61
+ entry[:extended_flag].should eq 0
62
+ entry[:skip_worktree] = nil
63
+ entry[:intent_to_add] = nil
64
+
65
+ entry = index[:entries][2]
66
+ entry[:extended_flag].should eq 1
67
+ entry[:skip_worktree] = 0
68
+ entry[:intent_to_add] = 1
69
+ end
56
70
  end
57
71
  end
58
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-object-browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Browse git raw objects.
15
15
  email:
@@ -74,8 +74,11 @@ files:
74
74
  - htdocs/templates/packed_refs.html
75
75
  - htdocs/templates/ref.html
76
76
  - lib/git-object-browser.rb
77
- - lib/git-object-browser/dumper.rb
78
- - lib/git-object-browser/index_dumper.rb
77
+ - lib/git-object-browser/dumper/index_dumper.rb
78
+ - lib/git-object-browser/dumper/main.rb
79
+ - lib/git-object-browser/dumper/object_dumper.rb
80
+ - lib/git-object-browser/dumper/pack_index_dumper.rb
81
+ - lib/git-object-browser/dumper/packed_object_dumper.rb
79
82
  - lib/git-object-browser/main.rb
80
83
  - lib/git-object-browser/models/bindata.rb
81
84
  - lib/git-object-browser/models/directory.rb
@@ -91,7 +94,6 @@ files:
91
94
  - lib/git-object-browser/models/packed_refs.rb
92
95
  - lib/git-object-browser/models/plain_file.rb
93
96
  - lib/git-object-browser/models/ref.rb
94
- - lib/git-object-browser/object_dumper.rb
95
97
  - lib/git-object-browser/server/git_servlet.rb
96
98
  - lib/git-object-browser/server/main.rb
97
99
  - lib/git-object-browser/version.rb
@@ -185,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
187
  version: '0'
186
188
  segments:
187
189
  - 0
188
- hash: 2893578660749395643
190
+ hash: 144653815734182267
189
191
  requirements: []
190
192
  rubyforge_project:
191
193
  rubygems_version: 1.8.24
@@ -1,62 +0,0 @@
1
- module GitObjectBrowser
2
-
3
- class Dumper
4
-
5
- def initialize(target)
6
- @target = target
7
- @outdir = File.join(@target, "plain")
8
- end
9
-
10
- def dump
11
- Dir.mkdir(@outdir) unless File.exist?(@outdir)
12
- dump_index
13
- dump_objects
14
- end
15
-
16
- def dump_index
17
- index_file = File.join(@target, "index")
18
- out_file = File.join(@outdir, "index")
19
-
20
- return unless File.exist?(index_file)
21
-
22
- STDERR << "Write: .git/plain/index\n"
23
- File.open(index_file) do |input|
24
- File.open(out_file, "w") do |output|
25
- dumper = GitObjectBrowser::IndexDumper.new(input, output)
26
- dumper.dump
27
- end
28
- end
29
- end
30
-
31
- def dump_objects
32
- obj_files = []
33
- Dir.chdir(@target) do
34
- Dir.glob("objects/**/*") do |path|
35
- obj_files << path if File.file?(path) && path =~ %r{/[a-z0-9]{38}$}
36
- end
37
- end
38
- return if obj_files.empty?
39
-
40
- obj_dir = File.join(@outdir, "objects")
41
- Dir.mkdir(obj_dir) unless File.exist?(obj_dir)
42
-
43
- obj_files.each do |path|
44
- outfile = File.join(@outdir, path)
45
- next if File.exist?(outfile)
46
-
47
- parent = File.dirname(outfile)
48
- Dir.mkdir(parent) unless File.exist?(parent)
49
-
50
- STDERR << "Write: .git/plain/#{path}\n"
51
- obj_file = File.join(@target, path)
52
- File.open(obj_file) do |input|
53
- File.open(outfile, "w") do |output|
54
- dumper = GitObjectBrowser::ObjectDumper.new(input, output)
55
- dumper.dump
56
- end
57
- end
58
- end
59
-
60
- end
61
- end
62
- end
@@ -1,77 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module GitObjectBrowser
4
-
5
- class IndexDumper
6
-
7
- def initialize(input, output)
8
- @index = Models::Index.new(input)
9
- @out = output
10
- end
11
-
12
- def dump
13
- @out << "----------------------------------------------------------------\n"
14
- @out << "header\n"
15
- @out << "----------------------------------------------------------------\n"
16
- @out << "version: #{@index.version}\n"
17
- @out << "entries: #{@index.entry_count}\n"
18
- @out << "\n"
19
-
20
- @index.entries.each_with_index do |entry, i|
21
- @out << "----------------------------------------------------------------\n"
22
- @out << "entry: #{i+1}\n"
23
- @out << "----------------------------------------------------------------\n"
24
- @out << " ctime: #{entry.ctime}\n"
25
- @out << " ctime nano: #{entry.cnano}\n"
26
- @out << " mtime: #{entry.mtime}\n"
27
- @out << " mtime nano: #{entry.mnano}\n"
28
- @out << " dev: #{entry.dev}\n"
29
- @out << " ino: #{entry.ino}\n"
30
- @out << " object_type: #{entry.object_type}\n"
31
- @out << " unix_permission: #{entry.unix_permission}\n"
32
- @out << " uid: #{entry.uid}\n"
33
- @out << " gid: #{entry.gid}\n"
34
- @out << " size: #{entry.size}\n"
35
- @out << " sha1: #{entry.sha1}\n"
36
- if @version == 2
37
- @out << "assume_valid_flag: #{entry.assume_valid_flag}\n"
38
- @out << " extended_flag: #{entry.extended_flag}\n"
39
- @out << " stage: #{entry.stage}\n"
40
- elsif @version == 3
41
- @out << " skip_worktree: #{entry.skip_worktree}\n"
42
- @out << " intent_to_add: #{entry.intent_to_add}\n"
43
- end
44
- @out << " name_length: #{entry.name_length}\n"
45
- @out << " path: #{entry.path}\n"
46
- @out << "\n"
47
- end
48
-
49
- @index.extensions.each do |extension|
50
- @out << "----------------------------------------------------------------\n"
51
- @out << "extension: #{extension.signature}\n"
52
- @out << "----------------------------------------------------------------\n"
53
- if extension.signature == "TREE"
54
- dump_tree_extension(extension)
55
- elsif extension.signature == "REUC"
56
- dump_reuc_extension
57
- end
58
- end
59
-
60
- @out << "----------------------------------------------------------------\n"
61
- @out << "checksum\n"
62
- @out << "----------------------------------------------------------------\n"
63
- @out << "sha1: #{@index.sha1}\n"
64
- end
65
-
66
- def dump_tree_extension(tree_extension)
67
- tree_extension.entries.each do |entry|
68
- @out << " path_component: #{entry[:path_component]}\n"
69
- @out << " entry_count: #{entry[:entry_count]}\n"
70
- @out << " subtree_count: #{entry[:subtree_count]}\n"
71
- @out << " sha1: #{entry[:sha1]}\n\n"
72
- end
73
- end
74
-
75
- end
76
-
77
- end
@@ -1,31 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module GitObjectBrowser
4
-
5
- class ObjectDumper
6
-
7
- def initialize(input, output)
8
- @object = Models::GitObject.new(input)
9
- @out = output
10
- end
11
-
12
- def dump
13
- @out << "type: #{@object.type}\n"
14
- @out << "size: #{@object.size}\n"
15
- @out << "sha1: #{@object.sha1}\n"
16
- @out << "\n"
17
- if @object.type == "tree"
18
- dump_tree_entries
19
- else
20
- @out << @object.contents
21
- end
22
- end
23
-
24
- # man git-ls-tree
25
- def dump_tree_entries
26
- @object.entries.each do |entry|
27
- @out << "#{entry[:mode]} #{entry[:sha1]} #{entry[:filename]}\n"
28
- end
29
- end
30
- end
31
- end