github-linguist 4.6.0 → 4.6.3
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 +4 -4
- data/LICENSE +22 -0
- data/bin/git-linguist +29 -33
- data/lib/linguist/languages.yml +2 -1
- data/lib/linguist/repository.rb +3 -2
- data/lib/linguist/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0a7e76588573f7975f1ed31cc621400170ebb21
|
4
|
+
data.tar.gz: f9529b2c29986e3493c3d5512c70c6aa3ddaa6c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b3bfae66561aca83ffd529619c36a7100b035f5d840d4a4d15e0e5ce2aa7afca93bbf26db42bec8117581401b48724cc3a0f009df2790e13ebb9db65052f998
|
7
|
+
data.tar.gz: dae8a3ed00c63957a34c3b0106409f863e9ee029ede1e000f54a49446d645f81b76dfa312312adeb7c71be81ee387e0e6a12af02294f84ea56927a1ff8ef4704
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011-2015 GitHub, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/git-linguist
CHANGED
@@ -8,20 +8,19 @@ require 'tmpdir'
|
|
8
8
|
require 'zlib'
|
9
9
|
|
10
10
|
class GitLinguist
|
11
|
-
attr_reader :repo_path
|
12
|
-
attr_reader :commit_oid
|
13
|
-
attr_reader :incremental
|
14
|
-
|
15
11
|
def initialize(path, commit_oid, incremental = true)
|
16
12
|
@repo_path = path
|
17
|
-
@commit_oid = commit_oid
|
13
|
+
@commit_oid = commit_oid
|
18
14
|
@incremental = incremental
|
19
15
|
end
|
20
16
|
|
21
17
|
def linguist
|
22
|
-
|
18
|
+
if @commit_oid.nil?
|
19
|
+
raise "git-linguist must be called with a specific commit OID to perform language computation"
|
20
|
+
end
|
21
|
+
repo = Linguist::Repository.new(rugged, @commit_oid)
|
23
22
|
|
24
|
-
if incremental && stats = load_language_stats
|
23
|
+
if @incremental && stats = load_language_stats
|
25
24
|
old_commit_oid, old_stats = stats
|
26
25
|
|
27
26
|
# A cache with NULL oid means that we want to froze
|
@@ -33,19 +32,19 @@ class GitLinguist
|
|
33
32
|
|
34
33
|
result = yield repo
|
35
34
|
|
36
|
-
save_language_stats(commit_oid, repo.cache)
|
35
|
+
save_language_stats(@commit_oid, repo.cache)
|
37
36
|
result
|
38
37
|
end
|
39
38
|
|
40
39
|
def load_language_stats
|
41
|
-
version,
|
42
|
-
if version == LANGUAGE_STATS_CACHE_VERSION &&
|
43
|
-
[
|
40
|
+
version, oid, stats = load_cache
|
41
|
+
if version == LANGUAGE_STATS_CACHE_VERSION && oid && stats
|
42
|
+
[oid, stats]
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
def save_language_stats(
|
48
|
-
cache = [LANGUAGE_STATS_CACHE_VERSION,
|
46
|
+
def save_language_stats(oid, stats)
|
47
|
+
cache = [LANGUAGE_STATS_CACHE_VERSION, oid, stats]
|
49
48
|
write_cache(cache)
|
50
49
|
end
|
51
50
|
|
@@ -64,25 +63,28 @@ class GitLinguist
|
|
64
63
|
LANGUAGE_STATS_CACHE_VERSION = "v3:#{Linguist::VERSION}"
|
65
64
|
|
66
65
|
def rugged
|
67
|
-
@rugged ||= Rugged::Repository.bare(repo_path)
|
66
|
+
@rugged ||= Rugged::Repository.bare(@repo_path)
|
68
67
|
end
|
69
68
|
|
70
69
|
def cache_file
|
71
|
-
File.join(repo_path, LANGUAGE_STATS_CACHE)
|
70
|
+
File.join(@repo_path, LANGUAGE_STATS_CACHE)
|
72
71
|
end
|
73
72
|
|
74
73
|
def write_cache(object)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
return unless File.directory? @repo_path
|
75
|
+
|
76
|
+
begin
|
77
|
+
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
|
78
|
+
File.open(tmp_path, "wb") do |f|
|
79
|
+
marshal = Marshal.dump(object)
|
80
|
+
f.write(Zlib::Deflate.deflate(marshal))
|
81
|
+
end
|
82
|
+
|
83
|
+
File.rename(tmp_path, cache_file)
|
84
|
+
rescue => e
|
85
|
+
(File.unlink(tmp_path) rescue nil)
|
86
|
+
raise e
|
80
87
|
end
|
81
|
-
|
82
|
-
File.rename(tmp_path, cache_file)
|
83
|
-
tmp_path = nil
|
84
|
-
ensure
|
85
|
-
(File.unlink(tmp_path) rescue nil) if tmp_path
|
86
88
|
end
|
87
89
|
|
88
90
|
def load_cache
|
@@ -97,24 +99,18 @@ end
|
|
97
99
|
def git_linguist(args)
|
98
100
|
incremental = true
|
99
101
|
commit = nil
|
100
|
-
git_dir = nil
|
101
102
|
|
102
103
|
parser = OptionParser.new do |opts|
|
103
104
|
opts.banner = "Usage: git-linguist [OPTIONS] stats|breakdown|dump-cache|clear|disable"
|
104
105
|
|
105
106
|
opts.on("-f", "--force", "Force a full rescan") { incremental = false }
|
106
|
-
opts.on("--git-dir=DIR", "Path to the git repository") { |v| git_dir = v }
|
107
107
|
opts.on("--commit=COMMIT", "Commit to index") { |v| commit = v}
|
108
108
|
end
|
109
109
|
|
110
110
|
parser.parse!(args)
|
111
111
|
|
112
|
-
git_dir
|
113
|
-
|
114
|
-
dotgit = File.join(pwd, ".git")
|
115
|
-
File.directory?(dotgit) ? dotgit : pwd
|
116
|
-
end
|
117
|
-
|
112
|
+
git_dir = `git rev-parse --git-dir`.strip
|
113
|
+
raise "git-linguist must be ran in a Git repository" unless $?.success?
|
118
114
|
wrapper = GitLinguist.new(git_dir, commit, incremental)
|
119
115
|
|
120
116
|
case args.pop
|
data/lib/linguist/languages.yml
CHANGED
@@ -8,7 +8,8 @@
|
|
8
8
|
# Use "text" if a mode does not exist.
|
9
9
|
# wrap - Boolean wrap to enable line wrapping (default: false)
|
10
10
|
# extensions - An Array of associated extensions (the first one is
|
11
|
-
# considered the primary extension
|
11
|
+
# considered the primary extension, the others should be
|
12
|
+
# listed alphabetically)
|
12
13
|
# interpreters - An Array of associated interpreters
|
13
14
|
# searchable - Boolean flag to enable searching (defaults to true)
|
14
15
|
# search_term - Deprecated: Some languages maybe indexed under a
|
data/lib/linguist/repository.rb
CHANGED
@@ -126,12 +126,13 @@ module Linguist
|
|
126
126
|
end
|
127
127
|
|
128
128
|
protected
|
129
|
+
MAX_TREE_SIZE = 100_000
|
129
130
|
|
130
131
|
def compute_stats(old_commit_oid, cache = nil)
|
131
|
-
|
132
|
+
return {} if current_tree.count_recursive(MAX_TREE_SIZE) >= MAX_TREE_SIZE
|
132
133
|
|
134
|
+
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
|
133
135
|
read_index
|
134
|
-
|
135
136
|
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
|
136
137
|
|
137
138
|
# Clear file map and fetch full diff if any .gitattributes files are changed
|
data/lib/linguist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-linguist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: charlock_holmes
|
@@ -174,6 +174,7 @@ executables:
|
|
174
174
|
extensions: []
|
175
175
|
extra_rdoc_files: []
|
176
176
|
files:
|
177
|
+
- LICENSE
|
177
178
|
- bin/git-linguist
|
178
179
|
- bin/linguist
|
179
180
|
- lib/linguist.rb
|