git_ls 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36a574370f3eb35ebc2809b74763a95b5e8ccfbcdeaa6a51c3e676b5c99169e1
4
- data.tar.gz: 23edfa443ecf1ba37421b9722447d4222e9f243caa020649b08c89186b3b1b78
3
+ metadata.gz: 3b3b64d9243806400218962b09edcb66818cb89e937d26891cb166abcab21758
4
+ data.tar.gz: 35635cc661eeed4da50a7552a9843a5c65f9502d54e7970d1a4d704e9409ee6e
5
5
  SHA512:
6
- metadata.gz: 1ec5afd8473e7549d01de8aa9396ce1fd498d761dc494f9a25145cf0234b59448c44d736bf5463b5d4dffbebb40eca661dfad5c10ab9644e4a0d132fad8df8a9
7
- data.tar.gz: 1cd05421d153e6a12357db5689daf22a5932bdd2a40a044d058acbb9f8f5425c7728b4c32b6422c6b3d3de6b732852f45034891c5d892aba068f12a29fd6acc9
6
+ metadata.gz: ee0a4c6e09c94eb10a50f98035cca54ebaf7c5c5d581e2777e8f3db48e713864277f2478b297e0b6aac105af5f1dbb465f4f576fbcbbb3be5fb7d8d7158898ce
7
+ data.tar.gz: de60f8686d502bd616997b123089707e39e9c234faaf523b8df8037476013fa83f4114ee7ecb6a9a02c485d69b8e93c593dc8e9ae925aaeebe718e09a7316a9e
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5')
6
+ enable_coverage(:branch)
7
+ minimum_coverage line: 100, branch: 100
8
+ else
9
+ minimum_coverage 100
10
+ end
11
+ end
@@ -1,3 +1,8 @@
1
+ # 0.2.0
2
+
3
+ - Handles git index version 4
4
+ - Handles git index version 3 with extended flags properly
5
+
1
6
  # 0.1.0
2
7
 
3
8
  Initial release
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_index (0.1.0)
4
+ git_ls (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  coderay (1.1.3)
10
10
  diff-lcs (1.4.4)
11
+ docile (1.3.2)
11
12
  method_source (1.0.0)
12
13
  pry (0.13.1)
13
14
  coderay (~> 1.1)
@@ -26,16 +27,21 @@ GEM
26
27
  diff-lcs (>= 1.2.0, < 2.0)
27
28
  rspec-support (~> 3.9.0)
28
29
  rspec-support (3.9.3)
30
+ simplecov (0.18.5)
31
+ docile (~> 1.1)
32
+ simplecov-html (~> 0.11)
33
+ simplecov-html (0.12.2)
29
34
 
30
35
  PLATFORMS
31
36
  ruby
32
37
 
33
38
  DEPENDENCIES
34
39
  bundler (>= 2)
35
- git_index!
40
+ git_ls!
36
41
  pry (> 0)
37
42
  rake (~> 12.0)
38
43
  rspec (~> 3.0)
44
+ simplecov (~> 0.18.5)
39
45
 
40
46
  BUNDLED WITH
41
47
  2.1.4
data/README.md CHANGED
@@ -30,9 +30,7 @@ Or install it yourself as:
30
30
 
31
31
  ## Issues
32
32
 
33
- - Doesn't work for git version 4 files at all
34
33
  - Doesn't understand split index files at all
35
- - Has only 1 test
36
34
 
37
35
  ## Development
38
36
 
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency 'bundler', '>= 2'
31
31
  spec.add_development_dependency 'pry', '> 0'
32
+ spec.add_development_dependency 'simplecov', '~> 0.18.5'
32
33
  end
@@ -13,6 +13,8 @@ module GitLS
13
13
  def files(path = ::Dir.pwd)
14
14
  path = ::File.join(path, '.git/index') if ::File.directory?(path)
15
15
  ::GitLS::Parser.new(::File.new(path)).files
16
+ rescue Errno::ENOENT => e
17
+ raise GitLS::Error, "Not a git directory: #{e.message}"
16
18
  end
17
19
  end
18
20
  end
@@ -19,10 +19,10 @@ module GitLS
19
19
  headers
20
20
 
21
21
  @files = Array.new(length)
22
- case git_version
22
+ case git_index_version
23
23
  when 2 then files_2
24
24
  when 3 then files_3
25
- when 4 then raise ::GitLS::Error, "4 is complicated git version, it's not done yet"
25
+ when 4 then files_4
26
26
  else raise ::GitLS::Error, 'Unrecognized git version'
27
27
  end
28
28
  @files
@@ -42,16 +42,58 @@ module GitLS
42
42
  def files_3
43
43
  @files.map! do
44
44
  @file.pos += 60 # skip 60 bytes (40 bytes of stat, 20 bytes of sha)
45
- flags = @file.read(2) # 2 bytes flags
46
- # skip extend flags if extended flags bit set
47
- @file.pos += 2 if flags && (flags.unpack1('n') & 0b0100_0000_0000_0000).positive?
45
+ flag = @file.getbyte
46
+ extended_flag_offset = if (flag & 0b0100_0000).positive?
47
+ 3 # skip next half of flag + extended flags
48
+ else
49
+ 1 # skip next half of flag
50
+ end
51
+ @file.pos += extended_flag_offset
48
52
 
49
53
  ret = @file.readline("\0").chop
50
- @file.pos += 7 - ((ret.bytesize - 2) % 8) # 1-8 bytes padding of nuls
54
+ @file.pos += 7 - ((ret.bytesize + extended_flag_offset - 3) % 8) # 1-8 bytes padding of nuls
51
55
  ret
52
56
  end
53
57
  end
54
58
 
59
+ def files_4
60
+ prev_entry_path = ""
61
+ @files.map! do
62
+ @file.pos += 60 # skip 60 bytes (40 bytes of stat, 20 bytes of sha)
63
+ flag = @file.getbyte
64
+ @file.pos += if (flag & 0b0100_0000).positive?
65
+ 3 # skip next half of flag + extended flags
66
+ else
67
+ 1 # skip next half of flag
68
+ end
69
+
70
+ # flags = @file.read(2) # 2 bytes flags
71
+ # # skip extend flags if extended flags bit set
72
+ # @file.pos += 2 if flags && (flags.unpack1('n') & 0b0100_0000_0000_0000).positive?
73
+
74
+ # documentation for this number from
75
+ # https://git-scm.com/docs/pack-format#_original_version_1_pack_idx_files_have_the_following_format
76
+ # offset encoding:
77
+ # n bytes with MSB set in all but the last one.
78
+ # The offset is then the number constructed by
79
+ # concatenating the lower 7 bit of each byte, and
80
+ # for n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1))
81
+ # to the result.
82
+ read_offset = 0
83
+ prev_read_offset = @file.getbyte
84
+ n = 1
85
+ while (prev_read_offset & 0b1000_0000).positive?
86
+ read_offset += (prev_read_offset - 0b1000_0000)
87
+ read_offset += 2**(7 * n)
88
+ n += 1
89
+ prev_read_offset = @file.getbyte
90
+ end
91
+ read_offset += prev_read_offset
92
+
93
+ prev_entry_path = prev_entry_path.byteslice(0, prev_entry_path.bytesize - read_offset) + @file.readline("\0").chop
94
+ end
95
+ end
96
+
55
97
  def headers
56
98
  @headers ||= @file.read(12).unpack(::GitLS::Parser::HEADER)
57
99
  end
@@ -60,7 +102,7 @@ module GitLS
60
102
  headers[0] == 'DIRC'
61
103
  end
62
104
 
63
- def git_version
105
+ def git_index_version
64
106
  @git_version = headers[1]
65
107
  end
66
108
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitLS
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_ls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Sherson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-17 00:00:00.000000000 Z
11
+ date: 2020-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.18.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.18.5
41
55
  description:
42
56
  email:
43
57
  - robot@dana.sh
@@ -47,6 +61,7 @@ extra_rdoc_files: []
47
61
  files:
48
62
  - ".gitignore"
49
63
  - ".rspec"
64
+ - ".simplecov"
50
65
  - ".travis.yml"
51
66
  - CHANGELOG.md
52
67
  - Gemfile