gitrb 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/gitrb.gemspec +3 -2
- data/lib/gitrb/blob.rb +4 -4
- data/lib/gitrb/commit.rb +7 -7
- data/lib/gitrb/diff.rb +1 -19
- data/lib/gitrb/gitobject.rb +26 -0
- data/lib/gitrb/pack.rb +0 -2
- data/lib/gitrb/{object.rb → reference.rb} +1 -30
- data/lib/gitrb/repository.rb +84 -69
- data/lib/gitrb/tag.rb +2 -2
- data/lib/gitrb/tree.rb +9 -9
- data/lib/gitrb/user.rb +4 -5
- data/lib/gitrb.rb +17 -0
- metadata +4 -3
data/gitrb.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'gitrb'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.9'
|
4
4
|
s.summary = 'Pure ruby git implementation'
|
5
5
|
s.author = 'Daniel Mendler'
|
6
6
|
s.email = 'mail@daniel-mendler.de'
|
@@ -21,8 +21,9 @@ lib/gitrb.rb
|
|
21
21
|
lib/gitrb/blob.rb
|
22
22
|
lib/gitrb/commit.rb
|
23
23
|
lib/gitrb/diff.rb
|
24
|
-
lib/gitrb/
|
24
|
+
lib/gitrb/gitobject.rb
|
25
25
|
lib/gitrb/pack.rb
|
26
|
+
lib/gitrb/reference.rb
|
26
27
|
lib/gitrb/repository.rb
|
27
28
|
lib/gitrb/tag.rb
|
28
29
|
lib/gitrb/tree.rb
|
data/lib/gitrb/blob.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Gitrb
|
2
2
|
|
3
3
|
# This class stores the raw string data of a blob
|
4
|
-
class Blob <
|
4
|
+
class Blob < GitObject
|
5
5
|
|
6
6
|
attr_accessor :data, :mode
|
7
7
|
|
@@ -9,15 +9,15 @@ module Gitrb
|
|
9
9
|
def initialize(options = {})
|
10
10
|
super(options)
|
11
11
|
@data = options[:data]
|
12
|
-
@mode = options[:mode] ||
|
12
|
+
@mode = options[:mode] || '100644'
|
13
13
|
end
|
14
14
|
|
15
15
|
def type
|
16
|
-
|
16
|
+
:blob
|
17
17
|
end
|
18
18
|
|
19
19
|
def ==(other)
|
20
|
-
Blob === other
|
20
|
+
Blob === other && id == other.id
|
21
21
|
end
|
22
22
|
|
23
23
|
def dump
|
data/lib/gitrb/commit.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Gitrb
|
2
2
|
|
3
|
-
class Commit <
|
4
|
-
attr_accessor :tree, :
|
3
|
+
class Commit < GitObject
|
4
|
+
attr_accessor :tree, :parents, :author, :committer, :message
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
super(options)
|
8
|
-
@
|
8
|
+
@parents = [options[:parents]].flatten.compact
|
9
9
|
@tree = options[:tree]
|
10
10
|
@author = options[:author]
|
11
11
|
@committer = options[:committer]
|
@@ -14,7 +14,7 @@ module Gitrb
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def type
|
17
|
-
|
17
|
+
:commit
|
18
18
|
end
|
19
19
|
|
20
20
|
def date
|
@@ -22,7 +22,7 @@ module Gitrb
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def ==(other)
|
25
|
-
Commit === other
|
25
|
+
Commit === other && id == other.id
|
26
26
|
end
|
27
27
|
|
28
28
|
def save
|
@@ -32,7 +32,7 @@ module Gitrb
|
|
32
32
|
|
33
33
|
def dump
|
34
34
|
[ "tree #{tree.id}",
|
35
|
-
@
|
35
|
+
@parents.map { |p| "parent #{p.id}" },
|
36
36
|
"author #{author.dump}",
|
37
37
|
"committer #{committer.dump}",
|
38
38
|
'',
|
@@ -54,7 +54,7 @@ module Gitrb
|
|
54
54
|
|
55
55
|
case key
|
56
56
|
when 'parent'
|
57
|
-
@
|
57
|
+
@parents << Reference.new(:repository => repository, :id => repository.set_encoding(value))
|
58
58
|
when 'author'
|
59
59
|
@author = User.parse(repository.set_encoding(value))
|
60
60
|
when 'committer'
|
data/lib/gitrb/diff.rb
CHANGED
@@ -1,21 +1,3 @@
|
|
1
1
|
module Gitrb
|
2
|
-
|
3
|
-
class Diff
|
4
|
-
attr_reader :from, :to, :patch, :deletions, :insertions
|
5
|
-
|
6
|
-
def initialize(from, to, patch)
|
7
|
-
@from = from
|
8
|
-
@to = to
|
9
|
-
@patch = patch
|
10
|
-
@deletions = @insertions = 0
|
11
|
-
@patch.split("\n").each do |line|
|
12
|
-
if line[0..0] == '-'
|
13
|
-
@deletions += 1
|
14
|
-
elsif line[0..0] == '+'
|
15
|
-
@insertions += 1
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
2
|
+
Diff = Struct.new(:from, :to, :patch)
|
21
3
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Gitrb
|
2
|
+
class GitObject
|
3
|
+
attr_accessor :repository, :id
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@repository = options[:repository]
|
7
|
+
@id = options[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def object
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
@types = {}
|
15
|
+
|
16
|
+
def self.inherited(subclass)
|
17
|
+
@types[subclass.name[7..-1].downcase] = subclass
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.factory(type, *args)
|
21
|
+
klass = @types[type]
|
22
|
+
raise NotImplementedError, "Object type not supported: #{type}" if !klass
|
23
|
+
klass.new(*args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/gitrb/pack.rb
CHANGED
@@ -1,36 +1,7 @@
|
|
1
1
|
module Gitrb
|
2
|
-
class Object
|
3
|
-
attr_accessor :repository, :id
|
4
|
-
alias sha id
|
5
|
-
|
6
|
-
def initialize(options = {})
|
7
|
-
@repository = options[:repository]
|
8
|
-
@id = options[:id] || options[:sha]
|
9
|
-
end
|
10
|
-
|
11
|
-
CLASS = {}
|
12
|
-
|
13
|
-
def object
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.inherited(subclass)
|
18
|
-
CLASS[subclass.name[7..-1].downcase] = subclass
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.factory(type, *args)
|
22
|
-
klass = CLASS[type] or raise NotImplementedError, "Object type not supported: #{type}"
|
23
|
-
klass.new(*args)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
2
|
class Reference
|
28
3
|
undef_method :id, :type rescue nil
|
29
4
|
|
30
|
-
def sha
|
31
|
-
id
|
32
|
-
end
|
33
|
-
|
34
5
|
def initialize(properties = {})
|
35
6
|
@properties = properties
|
36
7
|
@object = nil
|
@@ -42,7 +13,7 @@ module Gitrb
|
|
42
13
|
@object.send(name, *args, &block)
|
43
14
|
elsif name == :type && (mode = @properties['mode'] || @properties[:mode])
|
44
15
|
mode = mode.to_i(8)
|
45
|
-
return (mode & 0x4000 == 0x4000) ?
|
16
|
+
return (mode & 0x4000 == 0x4000) ? :tree : :blob
|
46
17
|
elsif @properties.include?(name)
|
47
18
|
return @properties[name]
|
48
19
|
elsif @properties.include?(name.to_s)
|
data/lib/gitrb/repository.rb
CHANGED
@@ -1,33 +1,25 @@
|
|
1
|
-
require 'zlib'
|
2
|
-
require 'digest/sha1'
|
3
|
-
require 'yaml'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'logger'
|
6
|
-
require 'enumerator'
|
7
|
-
|
8
|
-
require 'gitrb/util'
|
9
|
-
require 'gitrb/repository'
|
10
|
-
require 'gitrb/object'
|
11
|
-
require 'gitrb/blob'
|
12
|
-
require 'gitrb/diff'
|
13
|
-
require 'gitrb/tree'
|
14
|
-
require 'gitrb/tag'
|
15
|
-
require 'gitrb/user'
|
16
|
-
require 'gitrb/pack'
|
17
|
-
require 'gitrb/commit'
|
18
|
-
require 'gitrb/trie'
|
19
|
-
|
20
1
|
module Gitrb
|
21
2
|
class NotFound < StandardError; end
|
22
3
|
|
23
|
-
class
|
24
|
-
attr_reader :
|
4
|
+
class CommandError < StandardError
|
5
|
+
attr_reader :command, :args, :output
|
6
|
+
|
7
|
+
def initialize(command, args, output)
|
8
|
+
super("#{command} failed")
|
9
|
+
@command = command
|
10
|
+
@args = args
|
11
|
+
@output = output
|
12
|
+
end
|
13
|
+
end
|
25
14
|
|
26
|
-
|
27
|
-
|
15
|
+
class Repository
|
16
|
+
attr_reader :path, :root, :branch, :head, :encoding
|
28
17
|
|
29
|
-
|
18
|
+
SHA_PATTERN = /^[A-Fa-f0-9]{5,40}$/
|
19
|
+
REVISION_PATTERN = /^[\w\-\.]+([\^~](\d+)?)*$/
|
30
20
|
DEFAULT_ENCODING = 'utf-8'
|
21
|
+
MIN_GIT_VERSION = '1.6.0'
|
22
|
+
LOCK = 'Gitrb.Repository.lock'
|
31
23
|
|
32
24
|
if RUBY_VERSION > '1.9'
|
33
25
|
def set_encoding(s); s.force_encoding(@encoding); end
|
@@ -46,17 +38,8 @@ module Gitrb
|
|
46
38
|
@path.chomp!('/')
|
47
39
|
@path += '/.git' if !@bare
|
48
40
|
|
49
|
-
if options[:
|
50
|
-
|
51
|
-
raise ArgumentError, "Not a valid Git repository: '#{@path}'" if !File.directory?(@path)
|
52
|
-
if @bare
|
53
|
-
Dir.chdir(@path) { git_init('--bare') }
|
54
|
-
else
|
55
|
-
Dir.chdir(@path[0..-6]) { git_init }
|
56
|
-
end
|
57
|
-
else
|
58
|
-
raise ArgumentError, "Not a valid Git repository: '#{@path}'" if !File.directory?("#{@path}/objects")
|
59
|
-
end
|
41
|
+
check_git_version if !options[:ignore_version]
|
42
|
+
open_repository(options[:create])
|
60
43
|
|
61
44
|
load_packs
|
62
45
|
load
|
@@ -75,7 +58,7 @@ module Gitrb
|
|
75
58
|
|
76
59
|
# Has our repository been changed on disk?
|
77
60
|
def changed?
|
78
|
-
head.nil?
|
61
|
+
head.nil? || head.id != read_head_id
|
79
62
|
end
|
80
63
|
|
81
64
|
# Load the repository, if it has been changed on disk.
|
@@ -85,17 +68,17 @@ module Gitrb
|
|
85
68
|
|
86
69
|
# Is there any transaction going on?
|
87
70
|
def in_transaction?
|
88
|
-
Thread.current[
|
71
|
+
Thread.current[LOCK]
|
89
72
|
end
|
90
73
|
|
91
74
|
# Diff
|
92
75
|
def diff(from, to, path = nil)
|
93
76
|
if from && !(Commit === from)
|
94
|
-
raise ArgumentError if
|
77
|
+
raise ArgumentError, "Invalid sha: #{from}" if from !~ SHA_PATTERN
|
95
78
|
from = Reference.new(:repository => self, :id => from)
|
96
79
|
end
|
97
80
|
if !(Commit === to)
|
98
|
-
raise ArgumentError if
|
81
|
+
raise ArgumentError, "Invalid sha: #{to}" if to !~ SHA_PATTERN
|
99
82
|
to = Reference.new(:repository => self, :id => to)
|
100
83
|
end
|
101
84
|
Diff.new(from, to, git_diff_tree('--root', '-u', '--full-index', from && from.id, to.id, '--', path))
|
@@ -131,7 +114,7 @@ module Gitrb
|
|
131
114
|
|
132
115
|
commit = Commit.new(:repository => self,
|
133
116
|
:tree => root,
|
134
|
-
:
|
117
|
+
:parents => head,
|
135
118
|
:author => author,
|
136
119
|
:committer => committer,
|
137
120
|
:message => message)
|
@@ -145,17 +128,21 @@ module Gitrb
|
|
145
128
|
|
146
129
|
# Returns a list of commits starting from head commit.
|
147
130
|
def log(limit = 10, start = nil, path = nil)
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
131
|
+
limit = limit.to_s
|
132
|
+
start = start.to_s
|
133
|
+
raise ArgumentError, "Invalid limit: #{limit}" if limit !~ /^\d+$/
|
134
|
+
raise ArgumentError, "Invalid commit: #{start}" if start =~ /^\-/
|
135
|
+
args = ['--pretty=tformat:%H%n%P%n%T%n%an%n%ae%n%at%n%cn%n%ce%n%ct%n%x00%s%n%b%x00', "-#{limit}" ]
|
136
|
+
args << start if !start.empty?
|
137
|
+
args << '--' << path if path && !path.empty?
|
152
138
|
log = git_log(*args).split(/\n*\x00\n*/)
|
153
139
|
commits = []
|
154
140
|
log.each_slice(2) do |data, message|
|
155
141
|
data = data.split("\n")
|
142
|
+
parents = data[1].empty? ? nil : data[1].split(' ').map {|id| Reference.new(:repository => self, :id => id) }
|
156
143
|
commits << Commit.new(:repository => self,
|
157
144
|
:id => data[0],
|
158
|
-
:
|
145
|
+
:parents => parents,
|
159
146
|
:tree => Reference.new(:repository => self, :id => data[2]),
|
160
147
|
:author => User.new(data[3], data[4], Time.at(data[5].to_i)),
|
161
148
|
:committer => User.new(data[6], data[7], Time.at(data[8].to_i)),
|
@@ -171,15 +158,17 @@ module Gitrb
|
|
171
158
|
#
|
172
159
|
# Returns a tree, blob, commit or tag object.
|
173
160
|
def get(id)
|
174
|
-
raise
|
161
|
+
raise ArgumentError, 'No id given' if !(String === id)
|
162
|
+
|
175
163
|
if id =~ SHA_PATTERN
|
176
|
-
raise NotFound, "Sha too short" if id.length < 5
|
164
|
+
raise NotFound, "Sha too short: #{id}" if id.length < 5
|
177
165
|
list = @objects.find(id).to_a
|
166
|
+
raise NotFound, "Sha is ambiguous: #{id}" if list.size > 1
|
178
167
|
return list.first if list.size == 1
|
179
168
|
elsif id =~ REVISION_PATTERN
|
180
169
|
list = git_rev_parse(id).split("\n") rescue nil
|
181
|
-
raise NotFound, "Revision not found" if !list || list.empty?
|
182
|
-
raise NotFound, "Revision is ambiguous" if list.size > 1
|
170
|
+
raise NotFound, "Revision not found: #{id}" if !list || list.empty?
|
171
|
+
raise NotFound, "Revision is ambiguous: #{id}" if list.size > 1
|
183
172
|
id = list.first
|
184
173
|
end
|
185
174
|
|
@@ -188,7 +177,7 @@ module Gitrb
|
|
188
177
|
path = object_path(id)
|
189
178
|
if File.exists?(path) || (glob = Dir.glob(path + '*')).size >= 1
|
190
179
|
if glob
|
191
|
-
raise NotFound, "Sha is ambiguous" if glob.size > 1
|
180
|
+
raise NotFound, "Sha is ambiguous: #{id}" if glob.size > 1
|
192
181
|
path = glob.first
|
193
182
|
id = path[-41..-40] + path[-38..-1]
|
194
183
|
end
|
@@ -203,12 +192,12 @@ module Gitrb
|
|
203
192
|
raise NotFound, "Bad object: #{id}" if content.length != size.to_i
|
204
193
|
else
|
205
194
|
trie = @packs.find(id)
|
206
|
-
raise NotFound, "Object not found" if !trie
|
195
|
+
raise NotFound, "Object not found: #{id}" if !trie
|
207
196
|
|
208
197
|
id += trie.key[-(41 - id.length)...-1]
|
209
198
|
|
210
199
|
list = trie.to_a
|
211
|
-
raise NotFound, "Sha is ambiguous" if list.size > 1
|
200
|
+
raise NotFound, "Sha is ambiguous: #{id}" if list.size > 1
|
212
201
|
|
213
202
|
pack, offset = list.first
|
214
203
|
content, type = pack.get_object(offset)
|
@@ -217,14 +206,14 @@ module Gitrb
|
|
217
206
|
@logger.debug "gitrb: Loaded #{id}"
|
218
207
|
|
219
208
|
set_encoding(id)
|
220
|
-
object =
|
209
|
+
object = GitObject.factory(type, :repository => self, :id => id, :data => content)
|
221
210
|
@objects.insert(id, object)
|
222
211
|
object
|
223
212
|
end
|
224
213
|
|
225
|
-
def get_tree(id) get_type(id,
|
226
|
-
def get_blob(id) get_type(id,
|
227
|
-
def get_commit(id) get_type(id,
|
214
|
+
def get_tree(id) get_type(id, :tree) end
|
215
|
+
def get_blob(id) get_type(id, :blob) end
|
216
|
+
def get_commit(id) get_type(id, :commit) end
|
228
217
|
|
229
218
|
# Write a raw object to the repository.
|
230
219
|
#
|
@@ -258,22 +247,22 @@ module Gitrb
|
|
258
247
|
cmd = name.to_s
|
259
248
|
if cmd[0..3] == 'git_'
|
260
249
|
ENV['GIT_DIR'] = path
|
261
|
-
args = args.flatten.compact.map {|s| "'" + s.to_s.gsub("'", "'\\\\''") + "'" }.join(' ')
|
262
250
|
cmd = cmd[4..-1].tr('_', '-')
|
263
|
-
|
251
|
+
args = args.flatten.compact.map {|s| "'" + s.to_s.gsub("'", "'\\\\''") + "'" }.join(' ')
|
252
|
+
cmdline = "git #{cmd} #{args} 2>&1"
|
264
253
|
|
265
|
-
@logger.debug "gitrb: #{
|
254
|
+
@logger.debug "gitrb: #{cmdline}"
|
266
255
|
|
267
256
|
# Read in binary mode (ascii-8bit) and convert afterwards
|
268
257
|
out = if block_given?
|
269
|
-
IO.popen(
|
258
|
+
IO.popen(cmdline, 'rb', &block)
|
270
259
|
else
|
271
|
-
set_encoding IO.popen(
|
260
|
+
set_encoding IO.popen(cmdline, 'rb') {|io| io.read }
|
272
261
|
end
|
273
262
|
|
274
263
|
if $?.exitstatus > 0
|
275
264
|
return '' if $?.exitstatus == 1 && out == ''
|
276
|
-
raise
|
265
|
+
raise CommandError.new("git #{cmd}", args, out)
|
277
266
|
end
|
278
267
|
|
279
268
|
out
|
@@ -305,16 +294,42 @@ module Gitrb
|
|
305
294
|
end
|
306
295
|
end
|
307
296
|
|
308
|
-
|
297
|
+
private
|
298
|
+
|
299
|
+
def check_git_version
|
300
|
+
version = git_version
|
301
|
+
raise "Invalid git version: #{version}" if version !~ /^git version ([\d\.]+)$/
|
302
|
+
a = $1.split('.').map {|s| s.to_i }
|
303
|
+
b = MIN_GIT_VERSION.split('.').map {|s| s.to_i }
|
304
|
+
while !a.empty? && !b.empty? && a.first == b.first
|
305
|
+
a.shift
|
306
|
+
b.shift
|
307
|
+
end
|
308
|
+
raise "Minimum required git version is #{MIN_GIT_VERSION}" if a.first.to_i < b.first.to_i
|
309
|
+
end
|
310
|
+
|
311
|
+
def open_repository(create)
|
312
|
+
if create && !File.exists?("#{@path}/objects")
|
313
|
+
FileUtils.mkpath(@path) if !File.exists?(@path)
|
314
|
+
raise ArgumentError, "Not a valid Git repository: '#{@path}'" if !File.directory?(@path)
|
315
|
+
if @bare
|
316
|
+
Dir.chdir(@path) { git_init '--bare' }
|
317
|
+
else
|
318
|
+
Dir.chdir(@path[0..-6]) { git_init }
|
319
|
+
end
|
320
|
+
else
|
321
|
+
raise ArgumentError, "Not a valid Git repository: '#{@path}'" if !File.directory?("#{@path}/objects")
|
322
|
+
end
|
323
|
+
end
|
309
324
|
|
310
325
|
# Start a transaction.
|
311
326
|
#
|
312
327
|
# Tries to get lock on lock file, load the this repository if
|
313
328
|
# has changed in the repository.
|
314
329
|
def start_transaction
|
315
|
-
file = File.open("#{head_path}.lock",
|
330
|
+
file = File.open("#{head_path}.lock", 'w')
|
316
331
|
file.flock(File::LOCK_EX)
|
317
|
-
Thread.current[
|
332
|
+
Thread.current[LOCK] = file
|
318
333
|
refresh
|
319
334
|
end
|
320
335
|
|
@@ -331,8 +346,8 @@ module Gitrb
|
|
331
346
|
#
|
332
347
|
# Release the lock file.
|
333
348
|
def finish_transaction
|
334
|
-
Thread.current[
|
335
|
-
Thread.current[
|
349
|
+
Thread.current[LOCK].close rescue nil
|
350
|
+
Thread.current[LOCK] = nil
|
336
351
|
File.unlink("#{head_path}.lock") rescue nil
|
337
352
|
end
|
338
353
|
|
@@ -392,7 +407,7 @@ module Gitrb
|
|
392
407
|
if File.exists?(head_path)
|
393
408
|
File.read(head_path).strip
|
394
409
|
elsif File.exists?("#{path}/packed-refs")
|
395
|
-
File.open("#{path}/packed-refs",
|
410
|
+
File.open("#{path}/packed-refs", 'rb') do |io|
|
396
411
|
while line = io.gets
|
397
412
|
line.strip!
|
398
413
|
next if line[0..0] == '#'
|
@@ -404,7 +419,7 @@ module Gitrb
|
|
404
419
|
end
|
405
420
|
|
406
421
|
def write_head_id(id)
|
407
|
-
File.open(head_path,
|
422
|
+
File.open(head_path, 'wb') {|file| file.write(id) }
|
408
423
|
end
|
409
424
|
|
410
425
|
def legacy_loose_object?(buf)
|
data/lib/gitrb/tag.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Gitrb
|
2
2
|
|
3
|
-
class Tag <
|
3
|
+
class Tag < GitObject
|
4
4
|
attr_accessor :object, :tagtype, :tagger, :message
|
5
5
|
|
6
6
|
def initialize(options = {})
|
@@ -9,7 +9,7 @@ module Gitrb
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def ==(other)
|
12
|
-
Tag === other
|
12
|
+
Tag === other && id == other.id
|
13
13
|
end
|
14
14
|
|
15
15
|
def parse(data)
|
data/lib/gitrb/tree.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Gitrb
|
2
2
|
|
3
|
-
class Tree <
|
3
|
+
class Tree < GitObject
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
attr_accessor :mode, :repository
|
@@ -15,7 +15,7 @@ module Gitrb
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def type
|
18
|
-
|
18
|
+
:tree
|
19
19
|
end
|
20
20
|
|
21
21
|
def ==(other)
|
@@ -30,7 +30,7 @@ module Gitrb
|
|
30
30
|
|
31
31
|
# Has this tree been modified?
|
32
32
|
def modified?
|
33
|
-
@modified || @children.values.any? { |entry| entry.type ==
|
33
|
+
@modified || @children.values.any? { |entry| entry.type == :tree && entry.modified? }
|
34
34
|
end
|
35
35
|
|
36
36
|
def dump
|
@@ -61,7 +61,7 @@ module Gitrb
|
|
61
61
|
if path.size == 1
|
62
62
|
entry
|
63
63
|
elsif entry
|
64
|
-
raise
|
64
|
+
raise 'Not a tree' if entry.type != :tree
|
65
65
|
entry[path[1..-1]]
|
66
66
|
end
|
67
67
|
end
|
@@ -70,9 +70,9 @@ module Gitrb
|
|
70
70
|
def []=(path, entry)
|
71
71
|
path = normalize_path(path)
|
72
72
|
if path.empty?
|
73
|
-
raise
|
73
|
+
raise 'Empty path'
|
74
74
|
elsif path.size == 1
|
75
|
-
raise
|
75
|
+
raise 'No blob or tree' if entry.type != :tree && entry.type != :blob
|
76
76
|
entry.repository = repository
|
77
77
|
@modified = true
|
78
78
|
@children[path.first] = entry
|
@@ -82,7 +82,7 @@ module Gitrb
|
|
82
82
|
tree = @children[path.first] = Tree.new(:repository => repository)
|
83
83
|
@modified = true
|
84
84
|
end
|
85
|
-
raise
|
85
|
+
raise 'Not a tree' if tree.type != :tree
|
86
86
|
tree[path[1..-1]] = entry
|
87
87
|
end
|
88
88
|
end
|
@@ -91,13 +91,13 @@ module Gitrb
|
|
91
91
|
def delete(path)
|
92
92
|
path = normalize_path(path)
|
93
93
|
if path.empty?
|
94
|
-
raise
|
94
|
+
raise 'Empty path'
|
95
95
|
elsif path.size == 1
|
96
96
|
@modified = true
|
97
97
|
@children.delete(path.first)
|
98
98
|
else
|
99
99
|
tree = @children[path.first]
|
100
|
-
raise
|
100
|
+
raise 'Not a tree' if tree.type != :tree
|
101
101
|
tree.delete(path[1..-1])
|
102
102
|
end
|
103
103
|
end
|
data/lib/gitrb/user.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module Gitrb
|
2
2
|
|
3
|
-
class User
|
4
|
-
attr_accessor :name, :email, :date
|
5
|
-
|
3
|
+
class User < Struct.new(:name, :email, :date)
|
6
4
|
def initialize(name, email, date = Time.now)
|
7
|
-
|
5
|
+
super
|
8
6
|
end
|
9
7
|
|
10
8
|
def dump
|
11
|
-
|
9
|
+
off = date.gmt_offset / 60
|
10
|
+
'%s <%s> %d %s%02d%02d' % [name, email, date.to_i, off < 0 ? '-' : '+', off / 60, off % 60]
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.parse(user)
|
data/lib/gitrb.rb
CHANGED
@@ -1 +1,18 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'logger'
|
5
|
+
require 'enumerator'
|
6
|
+
|
7
|
+
require 'gitrb/util'
|
8
|
+
require 'gitrb/gitobject'
|
9
|
+
require 'gitrb/reference'
|
10
|
+
require 'gitrb/blob'
|
11
|
+
require 'gitrb/diff'
|
12
|
+
require 'gitrb/tree'
|
13
|
+
require 'gitrb/tag'
|
14
|
+
require 'gitrb/user'
|
15
|
+
require 'gitrb/pack'
|
16
|
+
require 'gitrb/commit'
|
17
|
+
require 'gitrb/trie'
|
1
18
|
require 'gitrb/repository'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-05-21 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,8 +30,9 @@ files:
|
|
30
30
|
- lib/gitrb/blob.rb
|
31
31
|
- lib/gitrb/commit.rb
|
32
32
|
- lib/gitrb/diff.rb
|
33
|
-
- lib/gitrb/
|
33
|
+
- lib/gitrb/gitobject.rb
|
34
34
|
- lib/gitrb/pack.rb
|
35
|
+
- lib/gitrb/reference.rb
|
35
36
|
- lib/gitrb/repository.rb
|
36
37
|
- lib/gitrb/tag.rb
|
37
38
|
- lib/gitrb/tree.rb
|