git_ls 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 36a574370f3eb35ebc2809b74763a95b5e8ccfbcdeaa6a51c3e676b5c99169e1
4
+ data.tar.gz: 23edfa443ecf1ba37421b9722447d4222e9f243caa020649b08c89186b3b1b78
5
+ SHA512:
6
+ metadata.gz: 1ec5afd8473e7549d01de8aa9396ce1fd498d761dc494f9a25145cf0234b59448c44d736bf5463b5d4dffbebb40eca661dfad5c10ab9644e4a0d132fad8df8a9
7
+ data.tar.gz: 1cd05421d153e6a12357db5689daf22a5932bdd2a40a044d058acbb9f8f5425c7728b4c32b6422c6b3d3de6b732852f45034891c5d892aba068f12a29fd6acc9
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ /.rspec_status
12
+ /.ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,3 @@
1
+ # 0.1.0
2
+
3
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in git_index.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_index (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (12.3.3)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.2)
21
+ rspec-support (~> 3.9.3)
22
+ rspec-expectations (3.9.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (>= 2)
35
+ git_index!
36
+ pry (> 0)
37
+ rake (~> 12.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Dana Sherson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # GitLS.files
2
+
3
+ Parses the .git/index file like `git ls-files` does.
4
+
5
+ - for small repos (as in, anything smaller than rails),
6
+ it can be significantly faster than doing the system call to git
7
+ - still takes less than half a second for large repos e.g. the linux repo
8
+ - doesn't require git to be installed
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'git_ls'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install git_ls
25
+
26
+ ## Usage
27
+
28
+ `GitLS.files` returns an array of filenames, equivalent to `` `git ls-files -z`.split("\0") ``
29
+ `GitLS.files("path/to/repo")` if the repo is not $PWD.
30
+
31
+ ## Issues
32
+
33
+ - Doesn't work for git version 4 files at all
34
+ - Doesn't understand split index files at all
35
+ - Has only 1 test
36
+
37
+ ## Development
38
+
39
+ Have a look in the bin dir for some useful tools.
40
+ To install this gem onto your local machine, run `bundle exec rake install`.
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/robotdana/git_ls.
45
+ If you're comfortable, please attach `.git/index` and the output of `git ls-files` where it doesn't match.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+ # git_ls
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/git_ls/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'git_ls'
7
+ spec.version = GitLS::VERSION
8
+ spec.authors = ['Dana Sherson']
9
+ spec.email = ['robot@dana.sh']
10
+
11
+ spec.summary = 'Read a .git/index file and list the files'
12
+ spec.homepage = 'https://github.com/robotdana/git_ls'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = spec.homepage + '/blob/main/CHANGELOG.md'
20
+ end
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(bin|test|spec|features)/}) }
26
+ end
27
+
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '>= 2'
31
+ spec.add_development_dependency 'pry', '> 0'
32
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'git_ls/parser'
4
+
5
+ # Entry point for gem.
6
+ # Usage:
7
+ # GitLS.files -> Array of strings as files.
8
+ # This will be identical output to git ls-files
9
+ module GitLS
10
+ class Error < StandardError; end
11
+
12
+ class << self
13
+ def files(path = ::Dir.pwd)
14
+ path = ::File.join(path, '.git/index') if ::File.directory?(path)
15
+ ::GitLS::Parser.new(::File.new(path)).files
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitLS
4
+ # Parse a .git/index file
5
+ # Format documented here: https://git-scm.com/docs/index-format
6
+ class Parser
7
+ HEADER = 'A4' + # 4-byte signature:
8
+ # The signature is { 'D', 'I', 'R', 'C' } (stands for "dircache")
9
+ 'N' + # 4-byte version number:
10
+ # The current supported versions are 2, 3 and 4.
11
+ 'N' # 32-bit number of index entries.
12
+
13
+ def initialize(file)
14
+ @file = file
15
+ raise ::GitLS::Error, 'not a git dir or .git/index file' unless valid?
16
+ end
17
+
18
+ def files
19
+ headers
20
+
21
+ @files = Array.new(length)
22
+ case git_version
23
+ when 2 then files_2
24
+ when 3 then files_3
25
+ when 4 then raise ::GitLS::Error, "4 is complicated git version, it's not done yet"
26
+ else raise ::GitLS::Error, 'Unrecognized git version'
27
+ end
28
+ @files
29
+ end
30
+
31
+ private
32
+
33
+ def files_2
34
+ @files.map! do
35
+ @file.pos += 62 # skip 62 bytes (40 bytes of stat, 20 bytes of sha, 2 bytes flags)
36
+ ret = @file.readline("\0").chop
37
+ @file.pos += 7 - ((ret.bytesize - 2) % 8) # 1-8 bytes padding of nuls
38
+ ret
39
+ end
40
+ end
41
+
42
+ def files_3
43
+ @files.map! do
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?
48
+
49
+ ret = @file.readline("\0").chop
50
+ @file.pos += 7 - ((ret.bytesize - 2) % 8) # 1-8 bytes padding of nuls
51
+ ret
52
+ end
53
+ end
54
+
55
+ def headers
56
+ @headers ||= @file.read(12).unpack(::GitLS::Parser::HEADER)
57
+ end
58
+
59
+ def valid?
60
+ headers[0] == 'DIRC'
61
+ end
62
+
63
+ def git_version
64
+ @git_version = headers[1]
65
+ end
66
+
67
+ def length
68
+ headers[2]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitLS
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_ls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dana Sherson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - robot@dana.sh
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - CHANGELOG.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - git_index.gemspec
58
+ - lib/git_ls.rb
59
+ - lib/git_ls/parser.rb
60
+ - lib/git_ls/version.rb
61
+ homepage: https://github.com/robotdana/git_ls
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://github.com/robotdana/git_ls
66
+ source_code_uri: https://github.com/robotdana/git_ls
67
+ changelog_uri: https://github.com/robotdana/git_ls/blob/main/CHANGELOG.md
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.4.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.1.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Read a .git/index file and list the files
87
+ test_files: []