gitrb 0.2.3 → 0.2.4
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/gitrb.gemspec +1 -1
- data/lib/gitrb.rb +0 -1
- data/lib/gitrb/repository.rb +36 -67
- data/lib/gitrb/util.rb +0 -11
- data/test/repository_test.rb +0 -51
- metadata +3 -3
data/gitrb.gemspec
CHANGED
data/lib/gitrb.rb
CHANGED
data/lib/gitrb/repository.rb
CHANGED
@@ -42,8 +42,6 @@ module Gitrb
|
|
42
42
|
@branch = options[:branch] || 'master'
|
43
43
|
@logger = options[:logger] || Logger.new(nil)
|
44
44
|
@encoding = options[:encoding] || DEFAULT_ENCODING
|
45
|
-
@lock = {}
|
46
|
-
@transaction = Mutex.new
|
47
45
|
|
48
46
|
@path = options[:path]
|
49
47
|
@path.chomp!('/')
|
@@ -56,6 +54,14 @@ module Gitrb
|
|
56
54
|
load
|
57
55
|
end
|
58
56
|
|
57
|
+
def dup
|
58
|
+
super.instance_eval do
|
59
|
+
@objects = Trie.new
|
60
|
+
load
|
61
|
+
self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
59
65
|
# Bare repository?
|
60
66
|
def bare?
|
61
67
|
@bare
|
@@ -63,10 +69,8 @@ module Gitrb
|
|
63
69
|
|
64
70
|
# Switch branch
|
65
71
|
def branch=(branch)
|
66
|
-
@
|
67
|
-
|
68
|
-
load
|
69
|
-
end
|
72
|
+
@branch = branch
|
73
|
+
load
|
70
74
|
end
|
71
75
|
|
72
76
|
# Has our repository been changed on disk?
|
@@ -81,22 +85,15 @@ module Gitrb
|
|
81
85
|
|
82
86
|
# Clear cached objects
|
83
87
|
def clear
|
84
|
-
@
|
85
|
-
|
86
|
-
load
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Is there any transaction going on?
|
91
|
-
def in_transaction?
|
92
|
-
!!@lock[Thread.current.object_id]
|
88
|
+
@objects.clear
|
89
|
+
load
|
93
90
|
end
|
94
91
|
|
95
92
|
# Difference between versions
|
96
93
|
# Options:
|
97
94
|
# :to - Required target commit
|
98
95
|
# :from - Optional source commit (otherwise comparision with empty tree)
|
99
|
-
# :path - Restrict to path
|
96
|
+
# :path - Restrict to path/or paths
|
100
97
|
# :detect_renames - Detect renames O(n^2)
|
101
98
|
# :detect_copies - Detect copies O(n^2), very slow
|
102
99
|
def diff(opts)
|
@@ -112,7 +109,7 @@ module Gitrb
|
|
112
109
|
Diff.new(from, to, git_diff_tree('--root', '--full-index', '-u',
|
113
110
|
opts[:detect_renames] ? '-M' : nil,
|
114
111
|
opts[:detect_copies] ? '-C' : nil,
|
115
|
-
from ? from.id : nil, to.id, '--', opts[:path]))
|
112
|
+
from ? from.id : nil, to.id, '--', *opts[:path]))
|
116
113
|
end
|
117
114
|
|
118
115
|
# All changes made inside a transaction are atomic. If some
|
@@ -122,19 +119,20 @@ module Gitrb
|
|
122
119
|
# repository.transaction { repository['a'] = 'b' }
|
123
120
|
#
|
124
121
|
def transaction(message = '', author = nil, committer = nil)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
122
|
+
lock = File.open("#{head_path}.lock", 'w')
|
123
|
+
lock.flock(File::LOCK_EX)
|
124
|
+
refresh
|
125
|
+
|
126
|
+
result = yield
|
127
|
+
commit(message, author, committer)
|
128
|
+
result
|
129
|
+
rescue
|
130
|
+
@objects.clear
|
131
|
+
load
|
132
|
+
raise
|
133
|
+
ensure
|
134
|
+
lock.close rescue nil
|
135
|
+
File.unlink("#{head_path}.lock") rescue nil
|
138
136
|
end
|
139
137
|
|
140
138
|
# Write a commit object to disk and set the head of the current branch.
|
@@ -162,15 +160,19 @@ module Gitrb
|
|
162
160
|
end
|
163
161
|
|
164
162
|
# Returns a list of commits starting from head commit.
|
163
|
+
# Options:
|
164
|
+
# :path - Restrict to path/or paths
|
165
|
+
# :max_count - Maximum count of commits
|
166
|
+
# :skip - Skip n commits
|
167
|
+
# :start - Commit to start from
|
165
168
|
def log(opts = {})
|
166
169
|
max_count = opts[:max_count]
|
167
170
|
skip = opts[:skip]
|
168
171
|
start = opts[:start]
|
169
|
-
path = opts[:path]
|
170
172
|
raise ArgumentError, "Invalid commit: #{start}" if start.to_s =~ /^\-/
|
171
173
|
log = git_log('--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',
|
172
174
|
skip ? "--skip=#{skip.to_i}" : nil,
|
173
|
-
max_count ? "--max-count=#{max_count.to_i}" : nil, start, '--', path).split(/\n*\x00\n*/)
|
175
|
+
max_count ? "--max-count=#{max_count.to_i}" : nil, start, '--', *opts[:path]).split(/\n*\x00\n*/)
|
174
176
|
commits = []
|
175
177
|
log.each_slice(2) do |data, message|
|
176
178
|
data = data.split("\n")
|
@@ -261,7 +263,7 @@ module Gitrb
|
|
261
263
|
|
262
264
|
content = object.dump
|
263
265
|
data = "#{object.type} #{content.bytesize rescue content.length}\0#{content}"
|
264
|
-
id =
|
266
|
+
id = Digest::SHA1.hexdigest(data)
|
265
267
|
path = object_path(id)
|
266
268
|
|
267
269
|
@logger.debug "gitrb: Storing #{id}"
|
@@ -348,34 +350,6 @@ module Gitrb
|
|
348
350
|
end
|
349
351
|
end
|
350
352
|
|
351
|
-
# Start a transaction.
|
352
|
-
#
|
353
|
-
# Tries to get lock on lock file, load the this repository if
|
354
|
-
# has changed in the repository.
|
355
|
-
def start_transaction
|
356
|
-
file = File.open("#{head_path}.lock", 'w')
|
357
|
-
file.flock(File::LOCK_EX)
|
358
|
-
@lock[Thread.current.object_id] = file
|
359
|
-
refresh
|
360
|
-
end
|
361
|
-
|
362
|
-
# Rerepository the state of the repository.
|
363
|
-
#
|
364
|
-
# Any changes made to the repository are discarded.
|
365
|
-
def rollback_transaction
|
366
|
-
@objects.clear
|
367
|
-
load
|
368
|
-
end
|
369
|
-
|
370
|
-
# Finish the transaction.
|
371
|
-
#
|
372
|
-
# Release the lock file.
|
373
|
-
def finish_transaction
|
374
|
-
@lock[Thread.current.object_id].close rescue nil
|
375
|
-
@lock.delete(Thread.current.object_id)
|
376
|
-
File.unlink("#{head_path}.lock") rescue nil
|
377
|
-
end
|
378
|
-
|
379
353
|
def get_type(id, expected)
|
380
354
|
object = get(id)
|
381
355
|
raise NotFound, "Wrong type #{object.type}, expected #{expected}" if object && object.type != expected
|
@@ -384,7 +358,7 @@ module Gitrb
|
|
384
358
|
|
385
359
|
def load_packs
|
386
360
|
@packs = Trie.new
|
387
|
-
@objects =
|
361
|
+
@objects = Trie.new
|
388
362
|
|
389
363
|
packs_path = "#{@path}/objects/pack"
|
390
364
|
if File.directory?(packs_path)
|
@@ -410,11 +384,6 @@ module Gitrb
|
|
410
384
|
@logger.debug "gitrb: Reloaded, head is #{head ? head.id : 'nil'}"
|
411
385
|
end
|
412
386
|
|
413
|
-
# Returns the hash value of an object string.
|
414
|
-
def sha(str)
|
415
|
-
Digest::SHA1.hexdigest(str)[0, 40]
|
416
|
-
end
|
417
|
-
|
418
387
|
# Returns the path to the current head file.
|
419
388
|
def head_path
|
420
389
|
"#{path}/refs/heads/#{branch}"
|
data/lib/gitrb/util.rb
CHANGED
data/test/repository_test.rb
CHANGED
@@ -190,31 +190,6 @@ describe Gitrb do
|
|
190
190
|
repo.git_show(c).should.equal 'c'
|
191
191
|
end
|
192
192
|
|
193
|
-
it 'should allow only one transaction' do
|
194
|
-
file 'a/b', 'Hello'
|
195
|
-
|
196
|
-
ready = false
|
197
|
-
|
198
|
-
# This test case produces a deadlock in old ruby versions
|
199
|
-
# (Works in 1.8.7_p302 and 1.9)
|
200
|
-
repo.transaction do
|
201
|
-
Thread.start do
|
202
|
-
repo.transaction do
|
203
|
-
sleep 0.1
|
204
|
-
repo.root['a/b'] = Gitrb::Blob.new(:data => 'Changed by second thread')
|
205
|
-
end
|
206
|
-
ready = true
|
207
|
-
end
|
208
|
-
repo.root['a/b'] = Gitrb::Blob.new(:data => 'Changed')
|
209
|
-
end
|
210
|
-
|
211
|
-
repo.root['a/b'].data.should.equal 'Changed'
|
212
|
-
|
213
|
-
sleep 0.01 until ready
|
214
|
-
|
215
|
-
repo.root['a/b'].data.should.equal 'Changed by second thread'
|
216
|
-
end
|
217
|
-
|
218
193
|
it 'should find all objects' do
|
219
194
|
repo.root['c'] = Gitrb::Blob.new(:data => 'Hello')
|
220
195
|
repo.root['d'] = Gitrb::Blob.new(:data => 'World')
|
@@ -272,32 +247,6 @@ describe Gitrb do
|
|
272
247
|
repo.root['a'].data.should.equal 'data'
|
273
248
|
end
|
274
249
|
|
275
|
-
it 'should forbid branch switching from within transaction' do
|
276
|
-
repo.transaction do
|
277
|
-
lambda { repo.branch = 'test' }.should.raise(ThreadError)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
it 'should forbid clearing from within transaction' do
|
282
|
-
repo.transaction do
|
283
|
-
lambda { repo.clear }.should.raise(ThreadError)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'should forbid nested transactions' do
|
288
|
-
repo.transaction do
|
289
|
-
lambda { repo.transaction {} }.should.raise(ThreadError)
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
it 'should be in transaction' do
|
294
|
-
repo.should.not.be.in_transaction
|
295
|
-
repo.transaction do
|
296
|
-
repo.should.be.in_transaction
|
297
|
-
end
|
298
|
-
repo.should.not.be.in_transaction
|
299
|
-
end
|
300
|
-
|
301
250
|
it "should diff 2 commits" do
|
302
251
|
repo.root['x'] = Gitrb::Blob.new(:data => 'a')
|
303
252
|
repo.root['y'] = Gitrb::Blob.new(:data => "\nFirst Line.\nSecond Line.\nLast Line.\n")
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Mendler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-16 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|