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 +4 -4
- data/.simplecov +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +8 -2
- data/README.md +0 -2
- data/git_index.gemspec +1 -0
- data/lib/git_ls.rb +2 -0
- data/lib/git_ls/parser.rb +49 -7
- data/lib/git_ls/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b3b64d9243806400218962b09edcb66818cb89e937d26891cb166abcab21758
|
4
|
+
data.tar.gz: 35635cc661eeed4da50a7552a9843a5c65f9502d54e7970d1a4d704e9409ee6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee0a4c6e09c94eb10a50f98035cca54ebaf7c5c5d581e2777e8f3db48e713864277f2478b297e0b6aac105af5f1dbb465f4f576fbcbbb3be5fb7d8d7158898ce
|
7
|
+
data.tar.gz: de60f8686d502bd616997b123089707e39e9c234faaf523b8df8037476013fa83f4114ee7ecb6a9a02c485d69b8e93c593dc8e9ae925aaeebe718e09a7316a9e
|
data/.simplecov
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
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
|
-
|
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
data/git_index.gemspec
CHANGED
data/lib/git_ls.rb
CHANGED
@@ -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
|
data/lib/git_ls/parser.rb
CHANGED
@@ -19,10 +19,10 @@ module GitLS
|
|
19
19
|
headers
|
20
20
|
|
21
21
|
@files = Array.new(length)
|
22
|
-
case
|
22
|
+
case git_index_version
|
23
23
|
when 2 then files_2
|
24
24
|
when 3 then files_3
|
25
|
-
when 4 then
|
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
|
-
|
46
|
-
|
47
|
-
|
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 -
|
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
|
105
|
+
def git_index_version
|
64
106
|
@git_version = headers[1]
|
65
107
|
end
|
66
108
|
|
data/lib/git_ls/version.rb
CHANGED
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.
|
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-
|
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
|