ddollar-git-db 0.0.2 → 0.1.2
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.rdoc +30 -9
- data/Rakefile +9 -23
- data/VERSION +1 -1
- data/bin/git-db +3 -2
- data/git-db.gemspec +35 -24
- data/lib/git-db.rb +56 -4
- data/lib/git-db/commands.rb +21 -0
- data/lib/git-db/commands/receive-pack.rb +73 -0
- data/lib/git-db/commands/upload-pack.rb +140 -0
- data/lib/git-db/database.rb +134 -0
- data/lib/git-db/objects.rb +20 -0
- data/lib/{git → git-db}/objects/base.rb +14 -9
- data/lib/git-db/objects/blob.rb +11 -0
- data/lib/{git → git-db}/objects/commit.rb +5 -5
- data/lib/{git → git-db}/objects/entry.rb +12 -4
- data/lib/git-db/objects/tag.rb +7 -0
- data/lib/{git → git-db}/objects/tree.rb +16 -16
- data/lib/{git → git-db}/pack.rb +6 -6
- data/lib/{git → git-db}/protocol.rb +3 -3
- data/lib/git-db/utility.rb +3 -0
- data/lib/{utility → git-db/utility}/counting_io.rb +0 -0
- data/spec/git-db/commands_spec.rb +23 -0
- data/spec/git-db/objects/base_spec.rb +27 -0
- data/spec/git-db/objects/entry_spec.rb +25 -0
- data/spec/git-db/objects/tag_spec.rb +14 -0
- data/spec/git-db/objects/tree_spec.rb +42 -0
- data/spec/git-db/utility/counting_io_spec.rb +30 -0
- data/spec/git-db_spec.rb +41 -3
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +2 -0
- metadata +33 -29
- data/lib/git.rb +0 -39
- data/lib/git/commands.rb +0 -17
- data/lib/git/commands/receive-pack.rb +0 -101
- data/lib/git/commands/upload-pack.rb +0 -204
- data/lib/git/objects.rb +0 -20
- data/lib/git/objects/blob.rb +0 -11
- data/lib/git/objects/tag.rb +0 -7
- data/lib/utility.rb +0 -3
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "GitDB::Objects::Entry" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@sha = "1111111111111111111111111111111111111111"
|
7
|
+
@perms = 100644
|
8
|
+
@name = "test name"
|
9
|
+
@entry = GitDB::Objects::Entry.new(@sha, @perms, @name)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has properties" do
|
13
|
+
@entry.properties.should == [:permissions, :name]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "converts to a hash" do
|
17
|
+
@entry.to_hash[:sha].should == @sha
|
18
|
+
@entry.to_hash[:permissions].should == @perms
|
19
|
+
@entry.to_hash[:name].should == @name
|
20
|
+
end
|
21
|
+
|
22
|
+
it "converts to json" do
|
23
|
+
@entry.to_json.should == @entry.to_hash.to_json
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "GitDB::Objects::Tag" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
# TODO: real tag data
|
7
|
+
@data = "test-tag"
|
8
|
+
@tag = GitDB::Objects::Tag.new(@data)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a type" do
|
12
|
+
@tag.type.should == GitDB::OBJ_TAG
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "GitDB::Objects::Tree" do
|
4
|
+
|
5
|
+
class TreeEntry
|
6
|
+
attr_reader :perms, :name, :sha
|
7
|
+
|
8
|
+
def initialize(perms, name, sha)
|
9
|
+
@perms = perms
|
10
|
+
@name = name
|
11
|
+
@sha = sha
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_entry
|
15
|
+
"#{perms} #{name}\000#{GitDB.hex_to_sha1(sha)}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@entry1 = TreeEntry.new(100644, "entry1", "1111111111111111111111111111111111111111")
|
21
|
+
@entry2 = TreeEntry.new(100444, "entry2", "2222222222222222222222222222222222222222")
|
22
|
+
@data = [ @entry1.to_entry, @entry2.to_entry ].join('')
|
23
|
+
@tree = GitDB::Objects::Tree.new(@data)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has entries" do
|
27
|
+
@tree.entries.first.name.should == @entry1.name
|
28
|
+
@tree.entries.last.name.should == @entry2.name
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has properties" do
|
32
|
+
@tree.properties.should == [:entries]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a raw value" do
|
36
|
+
@tree.raw.should == "tree #{@data.length}\000#{@data}"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a type" do
|
40
|
+
@tree.type.should == GitDB::OBJ_TREE
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "GitDB::Utility::CountingIO" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@base = StringIO.new
|
7
|
+
@io = GitDB::Utility::CountingIO.new(@base)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can flush" do
|
11
|
+
@base.should_receive(:flush)
|
12
|
+
@io.flush
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can read" do
|
16
|
+
@data = "00000"
|
17
|
+
@bytes = @data.length
|
18
|
+
|
19
|
+
@base.should_receive(:read).with(@bytes).and_return(@data)
|
20
|
+
@io.read(@bytes).should == @data
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can write" do
|
24
|
+
@data = "00000"
|
25
|
+
|
26
|
+
@base.should_receive(:write).with(@data)
|
27
|
+
@io.write(@data)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/git-db_spec.rb
CHANGED
@@ -1,7 +1,45 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
3
|
+
describe "GitDB" do
|
4
|
+
|
5
|
+
describe "git utility" do
|
6
|
+
it "can convert shas to/from hex/binary representation" do
|
7
|
+
@hex = "6161616161616161616161616161616161616161"
|
8
|
+
@sha = "aaaaaaaaaaaaaaaaaaaa"
|
9
|
+
|
10
|
+
GitDB.hex_to_sha1(@hex.dup).should == @sha.dup
|
11
|
+
GitDB.sha1_to_hex(@sha.dup).should == @hex.dup
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a null sha" do
|
15
|
+
GitDB.null_sha1.should == "0000000000000000000000000000000000000000"
|
16
|
+
end
|
6
17
|
end
|
18
|
+
|
19
|
+
describe "logging" do
|
20
|
+
it "has a logger that can respond to puts" do
|
21
|
+
GitDB.logger.should respond_to(:puts)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "logs messages sent to log" do
|
25
|
+
@logger = mock(Logger)
|
26
|
+
@message = "Log This"
|
27
|
+
|
28
|
+
GitDB.should_receive(:logger).and_return(@logger)
|
29
|
+
@logger.should_receive(:puts).with(@message)
|
30
|
+
|
31
|
+
GitDB.log(@message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "database" do
|
36
|
+
it "returns a database for a repository" do
|
37
|
+
@repository = "Test Repository"
|
38
|
+
|
39
|
+
GitDB::Database.should_receive(:database).with(@repository)
|
40
|
+
|
41
|
+
GitDB.database(@repository)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
7
45
|
end
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddollar-git-db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Dollar
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-14 00:00:00 -07:00
|
13
13
|
default_executable: git-db
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,18 +23,8 @@ dependencies:
|
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
type: :
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: cucumber
|
37
|
-
type: :development
|
26
|
+
name: couchrest
|
27
|
+
type: :runtime
|
38
28
|
version_requirement:
|
39
29
|
version_requirements: !ruby/object:Gem::Requirement
|
40
30
|
requirements:
|
@@ -64,22 +54,30 @@ files:
|
|
64
54
|
- features/support/env.rb
|
65
55
|
- git-db.gemspec
|
66
56
|
- lib/git-db.rb
|
67
|
-
- lib/git.rb
|
68
|
-
- lib/git/commands.rb
|
69
|
-
- lib/git/commands/
|
70
|
-
- lib/git/
|
71
|
-
- lib/git/objects.rb
|
72
|
-
- lib/git/objects/base.rb
|
73
|
-
- lib/git/objects/blob.rb
|
74
|
-
- lib/git/objects/commit.rb
|
75
|
-
- lib/git/objects/entry.rb
|
76
|
-
- lib/git/objects/tag.rb
|
77
|
-
- lib/git/objects/tree.rb
|
78
|
-
- lib/git/pack.rb
|
79
|
-
- lib/git/protocol.rb
|
80
|
-
- lib/utility.rb
|
81
|
-
- lib/utility/counting_io.rb
|
57
|
+
- lib/git-db/commands.rb
|
58
|
+
- lib/git-db/commands/receive-pack.rb
|
59
|
+
- lib/git-db/commands/upload-pack.rb
|
60
|
+
- lib/git-db/database.rb
|
61
|
+
- lib/git-db/objects.rb
|
62
|
+
- lib/git-db/objects/base.rb
|
63
|
+
- lib/git-db/objects/blob.rb
|
64
|
+
- lib/git-db/objects/commit.rb
|
65
|
+
- lib/git-db/objects/entry.rb
|
66
|
+
- lib/git-db/objects/tag.rb
|
67
|
+
- lib/git-db/objects/tree.rb
|
68
|
+
- lib/git-db/pack.rb
|
69
|
+
- lib/git-db/protocol.rb
|
70
|
+
- lib/git-db/utility.rb
|
71
|
+
- lib/git-db/utility/counting_io.rb
|
72
|
+
- spec/git-db/commands_spec.rb
|
73
|
+
- spec/git-db/objects/base_spec.rb
|
74
|
+
- spec/git-db/objects/entry_spec.rb
|
75
|
+
- spec/git-db/objects/tag_spec.rb
|
76
|
+
- spec/git-db/objects/tree_spec.rb
|
77
|
+
- spec/git-db/utility/counting_io_spec.rb
|
82
78
|
- spec/git-db_spec.rb
|
79
|
+
- spec/rcov.opts
|
80
|
+
- spec/spec.opts
|
83
81
|
- spec/spec_helper.rb
|
84
82
|
has_rdoc: false
|
85
83
|
homepage: http://github.com/ddollar/git-db
|
@@ -109,5 +107,11 @@ signing_key:
|
|
109
107
|
specification_version: 3
|
110
108
|
summary: Database-based git server
|
111
109
|
test_files:
|
110
|
+
- spec/git-db/commands_spec.rb
|
111
|
+
- spec/git-db/objects/base_spec.rb
|
112
|
+
- spec/git-db/objects/entry_spec.rb
|
113
|
+
- spec/git-db/objects/tag_spec.rb
|
114
|
+
- spec/git-db/objects/tree_spec.rb
|
115
|
+
- spec/git-db/utility/counting_io_spec.rb
|
112
116
|
- spec/git-db_spec.rb
|
113
117
|
- spec/spec_helper.rb
|
data/lib/git.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module GitDB::Git;
|
2
|
-
|
3
|
-
# git constants
|
4
|
-
OBJ_NONE = 0
|
5
|
-
OBJ_COMMIT = 1
|
6
|
-
OBJ_TREE = 2
|
7
|
-
OBJ_BLOB = 3
|
8
|
-
OBJ_TAG = 4
|
9
|
-
OBJ_OFS_DELTA = 6
|
10
|
-
OBJ_REF_DELTA = 7
|
11
|
-
|
12
|
-
def self.sha1_to_hex(sha)
|
13
|
-
hex = ""
|
14
|
-
sha.split('').each do |char|
|
15
|
-
val = char[0]
|
16
|
-
hex << (val >> 4).to_s(16)
|
17
|
-
hex << (val & 0xf).to_s(16)
|
18
|
-
end
|
19
|
-
hex
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.hex_to_sha1(hex)
|
23
|
-
sha = ""
|
24
|
-
len = 0
|
25
|
-
until (len == hex.length)
|
26
|
-
val = (hex[len, 1].to_i(16) << 4)
|
27
|
-
val += hex[len+1, 1].to_i(16)
|
28
|
-
sha << val.chr
|
29
|
-
len += 2
|
30
|
-
end
|
31
|
-
sha
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
require 'git/commands'
|
37
|
-
require 'git/objects'
|
38
|
-
require 'git/pack'
|
39
|
-
require 'git/protocol'
|
data/lib/git/commands.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module GitDB::Git::Commands
|
2
|
-
|
3
|
-
def self.execute(command, args=[])
|
4
|
-
return unless @commands
|
5
|
-
raise ArgumentError, "Unknown command: #{command}" unless @commands[command]
|
6
|
-
@commands[command].execute(args)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.register(command, klass)
|
10
|
-
@commands ||= {}
|
11
|
-
@commands[command] = klass.new
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'git/commands/receive-pack'
|
17
|
-
require 'git/commands/upload-pack'
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'zlib'
|
3
|
-
|
4
|
-
class GitDB::Git::Commands::ReceivePack
|
5
|
-
|
6
|
-
def execute(args)
|
7
|
-
repository = args.first
|
8
|
-
raise ArgumentError, "repository required" unless repository
|
9
|
-
|
10
|
-
needs_capabilities = true
|
11
|
-
each_git_ref do |ref, sha|
|
12
|
-
write_ref(ref, sha, needs_capabilities)
|
13
|
-
needs_capabilities = false
|
14
|
-
end
|
15
|
-
write_ref("capabilities^{}", null_sha1) if needs_capabilities
|
16
|
-
io.write_eof
|
17
|
-
|
18
|
-
refs = []
|
19
|
-
new_shas = []
|
20
|
-
|
21
|
-
while (data = io.read_command)
|
22
|
-
old_sha, new_sha, ref = data.split(' ')
|
23
|
-
ref, report = ref.split(0.chr)
|
24
|
-
refs << ref
|
25
|
-
new_shas << new_sha
|
26
|
-
if new_sha == null_sha1
|
27
|
-
delete_git_file(ref)
|
28
|
-
else
|
29
|
-
write_git_file(ref, new_sha)
|
30
|
-
end
|
31
|
-
# GitDB.log("OLDSHA: #{old_sha}")
|
32
|
-
# GitDB.log("NEWSHA: #{new_sha}")
|
33
|
-
# GitDB.log("REF: #{ref}")
|
34
|
-
# GitDB.log("REPORT: #{report}")
|
35
|
-
end
|
36
|
-
|
37
|
-
unless new_shas.reject { |sha| sha == null_sha1 }.length.zero?
|
38
|
-
while (entries = io.read_pack)
|
39
|
-
GitDB.log("ENTRIES: #{entries.inspect}")
|
40
|
-
entries.each do |entry|
|
41
|
-
filename = "objects/#{entry.sha[0..1]}/#{entry.sha[2..-1]}"
|
42
|
-
write_git_file(filename, Zlib::Deflate.deflate(entry.raw))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
io.write_command("unpack ok\n")
|
48
|
-
refs.each do |ref|
|
49
|
-
io.write_command("ok #{ref}\n")
|
50
|
-
end
|
51
|
-
io.write_eof
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def capabilities
|
57
|
-
" report-status delete-refs ofs-delta "
|
58
|
-
end
|
59
|
-
|
60
|
-
def io
|
61
|
-
@io ||= GitDB::Git::Protocol.new
|
62
|
-
end
|
63
|
-
|
64
|
-
def null_sha1
|
65
|
-
"0000000000000000000000000000000000000000"
|
66
|
-
end
|
67
|
-
|
68
|
-
def each_git_ref(&block)
|
69
|
-
Dir["/tmp/foo/.git/refs/*/*"].each do |ref|
|
70
|
-
sha = File.read(ref).strip
|
71
|
-
ref = ref.gsub('/tmp/foo/.git/', '')
|
72
|
-
yield ref, sha
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def delete_git_file(filename)
|
77
|
-
filename = "/tmp/foo/.git/#{filename}"
|
78
|
-
GitDB.log("REMOVING: #{filename}")
|
79
|
-
FileUtils.rm_rf(filename)
|
80
|
-
end
|
81
|
-
|
82
|
-
def write_git_file(filename, data)
|
83
|
-
filename = "/tmp/foo/.git/#{filename}"
|
84
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
85
|
-
File.open(filename, 'w') do |file|
|
86
|
-
file.print(data)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def write_ref(ref, sha, needs_capabilities=true)
|
91
|
-
if needs_capabilities
|
92
|
-
header = "%s %s\000%s\n" % [ sha, ref, capabilities ]
|
93
|
-
io.write_command(header)
|
94
|
-
else
|
95
|
-
header = "%s %s\n" % [ sha, ref ]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
GitDB::Git::Commands.register 'receive-pack', GitDB::Git::Commands::ReceivePack
|
@@ -1,204 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'zlib'
|
3
|
-
|
4
|
-
class GitDB::Git::Commands::UploadPack
|
5
|
-
|
6
|
-
def execute(args)
|
7
|
-
repository = args.first
|
8
|
-
raise ArgumentError, "repository required" unless repository
|
9
|
-
|
10
|
-
#execute_transcript
|
11
|
-
execute_real
|
12
|
-
end
|
13
|
-
|
14
|
-
def execute_transcript
|
15
|
-
cmd = GitDB::Git::Protocol.new(IO.popen("/opt/local/bin/git-upload-pack '/tmp/foo'", 'r+'))
|
16
|
-
|
17
|
-
while (data = cmd.read_command)
|
18
|
-
GitDB.log("CMD COMMAND: #{data}")
|
19
|
-
io.write_command(data)
|
20
|
-
end
|
21
|
-
io.write_eof
|
22
|
-
|
23
|
-
while (data = io.read_command)
|
24
|
-
GitDB.log("IO COMMAND: #{data}")
|
25
|
-
cmd.write_command(data)
|
26
|
-
end
|
27
|
-
cmd.write_eof
|
28
|
-
|
29
|
-
while (data = io.read_command)
|
30
|
-
cmd.write_command(data)
|
31
|
-
data = data.strip
|
32
|
-
break if data == 'done'
|
33
|
-
GitDB.log("READ FROM IO #{data}")
|
34
|
-
end
|
35
|
-
|
36
|
-
while (data = cmd.read_command)
|
37
|
-
GitDB.log("GOT COMMAND DATA: #{data.inspect}")
|
38
|
-
end
|
39
|
-
|
40
|
-
# data = io.reader.read(9)
|
41
|
-
# GitDB.log("READ FROM IO: #{data.inspect}")
|
42
|
-
# cmd.writer.write(data)
|
43
|
-
|
44
|
-
# while (data = cmd.read_command)
|
45
|
-
# GitDB.log("CMD COMMAND: #{data.inspect}")
|
46
|
-
# io.write_command(data)
|
47
|
-
# GitDB.log('weee')
|
48
|
-
# if data[0] == 1
|
49
|
-
# GitDB.log("ITS A PACK!")
|
50
|
-
# pack = data[1..-1]
|
51
|
-
# unpacker = GitDB::Git::Pack.new(StringIO.new(pack))
|
52
|
-
# unpacker.read
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
# io.write_eof
|
56
|
-
|
57
|
-
# while (data = cmd.read_command)
|
58
|
-
# GitDB.log("CMD COMMAND: #{data}")
|
59
|
-
# io.write_command(data)
|
60
|
-
# end
|
61
|
-
# io.write_eof
|
62
|
-
end
|
63
|
-
|
64
|
-
def execute_real
|
65
|
-
head_ref do |ref, sha|
|
66
|
-
write_ref(ref, sha)
|
67
|
-
end
|
68
|
-
each_git_ref do |ref, sha|
|
69
|
-
write_ref(ref, sha)
|
70
|
-
#write_ref(ref, sha.gsub('9', '1'))
|
71
|
-
end
|
72
|
-
io.write_eof
|
73
|
-
|
74
|
-
shas_to_read = []
|
75
|
-
shas_to_ignore = []
|
76
|
-
|
77
|
-
while (data = io.read_command)
|
78
|
-
GitDB.log("GOT COMMAND: #{data.inspect}")
|
79
|
-
command, sha, options = data.split(' ', 3)
|
80
|
-
shas_to_read << sha
|
81
|
-
end
|
82
|
-
|
83
|
-
while (data = io.read_command)
|
84
|
-
data = data.strip
|
85
|
-
break if data == 'done'
|
86
|
-
command, sha = data.split(" ", 2)
|
87
|
-
case command
|
88
|
-
when 'have' then
|
89
|
-
shas_to_ignore << sha
|
90
|
-
else
|
91
|
-
raise "Unknown SHA command: #{command}"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
if shas_to_ignore.length.zero?
|
96
|
-
io.write_command("NAK\n")
|
97
|
-
else
|
98
|
-
io.write_command("ACK #{shas_to_ignore.last}\n")
|
99
|
-
end
|
100
|
-
|
101
|
-
shas_to_ignore, _ = load_entries(shas_to_ignore, false)
|
102
|
-
# GitDB.log("SHAS_TO_READ: #{shas_to_read.inspect}")
|
103
|
-
# GitDB.log("SHAS_READ: #{shas_read.inspect}")
|
104
|
-
|
105
|
-
shas, entries = load_entries(shas_to_read, true, shas_to_ignore)
|
106
|
-
|
107
|
-
GitDB.log(entries.map { |e| e.inspect })
|
108
|
-
|
109
|
-
io.write_pack(entries)
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def load_entries(shas_to_read, keep_entries, shas_to_ignore=[])
|
115
|
-
entries = []
|
116
|
-
shas = []
|
117
|
-
|
118
|
-
while sha = shas_to_read.shift
|
119
|
-
next if shas_to_ignore.include?(sha)
|
120
|
-
shas_to_ignore << sha
|
121
|
-
|
122
|
-
shas << sha
|
123
|
-
|
124
|
-
raw_data = read_git_object(sha)
|
125
|
-
type = raw_data.split(" ").first
|
126
|
-
data = raw_data.split("\000", 2).last
|
127
|
-
|
128
|
-
#GitDB.log("SHADATA: #{data.inspect}")
|
129
|
-
case type
|
130
|
-
when 'commit' then
|
131
|
-
commit = GitDB::Git::Objects::Commit.new(data)
|
132
|
-
shas_to_read << commit.tree
|
133
|
-
shas_to_read += commit.parents if commit.parents
|
134
|
-
entries << commit if keep_entries
|
135
|
-
when 'tree' then
|
136
|
-
tree = GitDB::Git::Objects::Tree.new(data)
|
137
|
-
shas_to_read += tree.entries.map { |e| e.sha }
|
138
|
-
entries << tree if keep_entries
|
139
|
-
when 'blob' then
|
140
|
-
blob = GitDB::Git::Objects::Blob.new(data)
|
141
|
-
entries << blob if keep_entries
|
142
|
-
else
|
143
|
-
raise "UNKNOWN TYPE!! #{type}"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
[shas, entries]
|
148
|
-
end
|
149
|
-
|
150
|
-
def capabilities
|
151
|
-
" shallow include-tag"
|
152
|
-
end
|
153
|
-
|
154
|
-
def io
|
155
|
-
@io ||= GitDB::Git::Protocol.new
|
156
|
-
end
|
157
|
-
|
158
|
-
def null_sha1
|
159
|
-
"0000000000000000000000000000000000000000"
|
160
|
-
end
|
161
|
-
|
162
|
-
def each_git_ref(&block)
|
163
|
-
Dir["/tmp/foo/.git/refs/*/*"].each do |ref|
|
164
|
-
sha = File.read(ref).strip
|
165
|
-
ref = ref.gsub('/tmp/foo/.git/', '')
|
166
|
-
yield ref, sha
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def head_ref(&block)
|
171
|
-
sha = File.read("/tmp/foo/.git/HEAD").strip
|
172
|
-
if sha =~ /ref: (.+)/
|
173
|
-
sha = File.read("/tmp/foo/.git/#{$1}")
|
174
|
-
end
|
175
|
-
yield "HEAD", sha
|
176
|
-
end
|
177
|
-
|
178
|
-
def delete_git_file(filename)
|
179
|
-
filename = "/tmp/foo/.git/#{filename}"
|
180
|
-
GitDB.log("REMOVING: #{filename}")
|
181
|
-
FileUtils.rm_rf(filename)
|
182
|
-
end
|
183
|
-
|
184
|
-
def read_git_object(sha)
|
185
|
-
filename = "/tmp/foo/.git/objects/#{sha[0..1]}/#{sha[2..-1]}"
|
186
|
-
data = Zlib::Inflate.inflate(File.read(filename))
|
187
|
-
end
|
188
|
-
|
189
|
-
def write_git_file(filename, data)
|
190
|
-
filename = "/tmp/foo/.git/#{filename}"
|
191
|
-
FileUtils.mkdir_p(File.dirname(filename))
|
192
|
-
File.open(filename, 'w') do |file|
|
193
|
-
file.print(data)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def write_ref(ref, sha, needs_capabilities=true)
|
198
|
-
header = "%s %s\000%s\n" % [ sha, ref, capabilities ]
|
199
|
-
io.write_command(header)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
GitDB::Git::Commands.register 'upload-pack', GitDB::Git::Commands::UploadPack
|