Compare commits

...

14 Commits

Author SHA1 Message Date
Vicent Marti
98b99e38bb Merge pull request #2654 from github/vmg/git-linguist-fixes
Small fixes for git-linguist
2015-09-28 11:12:49 +02:00
Vicent Marti
d8e3bec499 Bump version 2015-09-28 01:45:49 -07:00
Vicent Marti
7c759d4d29 git-linguist: Do not write cache if repo is gone 2015-09-28 01:45:49 -07:00
Vicent Marti
41d438b47e repository: Do not attempt to scan large repos 2015-09-28 01:45:49 -07:00
Vicent Marti
41911d6921 git-linguist: Properly handle $GIT_DIR from git 2015-09-28 01:45:49 -07:00
Arfon Smith
dca18d77cb Merge pull request #2656 from iblech/better-test-description
Clarified that only nonprimary extensions should be sorted
2015-09-27 20:34:30 +01:00
Ingo Blechschmidt
040af5dad2 Clarify that only nonprimary extensions should be sorted 2015-09-25 19:23:06 +02:00
Arfon Smith
4867c49bd9 Merge pull request #2642 from github/license-in-gemspec
Include LICENSE in gem
2015-09-23 09:19:18 +01:00
Brandon Keepers
a354eddf4b Update github-linguist.gemspec 2015-09-22 16:33:08 -04:00
Vicent Marti
9b78c533a5 Merge pull request #2641 from github/js-syntax-fix
github-linguist-grammars 4.6.2
2015-09-21 21:56:33 +02:00
Mislav Marohnić
090ea576b9 github-linguist-grammars 4.6.2 2015-09-21 21:23:40 +02:00
Mislav Marohnić
6a2d33a4b3 Bump language-javascript for syntax highlighting fix
This is primarily to pull
https://github.com/atom/language-javascript/pull/227

Full changelog:
c5c381e...7b14bbb (diff-46d5c1ca71eaebb92619d6c7abc9388d)
2015-09-21 19:04:30 +02:00
Vicent Marti
2c62da7834 Merge pull request #2636 from github/vmg/git-linguist-oid
git-linguist: Delay loading @commit_oid
2015-09-16 16:48:12 +02:00
Vicent Marti
0145a0adb2 git-linguist: Delay loading @commit_oid 2015-09-16 05:50:35 -07:00
7 changed files with 37 additions and 39 deletions

View File

@@ -8,20 +8,19 @@ require 'tmpdir'
require 'zlib'
class GitLinguist
attr_reader :repo_path
attr_reader :commit_oid
attr_reader :incremental
def initialize(path, commit_oid, incremental = true)
@repo_path = path
@commit_oid = commit_oid || rugged.head.target_id
@commit_oid = commit_oid
@incremental = incremental
end
def linguist
repo = Linguist::Repository.new(rugged, commit_oid)
if @commit_oid.nil?
raise "git-linguist must be called with a specific commit OID to perform language computation"
end
repo = Linguist::Repository.new(rugged, @commit_oid)
if incremental && stats = load_language_stats
if @incremental && stats = load_language_stats
old_commit_oid, old_stats = stats
# A cache with NULL oid means that we want to froze
@@ -33,19 +32,19 @@ class GitLinguist
result = yield repo
save_language_stats(commit_oid, repo.cache)
save_language_stats(@commit_oid, repo.cache)
result
end
def load_language_stats
version, commit_oid, stats = load_cache
if version == LANGUAGE_STATS_CACHE_VERSION && commit_oid && stats
[commit_oid, stats]
version, oid, stats = load_cache
if version == LANGUAGE_STATS_CACHE_VERSION && oid && stats
[oid, stats]
end
end
def save_language_stats(commit_oid, stats)
cache = [LANGUAGE_STATS_CACHE_VERSION, commit_oid, stats]
def save_language_stats(oid, stats)
cache = [LANGUAGE_STATS_CACHE_VERSION, oid, stats]
write_cache(cache)
end
@@ -64,25 +63,28 @@ class GitLinguist
LANGUAGE_STATS_CACHE_VERSION = "v3:#{Linguist::VERSION}"
def rugged
@rugged ||= Rugged::Repository.bare(repo_path)
@rugged ||= Rugged::Repository.bare(@repo_path)
end
def cache_file
File.join(repo_path, LANGUAGE_STATS_CACHE)
File.join(@repo_path, LANGUAGE_STATS_CACHE)
end
def write_cache(object)
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
return unless File.directory? @repo_path
begin
tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil)
File.open(tmp_path, "wb") do |f|
marshal = Marshal.dump(object)
f.write(Zlib::Deflate.deflate(marshal))
end
File.rename(tmp_path, cache_file)
tmp_path = nil
ensure
(File.unlink(tmp_path) rescue nil) if tmp_path
rescue => e
(File.unlink(tmp_path) rescue nil)
raise e
end
end
def load_cache
@@ -97,24 +99,18 @@ end
def git_linguist(args)
incremental = true
commit = nil
git_dir = nil
parser = OptionParser.new do |opts|
opts.banner = "Usage: git-linguist [OPTIONS] stats|breakdown|dump-cache|clear|disable"
opts.on("-f", "--force", "Force a full rescan") { incremental = false }
opts.on("--git-dir=DIR", "Path to the git repository") { |v| git_dir = v }
opts.on("--commit=COMMIT", "Commit to index") { |v| commit = v}
end
parser.parse!(args)
git_dir ||= begin
pwd = Dir.pwd
dotgit = File.join(pwd, ".git")
File.directory?(dotgit) ? dotgit : pwd
end
git_dir = `git rev-parse --git-dir`.strip
raise "git-linguist must be ran in a Git repository" unless $?.success?
wrapper = GitLinguist.new(git_dir, commit, incremental)
case args.pop

View File

@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.homepage = "https://github.com/github/linguist"
s.license = "MIT"
s.files = Dir['lib/**/*'] - ['lib/linguist/grammars.rb']
s.files = Dir['lib/**/*'] - ['lib/linguist/grammars.rb'] + ['LICENSE']
s.executables = ['linguist', 'git-linguist']
s.add_dependency 'charlock_holmes', '~> 0.7.3'

View File

@@ -8,7 +8,8 @@
# Use "text" if a mode does not exist.
# wrap - Boolean wrap to enable line wrapping (default: false)
# extensions - An Array of associated extensions (the first one is
# considered the primary extension)
# considered the primary extension, the others should be
# listed alphabetically)
# interpreters - An Array of associated interpreters
# searchable - Boolean flag to enable searching (defaults to true)
# search_term - Deprecated: Some languages maybe indexed under a

View File

@@ -126,12 +126,13 @@ module Linguist
end
protected
MAX_TREE_SIZE = 100_000
def compute_stats(old_commit_oid, cache = nil)
return {} if current_tree.count_recursive(MAX_TREE_SIZE) >= MAX_TREE_SIZE
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
read_index
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
# Clear file map and fetch full diff if any .gitattributes files are changed

View File

@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.6.0"
VERSION = "4.6.3"
end

View File

@@ -9,7 +9,7 @@ class TestPedantic < Minitest::Test
assert_sorted LANGUAGES.keys
end
def test_extensions_are_sorted
def test_nonprimary_extensions_are_sorted
LANGUAGES.each do |name, language|
extensions = language['extensions']
assert_sorted extensions[1..-1].map(&:downcase) if extensions && extensions.size > 1