git_store 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,32 +1,17 @@
1
1
  require 'rake'
2
- require "rake/rdoctask"
3
-
4
- begin
5
- require 'spec/rake/spectask'
6
- rescue LoadError
7
- puts <<-EOS
8
- To use rspec for testing you must install the rspec gem:
9
- gem install rspec
10
- EOS
11
- exit(0)
12
- end
2
+ require 'rdoc/task'
3
+ require 'rspec/core/rake_task'
13
4
 
14
5
  desc "Run all specs"
15
- Spec::Rake::SpecTask.new(:spec) do |t|
16
- t.spec_opts = ['-cfs']
17
- t.spec_files = FileList['test/**/*_spec.rb']
18
- end
19
-
20
- desc "Print SpecDocs"
21
- Spec::Rake::SpecTask.new(:doc) do |t|
22
- t.spec_opts = ["--format", "specdoc"]
23
- t.spec_files = FileList['test/*_spec.rb']
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'test/**/*_spec.rb'
8
+ spec.rspec_opts = ['--backtrace']
24
9
  end
25
10
 
26
11
  desc "Generate the RDoc"
27
- Rake::RDocTask.new do |rdoc|
12
+ RDoc::Task.new do |rdoc|
28
13
  files = ["README.md", "LICENSE", "lib/**/*.rb"]
29
- rdoc.rdoc_files.add(files)
14
+ rdoc.rdoc_files.include(files)
30
15
  rdoc.main = "README.md"
31
16
  rdoc.title = "Git Store - using Git as versioned data store in Ruby"
32
17
  end
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'git_store'
3
- s.version = '0.3.1'
3
+ s.version = '0.3.3'
4
4
  s.summary = 'a simple data store based on git'
5
5
  s.author = 'Matthias Georgi'
6
6
  s.email = 'matti.georgi@gmail.com'
7
- s.homepage = 'http://ww.matthias-georgi.de/git_store'
7
+ s.homepage = 'http://georgi.github.com/git_store'
8
8
  s.description = <<END
9
9
  GitStore implements a versioned data store based on the revision
10
10
  management system Git. You can store object hierarchies as nested
@@ -198,10 +198,10 @@ class GitStore
198
198
  # Example:
199
199
  # store.transaction { store['a'] = 'b' }
200
200
  #
201
- def transaction(message = "")
201
+ def transaction(message = "", author = User.from_config, committer = author)
202
202
  start_transaction
203
203
  result = yield
204
- commit message
204
+ commit message, author, committer
205
205
 
206
206
  result
207
207
  rescue
@@ -293,13 +293,13 @@ class GitStore
293
293
  obj_offset = offset
294
294
  packfile.seek(offset)
295
295
 
296
- c = packfile.read(1)[0]
296
+ c = packfile.read(1)[0].ord
297
297
  size = c & 0xf
298
298
  type = (c >> 4) & 7
299
299
  shift = 4
300
300
  offset += 1
301
301
  while c & 0x80 != 0
302
- c = packfile.read(1)[0]
302
+ c = packfile.read(1)[0].ord
303
303
  size |= ((c & 0x7f) << shift)
304
304
  shift += 7
305
305
  offset += 1
@@ -326,10 +326,10 @@ class GitStore
326
326
 
327
327
  if type == OBJ_OFS_DELTA
328
328
  i = 0
329
- c = data[i]
329
+ c = data[i].ord
330
330
  base_offset = c & 0x7f
331
331
  while c & 0x80 != 0
332
- c = data[i += 1]
332
+ c = data[i += 1].ord
333
333
  base_offset += 1
334
334
  base_offset <<= 7
335
335
  base_offset |= c & 0x7f
@@ -380,21 +380,21 @@ class GitStore
380
380
  dest_size, pos = patch_delta_header_size(delta, pos)
381
381
  dest = ""
382
382
  while pos < delta.size
383
- c = delta[pos]
383
+ c = delta[pos].ord
384
384
  pos += 1
385
385
  if c & 0x80 != 0
386
386
  pos -= 1
387
387
  cp_off = cp_size = 0
388
- cp_off = delta[pos += 1] if c & 0x01 != 0
389
- cp_off |= delta[pos += 1] << 8 if c & 0x02 != 0
390
- cp_off |= delta[pos += 1] << 16 if c & 0x04 != 0
391
- cp_off |= delta[pos += 1] << 24 if c & 0x08 != 0
392
- cp_size = delta[pos += 1] if c & 0x10 != 0
393
- cp_size |= delta[pos += 1] << 8 if c & 0x20 != 0
394
- cp_size |= delta[pos += 1] << 16 if c & 0x40 != 0
388
+ cp_off = delta[pos += 1].ord if c & 0x01 != 0
389
+ cp_off |= delta[pos += 1].ord << 8 if c & 0x02 != 0
390
+ cp_off |= delta[pos += 1].ord << 16 if c & 0x04 != 0
391
+ cp_off |= delta[pos += 1].ord << 24 if c & 0x08 != 0
392
+ cp_size = delta[pos += 1].ord if c & 0x10 != 0
393
+ cp_size |= delta[pos += 1].ord << 8 if c & 0x20 != 0
394
+ cp_size |= delta[pos += 1].ord << 16 if c & 0x40 != 0
395
395
  cp_size = 0x10000 if cp_size == 0
396
396
  pos += 1
397
- dest += base[cp_off,cp_size]
397
+ dest += base[cp_off, cp_size]
398
398
  elsif c != 0
399
399
  dest += delta[pos,c]
400
400
  pos += c
@@ -414,6 +414,7 @@ class GitStore
414
414
  if c == nil
415
415
  raise PackFormatError, 'invalid delta header'
416
416
  end
417
+ c = c.ord
417
418
  pos += 1
418
419
  size |= (c & 0x7f) << shift
419
420
  shift += 7
@@ -74,12 +74,15 @@ class GitStore
74
74
 
75
75
  # Write entry with specified name.
76
76
  def put(name, value)
77
- @modified = true
78
-
79
77
  if value.is_a?(Tree)
78
+ @modified = true
80
79
  @table[name] = value
81
80
  else
82
- @table[name] = Blob.new(store, nil, handler_for(name).write(value))
81
+ data = handler_for(name).write(value)
82
+ if @table[name].nil? or data != @table[name].data
83
+ @modified = true
84
+ @table[name] = Blob.new(store, nil, data)
85
+ end
83
86
  end
84
87
 
85
88
  value
@@ -1,29 +1,38 @@
1
1
  class GitStore
2
-
3
- class User
4
- attr_accessor :name, :email, :time
5
-
6
- def initialize(name, email, time)
7
- @name, @email, @time = name, email, time
8
- end
9
-
2
+ class User < Struct.new(:name, :email, :time)
10
3
  def dump
11
4
  "#{ name } <#{email}> #{ time.to_i } #{ time.strftime('%z') }"
12
5
  end
6
+ alias to_s dump
13
7
 
14
- def self.from_config
15
- name = IO.popen("git config user.name") { |io| io.gets.chomp }
16
- email = IO.popen("git config user.email") { |io| io.gets.chomp }
8
+ def inspect
9
+ "#<GitStore::User name=%p email=%p time=%p>" % [name, email, time]
10
+ end
17
11
 
12
+ def self.from_config
13
+ name, email = config_get('user.name'), config_get('user.email')
18
14
  new name, email, Time.now
19
15
  end
20
16
 
17
+ def self.config_get(key)
18
+ value = `git config #{key}`.chomp
19
+
20
+ if $?.exitstatus == 0
21
+ return value unless value.empty?
22
+ raise RuntimError, "#{key} is empty"
23
+ else
24
+ raise RuntimError, "No #{key} found in git config"
25
+ end
26
+ end
27
+
28
+ def self.config_user_email
29
+ email = `git config user.email`.chomp
30
+ end
31
+
21
32
  def self.parse(user)
22
33
  if match = user.match(/(.*)<(.*)> (\d+) ([+-]\d+)/)
23
34
  new match[1].strip, match[2].strip, Time.at(match[3].to_i + match[4].to_i * 3600)
24
35
  end
25
36
  end
26
-
27
37
  end
28
-
29
38
  end
@@ -32,7 +32,7 @@ This is a message"
32
32
  end
33
33
 
34
34
  it "should be readable by git binary" do
35
- time = Time.local(2009, 4, 20)
35
+ time = Time.utc(2009, 4, 20)
36
36
  author = GitStore::User.new("hans", "hans@email.de", time)
37
37
 
38
38
  store['a'] = "Yay"
@@ -41,7 +41,7 @@ This is a message"
41
41
  IO.popen("git log") do |io|
42
42
  io.gets.should == "commit #{commit.id}\n"
43
43
  io.gets.should == "Author: hans <hans@email.de>\n"
44
- io.gets.should == "Date: Mon Apr 20 00:00:00 2009 #{Time.now.strftime('%z')}\n"
44
+ io.gets.should == "Date: Mon Apr 20 00:00:00 2009 +0000\n"
45
45
  io.gets.should == "\n"
46
46
  io.gets.should == " Commit Message\n"
47
47
  end
@@ -14,6 +14,8 @@ describe GitStore do
14
14
  Dir.chdir REPO
15
15
 
16
16
  `git init`
17
+ `git config user.name 'User Name'`
18
+ `git config user.email 'user.name@email.com'`
17
19
  @store = GitStore.new(REPO)
18
20
  end
19
21
 
@@ -243,14 +245,13 @@ describe GitStore do
243
245
 
244
246
  store.load
245
247
 
246
- user = GitStore::User.from_config
247
248
  id = File.read('.git/refs/tags/0.1')
248
249
  tag = store.get(id)
249
250
 
250
251
  tag.type.should == 'commit'
251
252
  tag.object.should == store.head
252
- tag.tagger.name.should == user.name
253
- tag.tagger.email.should == user.email
253
+ tag.tagger.name.should == 'User Name'
254
+ tag.tagger.email.should == 'user.name@email.com'
254
255
  tag.message.should =~ /message/
255
256
  end
256
257
 
metadata CHANGED
@@ -1,33 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: git_store
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Matthias Georgi
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-02-07 00:00:00 +01:00
13
- default_executable:
12
+ date: 2013-01-26 00:00:00.000000000 Z
14
13
  dependencies: []
14
+ description: ! 'GitStore implements a versioned data store based on the revision
15
15
 
16
- description: |
17
- GitStore implements a versioned data store based on the revision
18
16
  management system Git. You can store object hierarchies as nested
17
+
19
18
  hashes, which will be mapped on the directory structure of a git
19
+
20
20
  repository. GitStore checks out the repository into a in-memory
21
+
21
22
  representation, which can be modified and finally committed.
22
23
 
24
+ '
23
25
  email: matti.georgi@gmail.com
24
26
  executables: []
25
-
26
27
  extensions: []
27
-
28
- extra_rdoc_files:
28
+ extra_rdoc_files:
29
29
  - README.md
30
- files:
30
+ files:
31
31
  - .gitignore
32
32
  - LICENSE
33
33
  - README.md
@@ -47,33 +47,29 @@ files:
47
47
  - test/commit_spec.rb
48
48
  - test/git_store_spec.rb
49
49
  - test/tree_spec.rb
50
- has_rdoc: true
51
- homepage: http://ww.matthias-georgi.de/git_store
50
+ homepage: http://georgi.github.com/git_store
52
51
  licenses: []
53
-
54
52
  post_install_message:
55
53
  rdoc_options: []
56
-
57
- require_paths:
54
+ require_paths:
58
55
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
71
68
  requirements: []
72
-
73
69
  rubyforge_project:
74
- rubygems_version: 1.3.5
70
+ rubygems_version: 1.8.24
75
71
  signing_key:
76
72
  specification_version: 3
77
73
  summary: a simple data store based on git
78
74
  test_files: []
79
-
75
+ has_rdoc: true