github-linguist 4.6.0 → 4.6.3

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
  SHA1:
3
- metadata.gz: b1e908297a23747b75632757998f7e16e3daa923
4
- data.tar.gz: d4421c50a81f0360941bd3d92ffb76702edd7136
3
+ metadata.gz: f0a7e76588573f7975f1ed31cc621400170ebb21
4
+ data.tar.gz: f9529b2c29986e3493c3d5512c70c6aa3ddaa6c6
5
5
  SHA512:
6
- metadata.gz: 1603a43de2817ceff7a9512524a24010b5a649b7fb8236331677821152729f2f6fda13d00b6a3f787b6363f7a00d64bfbc12f9a7700880d838ed681b61fd7a67
7
- data.tar.gz: 38f1e50a2006ee6e5b29ec073ed4741a4638c4ee806656fa17654b77bde270b6eaa1e65bae8cfdd82bbc20539f9604f389fdd0efcc65e853c00015a752defb5c
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 || rugged.head.target_id
13
+ @commit_oid = commit_oid
18
14
  @incremental = incremental
19
15
  end
20
16
 
21
17
  def linguist
22
- repo = Linguist::Repository.new(rugged, commit_oid)
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, commit_oid, stats = load_cache
42
- if version == LANGUAGE_STATS_CACHE_VERSION && commit_oid && stats
43
- [commit_oid, stats]
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(commit_oid, stats)
48
- cache = [LANGUAGE_STATS_CACHE_VERSION, commit_oid, stats]
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
- tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
76
-
77
- File.open(tmp_path, "wb") do |f|
78
- marshal = Marshal.dump(object)
79
- f.write(Zlib::Deflate.deflate(marshal))
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 ||= begin
113
- pwd = Dir.pwd
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
@@ -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
@@ -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
- old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
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
@@ -1,3 +1,3 @@
1
1
  module Linguist
2
- VERSION = "4.6.0"
2
+ VERSION = "4.6.3"
3
3
  end
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.0
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-15 00:00:00.000000000 Z
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