git_dump 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDRlN2E3ZTg5MmUzZWI5M2IxNjhjYzU0Y2Y3ZmQ2YWZiYzU3MTcwMg==
5
- data.tar.gz: !binary |-
6
- MThmYjAxMzY5NGI3Yzg4YjU5ODg3ZDQwOTBlYTQ1MTJmOGYwZDk0Yw==
2
+ SHA256:
3
+ metadata.gz: 68a7d19a624eb19faef3d2cfee530421b2f95e7eb2712cbc0495db02abf8faf9
4
+ data.tar.gz: 330a3e791b620109a7695fa2fced5c4d14b67b65d44326154041055a4f1d52ee
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTA2NjUwNWNmNDU4NDVhNDNjYzUxN2U1ZDFkODg5N2I2YzY4MmE0MGI5OGYy
10
- Zjk2OGI3YzYxZTQ4NWY1NTFmYzRiNzgxNmQ0NzZiYTE3ZGNkZjgxOWE0ODMw
11
- ZDgyMDhkZGFjNWFhM2IyNWE5MDVmMTI2MmE3OGUzMDMxZGQ3N2Q=
12
- data.tar.gz: !binary |-
13
- N2RiOTIxY2Y3ZTgxOWM2MTYzOTMyNWNlNDhiMGNiYjBhNzNlYzM3ZDk2NGFk
14
- MzdiN2RmODBjZmE2NGU2Nzk3MThmYzJlYjM4NWU2NDEyNWE1ZjcwMDdmZDMz
15
- NWQ2YzJiMzUzNzg5OTRhYjMyNmQ4NzEwMTlmMWVkNGRlZGVkYzA=
6
+ metadata.gz: 3ee4d7241b044160c50eefdefd1dd98809edea36422f33cb3c0f7a9c1bd71b41e30dfe67b27e339d46079c9f849246c9d96868d1cd4cbb65686b32b8a543a448
7
+ data.tar.gz: ce5aadd0694dc570940760624d3fd75b46a1bc2a4561ee5ee82b38200bcf53da46d6f8086ad7537bab35c91fbd744348afc0b1e1829b6ebd407d098e03519050
@@ -2,61 +2,103 @@ AllCops:
2
2
  Exclude:
3
3
  - '*.gemspec'
4
4
 
5
- Lint/EndAlignment:
6
- AlignWith: variable
5
+ Layout/AccessModifierIndentation:
6
+ EnforcedStyle: outdent
7
+
8
+ Layout/CaseIndentation:
9
+ EnforcedStyle: end
10
+
11
+ Layout/DotPosition:
12
+ EnforcedStyle: trailing
13
+
14
+ Layout/EndAlignment:
15
+ EnforcedStyleAlignWith: variable
16
+
17
+ Layout/IndentFirstArrayElement:
18
+ EnforcedStyle: consistent
19
+
20
+ Layout/IndentFirstHashElement:
21
+ EnforcedStyle: consistent
22
+
23
+ Layout/SpaceBeforeBlockBraces:
24
+ EnforcedStyle: no_space
25
+ EnforcedStyleForEmptyBraces: no_space
26
+
27
+ Layout/SpaceInsideHashLiteralBraces:
28
+ EnforcedStyle: no_space
29
+
30
+ Lint/NestedPercentLiteral:
31
+ Enabled: false
32
+
33
+ Lint/UnneededSplatExpansion:
34
+ Enabled: false
7
35
 
8
36
  Metrics/AbcSize:
9
37
  Max: 25
10
38
 
39
+ Metrics/BlockLength:
40
+ Exclude:
41
+ - 'script/benchmark'
42
+ - 'spec/**/*.rb'
43
+
11
44
  Metrics/CyclomaticComplexity:
12
45
  Max: 10
13
46
 
14
47
  Metrics/MethodLength:
15
48
  Max: 20
16
49
 
50
+ Metrics/ModuleLength:
51
+ Max: 300
52
+
17
53
  Metrics/PerceivedComplexity:
18
54
  Max: 8
19
55
 
20
- Style/AccessModifierIndentation:
21
- EnforcedStyle: outdent
56
+ Style/Alias:
57
+ EnforcedStyle: prefer_alias_method
22
58
 
23
59
  Style/BracesAroundHashParameters:
24
60
  Enabled: false
25
61
 
26
- Style/CaseIndentation:
27
- IndentWhenRelativeTo: end
28
-
29
- Style/DotPosition:
30
- EnforcedStyle: trailing
31
-
32
62
  Style/DoubleNegation:
33
63
  Enabled: false
34
64
 
35
65
  Style/Encoding:
36
- EnforcedStyle: when_needed
66
+ Enabled: false
67
+
68
+ Style/FormatStringToken:
69
+ Enabled: false
37
70
 
38
71
  Style/HashSyntax:
39
72
  EnforcedStyle: hash_rockets
40
73
 
41
74
  Style/IfUnlessModifier:
42
- MaxLineLength: 40
75
+ Enabled: false
43
76
 
44
- Style/IndentHash:
45
- EnforcedStyle: consistent
77
+ Style/NumericPredicate:
78
+ EnforcedStyle: comparison
79
+
80
+ Style/ParallelAssignment:
81
+ Enabled: false
46
82
 
47
83
  Style/PercentLiteralDelimiters:
48
84
  PreferredDelimiters:
49
85
  '%w': '[]'
50
86
  '%W': '[]'
51
87
 
88
+ Style/SafeNavigation:
89
+ Enabled: false
90
+
52
91
  Style/Semicolon:
53
92
  AllowAsExpressionSeparator: true
54
93
 
55
- Style/SpaceBeforeBlockBraces:
56
- EnforcedStyle: no_space
94
+ Style/SignalException:
95
+ EnforcedStyle: semantic
57
96
 
58
- Style/SpaceInsideHashLiteralBraces:
59
- EnforcedStyle: no_space
97
+ Style/TrailingCommaInArguments:
98
+ EnforcedStyleForMultiline: no_comma
99
+
100
+ Style/TrailingCommaInArrayLiteral:
101
+ EnforcedStyleForMultiline: comma
60
102
 
61
- Style/TrailingComma:
103
+ Style/TrailingCommaInHashLiteral:
62
104
  EnforcedStyleForMultiline: comma
@@ -1,37 +1,40 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 1.8.7
4
- - 1.9.3
5
- - '2.0'
6
- - '2.1'
7
- - '2.2'
8
- - jruby-18mode
9
- - jruby-19mode
10
- - ree
11
- script:
12
- if [ -n "$RUBOCOP" ]; then
13
- bundle exec rubocop
14
- ; elif [ -n "$BENCHMARK" ]; then
15
- RUGGED=0 bundle exec script/benchmark; RUGGED=1 bundle exec script/benchmark
16
- ; else
17
- bundle exec rspec
18
- ; fi
4
+ - '1.9.3-p551'
5
+ - '2.2.10'
6
+ - '2.3.8'
7
+ - '2.4.6'
8
+ - '2.5.5'
9
+ - '2.6.3'
10
+ - 'jruby-9.1.9.0'
11
+ script: bundle exec rspec
12
+ before_install:
13
+ - gem install rubygems-update || gem install rubygems-update --version '< 3'
14
+ - gem update --system
15
+ - gem install bundler || gem install bundler --version '< 2'
19
16
  env:
20
- -
21
- - RUGGED=1
17
+ - DRIVER=git
18
+ - DRIVER=rugged
22
19
  matrix:
23
- fast_finish: true
24
20
  include:
25
- - env: RUBOCOP=true
26
- rvm: default
27
- - env: BENCHMARK=true RUGGED=1
28
- rvm: default
21
+ - env: RUBOCOP=✓
22
+ rvm: '2.6.3'
23
+ script: bundle exec rubocop
24
+ - env: BENCHMARK=✓
25
+ rvm: '2.6.3'
26
+ install: DRIVER=rugged bundle install --jobs=3 --retry=3
27
+ script:
28
+ - DRIVER=git bundle exec script/benchmark
29
+ - DRIVER=rugged bundle exec script/benchmark
30
+ - env: CHECK_RUBIES=✓
31
+ rvm: '2.6.3'
32
+ script: bundle exec travis_check_rubies
29
33
  exclude:
30
- - rvm: 1.8.7
31
- env: RUGGED=1
32
- - rvm: jruby-18mode
33
- env: RUGGED=1
34
- - rvm: jruby-19mode
35
- env: RUGGED=1
36
- - rvm: ree
37
- env: RUGGED=1
34
+ - rvm: '1.9.3-p551'
35
+ env: DRIVER=rugged
36
+ - rvm: 'jruby-9.1.9.0'
37
+ env: DRIVER=rugged
38
+ allow_failures:
39
+ - rvm: 'jruby-9.1.9.0'
40
+ env: DRIVER=git
@@ -0,0 +1 @@
1
+ exclude: [2.0, 2.1]
data/Gemfile CHANGED
@@ -1,5 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem 'rugged' if ENV['RUGGED'] == '1'
7
+ gem 'rugged', '>= 0.22' if ENV['DRIVER'] == 'rugged'
8
+
9
+ if RUBY_VERSION >= '2.0'
10
+ gem 'travis_check_rubies', '~> 0.2', '>= 0.2.3'
11
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2014 Ivan Kuchin
1
+ Copyright (c) 2012-2019 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,8 +1,8 @@
1
1
  [![Gem Version](https://img.shields.io/gem/v/git_dump.svg?style=flat)](https://rubygems.org/gems/git_dump)
2
2
  [![Build Status](https://img.shields.io/travis/toy/git_dump/master.svg?style=flat)](https://travis-ci.org/toy/git_dump)
3
- [![Code Climate](https://img.shields.io/codeclimate/github/toy/git_dump.svg?style=flat)](https://codeclimate.com/github/toy/git_dump)
4
- [![Dependency Status](https://img.shields.io/gemnasium/toy/git_dump.svg?style=flat)](https://gemnasium.com/toy/git_dump)
5
- [![Inch CI](http://inch-ci.org/github/toy/git_dump.svg?branch=master&style=flat)](http://inch-ci.org/github/toy/git_dump)
3
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/toy/git_dump.svg?style=flat)](https://codeclimate.com/github/toy/git_dump)
4
+ [![Depfu](https://badges.depfu.com/badges/d6fc5f97912d1efe42933171f333ff16/overview.svg)](https://depfu.com/github/toy/git_dump)
5
+ [![Inch CI](https://inch-ci.org/github/toy/git_dump.svg?branch=master&style=flat)](https://inch-ci.org/github/toy/git_dump)
6
6
 
7
7
  # git_dump
8
8
 
@@ -27,8 +27,8 @@ Create version:
27
27
  ```rb
28
28
  version = dump.new_version
29
29
  version['a/b/c'] = 'string'
30
- version.store('b/c/d', StringIO.new('string'), 0644)
31
- version.store('d/e', File.open('path'), 0755)
30
+ version.store('b/c/d', StringIO.new('string'), 0o644)
31
+ version.store('d/e', File.open('path'), 0o755)
32
32
  version.store_from('e/f', 'path')
33
33
  version.commit(:tags => 'test')
34
34
  ```
@@ -72,4 +72,4 @@ dump.fetch(url, ids.first)
72
72
 
73
73
  ## Copyright
74
74
 
75
- Copyright (c) 2012-2014 Ivan Kuchin. See LICENSE.txt for details.
75
+ Copyright (c) 2012-2019 Ivan Kuchin. See LICENSE.txt for details.
@@ -2,13 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'git_dump'
5
- s.version = '0.1.0'
5
+ s.version = '0.1.1'
6
6
  s.summary = %q{Distributed versioned store using git}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
9
9
  s.license = 'MIT'
10
10
 
11
- s.rubyforge_project = s.name
11
+ s.metadata = {
12
+ 'bug_tracker_uri' => "https://github.com/toy/#{s.name}/issues",
13
+ 'documentation_uri' => "https://www.rubydoc.info/gems/#{s.name}/#{s.version}",
14
+ 'source_code_uri' => "https://github.com/toy/#{s.name}",
15
+ }
12
16
 
13
17
  s.files = `git ls-files`.split("\n")
14
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -16,7 +20,7 @@ Gem::Specification.new do |s|
16
20
  s.require_paths = %w[lib]
17
21
 
18
22
  s.add_development_dependency 'rspec', '~> 3.0'
19
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9.3')
20
- s.add_development_dependency 'rubocop', '~> 0.27'
23
+ if RUBY_VERSION >= '2.1'
24
+ s.add_development_dependency 'rubocop', '~> 0.52'
21
25
  end
22
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/repo'
2
4
 
3
5
  require 'forwardable'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'shellwords'
2
4
  require 'English'
3
5
 
@@ -46,22 +48,23 @@ class GitDump
46
48
 
47
49
  # Construct command string
48
50
  def to_s
49
- cmd = args.shelljoin
51
+ parts = [args.shelljoin]
50
52
  if env
51
53
  env_str = env.map{ |k, v| "#{k}=#{v}" }.shelljoin
52
- cmd = "export #{env_str}; #{cmd}"
54
+ parts.unshift "export #{env_str};"
53
55
  end
54
- cmd = "cd #{chdir}; #{cmd}" if chdir
55
- cmd << ' < /dev/null' if no_stdin
56
- cmd << ' > /dev/null' if no_stdout
57
- cmd << ' 2> /dev/null' if no_stderr
58
- cmd
56
+ parts.unshift "cd #{chdir};" if chdir
57
+ parts.push '< /dev/null' if no_stdin
58
+ parts.push '> /dev/null' if no_stdout
59
+ parts.push '2> /dev/null' if no_stderr
60
+ parts.join(' ')
59
61
  end
60
62
 
61
63
  # Run using system
62
64
  def run
63
65
  success = system(*arguments)
64
66
  return true if success
67
+
65
68
  fail Failure, "`#{self}` failed with #{$CHILD_STATUS.exitstatus}"
66
69
  end
67
70
 
@@ -70,12 +73,24 @@ class GitDump
70
73
  if block
71
74
  result = IO.popen(arguments, mode, &block)
72
75
  return result if $CHILD_STATUS.success?
76
+
73
77
  fail Failure, "`#{self}` failed with #{$CHILD_STATUS.exitstatus}"
74
78
  else
75
79
  IO.popen(arguments, mode)
76
80
  end
77
81
  end
78
82
 
83
+ # Write input to pipe and return output
84
+ def pipe(input)
85
+ popen(input ? 'r+' : 'r') do |f|
86
+ if input
87
+ f.write input
88
+ f.close_write
89
+ end
90
+ f.read
91
+ end
92
+ end
93
+
79
94
  # Capture output
80
95
  def capture
81
96
  popen(&:read)
@@ -107,6 +122,7 @@ class GitDump
107
122
  # prepanded and options hash appended
108
123
  def arguments
109
124
  return to_s if RUBY_VERSION < '1.9' || defined?(JRUBY_VERSION)
125
+
110
126
  options = {}
111
127
  options[:chdir] = chdir if chdir
112
128
  options[:in] = '/dev/null' if no_stdin
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/path_object'
2
4
 
3
5
  class GitDump
@@ -6,7 +8,12 @@ class GitDump
6
8
  attr_reader :sha, :mode
7
9
  def initialize(repo, dir, name, sha, mode)
8
10
  super(repo, dir, name)
9
- @sha, @mode = sha, (mode & 0100) == 0 ? 0644 : 0755
11
+ @sha, @mode = sha, (mode & 0o100) == 0 ? 0o644 : 0o755
12
+ end
13
+
14
+ # Get size
15
+ def size
16
+ @size ||= repo.size(sha)
10
17
  end
11
18
 
12
19
  # Pipe for reading data
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class GitDump
2
4
  # Base class for Tree, Tree::Builder and Entry
3
5
  class PathObject
4
6
  attr_reader :repo, :path, :name
5
7
  def initialize(repo, dir, name)
8
+ fail ArgumentError, 'Expected Repo' unless repo.is_a?(Repo)
9
+
6
10
  @repo = repo
7
11
  @path = dir ? "#{dir}/#{name}" : name if name
8
12
  @name = name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'git_dump/repo/rugged'
3
5
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tempfile'
2
4
  require 'time'
3
5
 
@@ -17,11 +19,10 @@ class GitDump
17
19
  # List remote tag names
18
20
  def remote_tag_names(url)
19
21
  Cmd.git('ls-remote', '--tags', url).stripped_lines.map do |line|
20
- if (m = %r!^[0-9a-f]{40}\trefs/tags/(.*)$!.match(line))
21
- m[1]
22
- else
23
- fail "Unexpected: #{line}"
24
- end
22
+ m = %r!^[0-9a-f]{40}\trefs/tags/(.*)$!.match(line)
23
+ fail "Unexpected: #{line}" unless m
24
+
25
+ m[1]
25
26
  end
26
27
  end
27
28
  end
@@ -29,7 +30,7 @@ class GitDump
29
30
  # Add blob for content to repository, return sha
30
31
  def data_sha(content)
31
32
  @data_sha_command ||= git(*%w[hash-object -w --no-filters --stdin])
32
- @data_sha_command.popen('r+') do |f|
33
+ @data_sha_command.popen('rb+') do |f|
33
34
  if content.respond_to?(:read)
34
35
  f.write(content.read(4096)) until content.eof?
35
36
  else
@@ -82,13 +83,7 @@ class GitDump
82
83
  args << '-F' << '-' if options[:message]
83
84
  args << tree_sha << {:env => env, :no_stdin => !options[:message]}
84
85
 
85
- git(*args).popen(options[:message] ? 'r+' : 'r') do |f|
86
- if options[:message]
87
- f.write options[:message]
88
- f.close_write
89
- end
90
- f.read.chomp
91
- end
86
+ git(*args).pipe(options[:message]).chomp
92
87
  end
93
88
 
94
89
  # Create tag for commit_sha with name constructed from name_parts, return
@@ -109,17 +104,18 @@ class GitDump
109
104
  args << '-F' << '-' << '--cleanup=verbatim' if options[:message]
110
105
  args << name << commit_sha << {:env => env}
111
106
 
112
- git(*args).popen(options[:message] ? 'r+' : 'r') do |f|
113
- if options[:message]
114
- f.write options[:message]
115
- f.close_write
116
- end
117
- f.read.chomp
118
- end
107
+ git(*args).pipe(options[:message])
119
108
 
120
109
  name
121
110
  end
122
111
 
112
+ # Return size of object identified by sha
113
+ def size(sha)
114
+ @size_pipe ||= git(*%w[cat-file --batch-check]).popen('r+')
115
+ @size_pipe.puts(sha)
116
+ @size_pipe.gets.split(' ')[2].to_i
117
+ end
118
+
123
119
  # Return pipe with contents of blob identified by sha
124
120
  def blob_pipe(sha, &block)
125
121
  git('cat-file', 'blob', sha).popen('rb', &block)
@@ -161,16 +157,15 @@ class GitDump
161
157
  # Each entry is a hash like one for treeify
162
158
  def tree_entries(sha)
163
159
  git('ls-tree', sha).stripped_lines.map do |line|
164
- if (m = /^(\d{6}) (blob|tree) ([0-9a-f]{40})\t(.*)$/.match(line))
165
- {
166
- :mode => m[1].to_i(8),
167
- :type => m[2].to_sym,
168
- :sha => m[3],
169
- :name => m[4],
170
- }
171
- else
172
- fail "Unexpected: #{line}"
173
- end
160
+ m = /^(\d{6}) (blob|tree) ([0-9a-f]{40})\t(.*)$/.match(line)
161
+ fail "Unexpected: #{line}" unless m
162
+
163
+ {
164
+ :mode => m[1].to_i(8),
165
+ :type => m[2].to_sym,
166
+ :sha => m[3],
167
+ :name => m[4],
168
+ }
174
169
  end
175
170
  end
176
171
 
@@ -182,7 +177,7 @@ class GitDump
182
177
  %(committerdate:rfc2822)%(*committerdate:rfc2822)%00
183
178
  %(contents)%00
184
179
  %(*contents)%00
185
- ]
180
+ ].freeze
186
181
 
187
182
  # Return list of entries per tag ref
188
183
  # Each entry is a hash with following keys:
@@ -239,11 +234,12 @@ class GitDump
239
234
 
240
235
  def git_env(options)
241
236
  env = {}
242
- [:author, :committer].each do |role|
243
- [:name, :email, :date].each do |part|
237
+ %w[author committer].each do |role|
238
+ %w[name email date].each do |part|
244
239
  value = options[:"#{role}_#{part}"]
245
240
  next unless value
246
- value = value.strftime('%s %z') if part == :date
241
+
242
+ value = value.strftime('%s %z') if part == 'date'
247
243
  env["GIT_#{role}_#{part}".upcase] = value
248
244
  end
249
245
  end
@@ -260,7 +256,7 @@ class GitDump
260
256
  out[:mode] = if out[:type] == :tree
261
257
  0o040_000
262
258
  else
263
- (entry[:mode] & 0100) == 0 ? 0o100_644 : 0o100_755
259
+ (entry[:mode] & 0o100) == 0 ? 0o100_644 : 0o100_755
264
260
  end
265
261
 
266
262
  unless out[:sha] =~ /\A[0-9a-f]{40}\z/
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rugged'
2
4
  require 'git_dump/repo/git'
3
5
 
@@ -32,7 +34,7 @@ class GitDump
32
34
  # :sha => sha of content
33
35
  # :mode => last three octets of mode
34
36
  def treeify(entries)
35
- builder = ::Rugged::Tree::Builder.new
37
+ builder = ::Rugged::Tree::Builder.new(repo)
36
38
  entries.map do |entry|
37
39
  entry = normalize_entry(entry)
38
40
  builder << {
@@ -42,7 +44,12 @@ class GitDump
42
44
  :filemode => entry[:mode],
43
45
  }
44
46
  end
45
- builder.write(repo)
47
+ builder.write
48
+ end
49
+
50
+ # Return size of object identified by sha
51
+ def size(sha)
52
+ ::Rugged::Object.new(repo, sha).size
46
53
  end
47
54
 
48
55
  # Return contents of blob identified by sha
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/path_object'
2
4
  require 'git_dump/tree/base'
3
5
  require 'git_dump/entry'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/path_object'
2
4
  require 'git_dump/entry'
3
5
 
@@ -14,7 +16,8 @@ class GitDump
14
16
  # block given
15
17
  def each(&block)
16
18
  return to_enum(:each) unless block
17
- @entries.each do |_, entry|
19
+
20
+ @entries.each_value do |entry|
18
21
  block[entry]
19
22
  end
20
23
  end
@@ -23,7 +26,8 @@ class GitDump
23
26
  # given
24
27
  def each_recursive(&block)
25
28
  return to_enum(:each_recursive) unless block
26
- @entries.each do |_, entry|
29
+
30
+ @entries.each_value do |entry|
27
31
  if entry.is_a?(Entry)
28
32
  block[entry]
29
33
  else
@@ -36,6 +40,7 @@ class GitDump
36
40
 
37
41
  def get_at(parts)
38
42
  return unless (entry = @entries[parts.first])
43
+
39
44
  if parts.length == 1
40
45
  entry
41
46
  elsif entry.is_a?(self.class)
@@ -47,7 +52,7 @@ class GitDump
47
52
 
48
53
  def parse_path(path)
49
54
  path = Array(path).join('/') unless path.is_a?(String)
50
- path.scan(/[^\/]+/)
55
+ path.scan(%r{[^/]+})
51
56
  end
52
57
  end
53
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/path_object'
2
4
  require 'git_dump/entry'
3
5
 
@@ -14,7 +16,7 @@ class GitDump
14
16
 
15
17
  # Store data `content` with mode `mode` at `path`
16
18
  # Pass `nil` as content to remove
17
- def store(path, content, mode = 0644)
19
+ def store(path, content, mode = 0o644)
18
20
  put_at(parse_path(path), content && repo.data_sha(content), mode)
19
21
  end
20
22
  alias_method :[]=, :store
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/version/base'
2
4
  require 'git_dump/tree'
3
5
 
@@ -24,6 +26,8 @@ class GitDump
24
26
  attr_reader :repo, :id, :sha, :time
25
27
  attr_reader :commit_time, :annotation, :description
26
28
  def initialize(repo, id, sha, attributes = {})
29
+ fail ArgumentError, 'Expected Repo' unless repo.is_a?(Repo)
30
+
27
31
  @repo, @id, @sha = repo, id, sha
28
32
  @time = attributes[:time]
29
33
  @commit_time = attributes[:commit_time]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class GitDump
2
4
  class Version
3
5
  # Common methods in Version and Builder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_dump/version'
2
4
  require 'git_dump/version/base'
3
5
  require 'git_dump/tree/builder'
@@ -10,13 +12,15 @@ class GitDump
10
12
 
11
13
  attr_reader :repo
12
14
  def initialize(repo)
15
+ fail ArgumentError, 'Expected Repo' unless repo.is_a?(Repo)
16
+
13
17
  @repo = repo
14
18
  @tree = Tree::Builder.new(repo, nil, nil)
15
19
  end
16
20
 
17
21
  # Store data `content` with mode `mode` at `path`
18
22
  # Pass `nil` as content to remove
19
- def store(path, content, mode = 0644)
23
+ def store(path, content, mode = 0o644)
20
24
  tree.store(path, content, mode)
21
25
  end
22
26
  alias_method :[]=, :store
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
+ # frozen_string_literal: true
3
4
 
4
5
  require 'rubygems'
5
6
  require 'bundler/setup'
@@ -8,7 +9,7 @@ require 'git_dump'
8
9
  require 'benchmark'
9
10
  require 'tmpdir'
10
11
 
11
- def measure(label, number = nil, &block)
12
+ def measure(label, number = nil)
12
13
  label = "#{label} x#{number}" if number
13
14
  label = "#{label}:"
14
15
 
@@ -16,7 +17,7 @@ def measure(label, number = nil, &block)
16
17
  print label.ljust(30)
17
18
  times = Benchmark.measure do
18
19
  (number || 1).times do |n|
19
- result = block.call(n)
20
+ result = yield n
20
21
  end
21
22
  end
22
23
  puts " #{times}"
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'spec_helper'
2
5
  require 'git_dump'
3
6
  require 'tmpdir'
@@ -14,7 +17,7 @@ describe GitDump do
14
17
  DATAS = {
15
18
  :text => "\r\n\r\nline\nline\rline\r\nline\n\rline\r\n\r\n",
16
19
  :binary => 256.times.sort_by{ rand }.pack('C*'),
17
- }
20
+ }.freeze
18
21
 
19
22
  describe :new do
20
23
  let(:path){ File.join(tmp_dir, 'dump') }
@@ -156,8 +159,8 @@ describe GitDump do
156
159
  it 'creates and reads version' do
157
160
  builder = dump.new_version
158
161
  builder['string/x'] = 'test a'
159
- builder.store('stringio/x', StringIO.new('test b'), 0644)
160
- builder.store('io/x', File.open(__FILE__), 0755)
162
+ builder.store('stringio/x', StringIO.new('test b'), 0o644)
163
+ builder.store('io/x', File.open(__FILE__), 0o755)
161
164
  builder.store_from('path/x', __FILE__)
162
165
  built = builder.commit
163
166
 
@@ -171,8 +174,8 @@ describe GitDump do
171
174
 
172
175
  expect(version['string/x'].read).to eq('test a')
173
176
  expect(version['stringio/x'].read).to eq('test b')
174
- expect(version['io/x'].read).to eq(File.read(__FILE__))
175
- expect(version['path/x'].read).to eq(File.read(__FILE__))
177
+ expect(version['io/x'].read).to eq(File.open(__FILE__, 'rb', &:read))
178
+ expect(version['path/x'].read).to eq(File.open(__FILE__, 'rb', &:read))
176
179
  expect(version['should/not/be/there']).to be_nil
177
180
  end
178
181
 
@@ -202,6 +205,23 @@ describe GitDump do
202
205
  end
203
206
  end
204
207
 
208
+ it 'returns size for entries' do
209
+ datas = [
210
+ '',
211
+ '1',
212
+ '᚛᚛ᚉᚑᚅᚔᚉᚉᚔᚋ ᚔᚈᚔ ᚍᚂᚐᚅᚑ ᚅᚔᚋᚌᚓᚅᚐ᚜',
213
+ ] + DATAS.values
214
+
215
+ builder = dump.new_version
216
+ datas.each_with_index do |data, i|
217
+ builder["a/path/#{i}"] = data
218
+ end
219
+
220
+ datas.each_with_index do |data, i|
221
+ expect(builder["a/path/#{i}"].size).to eq(data.bytesize)
222
+ end
223
+ end
224
+
205
225
  it 'cleans paths' do
206
226
  builder = dump.new_version
207
227
  builder['//aa//fa//'] = 'test a'
@@ -272,8 +292,8 @@ describe GitDump do
272
292
  builder
273
293
  end
274
294
 
275
- def recursive_path_n_read(o)
276
- o.each_recursive.map do |entry|
295
+ def recursive_path_n_read(obj)
296
+ obj.each_recursive.map do |entry|
277
297
  [entry.path, entry.read]
278
298
  end
279
299
  end
@@ -324,7 +344,7 @@ describe GitDump do
324
344
  end
325
345
  end
326
346
 
327
- [0644, 0755].each do |mode|
347
+ [0o644, 0o755].each do |mode|
328
348
  it "sets mode to #{mode.to_s(8)}" do
329
349
  builder = dump.new_version
330
350
  builder.store('a', 'test', mode)
@@ -332,17 +352,17 @@ describe GitDump do
332
352
  path = File.join(tmp_dir, 'file')
333
353
  builder['a'].write_to(path)
334
354
 
335
- expect(File.stat(path).mode & 0777).to eq(mode)
355
+ expect(File.stat(path).mode & 0o777).to eq(mode)
336
356
  end
337
357
 
338
358
  it "fixes mode to #{mode.to_s(8)}" do
339
359
  builder = dump.new_version
340
- builder.store('a', 'test', mode & 0100)
360
+ builder.store('a', 'test', mode & 0o100)
341
361
 
342
362
  path = File.join(tmp_dir, 'file')
343
363
  builder['a'].write_to(path)
344
364
 
345
- expect(File.stat(path).mode & 0777).to eq(mode)
365
+ expect(File.stat(path).mode & 0o777).to eq(mode)
346
366
  end
347
367
  end
348
368
  end
metadata CHANGED
@@ -1,52 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_dump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2019-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.27'
33
+ version: '0.52'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.27'
40
+ version: '0.52'
41
41
  description:
42
42
  email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - .gitignore
48
- - .rubocop.yml
49
- - .travis.yml
47
+ - ".gitignore"
48
+ - ".rubocop.yml"
49
+ - ".travis.yml"
50
+ - ".travis_check_rubies.yml"
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.markdown
@@ -70,28 +71,29 @@ files:
70
71
  homepage: http://github.com/toy/git_dump
71
72
  licenses:
72
73
  - MIT
73
- metadata: {}
74
+ metadata:
75
+ bug_tracker_uri: https://github.com/toy/git_dump/issues
76
+ documentation_uri: https://www.rubydoc.info/gems/git_dump/0.1.1
77
+ source_code_uri: https://github.com/toy/git_dump
74
78
  post_install_message:
75
79
  rdoc_options: []
76
80
  require_paths:
77
81
  - lib
78
82
  required_ruby_version: !ruby/object:Gem::Requirement
79
83
  requirements:
80
- - - ! '>='
84
+ - - ">="
81
85
  - !ruby/object:Gem::Version
82
86
  version: '0'
83
87
  required_rubygems_version: !ruby/object:Gem::Requirement
84
88
  requirements:
85
- - - ! '>='
89
+ - - ">="
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0'
88
92
  requirements: []
89
- rubyforge_project: git_dump
90
- rubygems_version: 2.4.4
93
+ rubygems_version: 3.0.3
91
94
  signing_key:
92
95
  specification_version: 4
93
96
  summary: Distributed versioned store using git
94
97
  test_files:
95
98
  - spec/git_dump_spec.rb
96
99
  - spec/spec_helper.rb
97
- has_rdoc: