From 4bfd65deb84c33b2e2deb60b6fadda4460985170 Mon Sep 17 00:00:00 2001 From: Paul Cantrell Date: Wed, 19 Aug 2015 11:42:21 -0500 Subject: [PATCH 01/26] #import "*.h" detection for Objective-C --- lib/linguist/heuristics.rb | 2 +- samples/Objective-C/Siesta.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 samples/Objective-C/Siesta.h diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index dd1f8ee6..1660d99f 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -65,7 +65,7 @@ module Linguist end # Common heuristics - ObjectiveCRegex = /^[ \t]*@(interface|class|protocol|property|end|synchronized|selector|implementation)\b/ + ObjectiveCRegex = /^\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\b|#import\s+.+\.h[">])/ disambiguate ".asc" do |data| if /^(----[- ]BEGIN|ssh-(rsa|dss)) /.match(data) diff --git a/samples/Objective-C/Siesta.h b/samples/Objective-C/Siesta.h new file mode 100644 index 00000000..a48984e3 --- /dev/null +++ b/samples/Objective-C/Siesta.h @@ -0,0 +1,16 @@ +// +// Siesta.h +// Siesta +// +// Created by Paul on 2015/6/14. +// Copyright © 2015 Bust Out Solutions. MIT license. +// + +#import + +//! Project version number for Siesta. +FOUNDATION_EXPORT double SiestaVersionNumber; + +//! Project version string for Siesta. +FOUNDATION_EXPORT const unsigned char SiestaVersionString[]; + From b1dcdf34186d3088e6e45ed9a78ffe9af26e96b7 Mon Sep 17 00:00:00 2001 From: miksen Date: Fri, 4 Sep 2015 11:49:10 +0200 Subject: [PATCH 02/26] Language bar clarification in README.md Clarified what the percentages in the Language bar are based on. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ca08af1..2a4d3c31 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ See [Troubleshooting](#troubleshooting) and [`CONTRIBUTING.md`](/CONTRIBUTING.md ![language stats bar](https://cloud.githubusercontent.com/assets/173/5562290/48e24654-8ddf-11e4-8fe7-735b0ce3a0d3.png) -The Language stats bar is built by aggregating the languages of each file in that repository. If it is reporting a language that you don't expect: +The Language stats bar displays languages percentages for the files in the repository. The percentages are calculated based on the bytes of code for each language as reported by the [List Languages](https://developer.github.com/v3/repos/#list-languages) API. If the bar is reporting a language that you don't expect: 0. Click on the name of the language in the stats bar to see a list of the files that are identified as that language. 0. If you see files that you didn't write, consider moving the files into one of the [paths for vendored code](/lib/linguist/vendor.yml), or use the [manual overrides](#overrides) feature to ignore them. From 1f46cfafa7ddf7e849f73e2472c558004b83f22c Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sat, 5 Sep 2015 13:31:17 +0200 Subject: [PATCH 03/26] New JSX language under JavaScript group A specific grammar is needed to highlight .jsx files Thus, there are now in a distinct language but still in the JavaScript group --- .gitmodules | 3 +++ grammars.yml | 3 +++ lib/linguist/languages.yml | 9 ++++++++- samples/JSX/sample.jsx | 23 +++++++++++++++++++++++ vendor/grammars/language-babel | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 samples/JSX/sample.jsx create mode 160000 vendor/grammars/language-babel diff --git a/.gitmodules b/.gitmodules index 5f07d011..87654b7e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -677,3 +677,6 @@ [submodule "vendor/grammars/X10"] path = vendor/grammars/X10 url = git@github.com:x10-lang/x10-highlighting.git +[submodule "vendor/grammars/language-babel"] + path = vendor/grammars/language-babel + url = https://github.com/gandm/language-babel diff --git a/grammars.yml b/grammars.yml index 42be3967..2a7a89e2 100644 --- a/grammars.yml +++ b/grammars.yml @@ -314,6 +314,9 @@ vendor/grammars/json.tmbundle: - source.json vendor/grammars/kotlin-sublime-package: - source.Kotlin +vendor/grammars/language-babel/: +- source.js.jsx +- source.regexp.babel vendor/grammars/language-clojure: - source.clojure vendor/grammars/language-coffee-script: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b2d75fa1..7be29046 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1575,6 +1575,14 @@ JSONiq: - .jq tm_scope: source.jq +JSX: + type: programming + group: JavaScript + extensions: + - .jsx + tm_scope: source.js.jsx + ace_mode: javascript + Jade: group: HTML type: markup @@ -1628,7 +1636,6 @@ JavaScript: - .jsfl - .jsm - .jss - - .jsx - .njs - .pac - .sjs diff --git a/samples/JSX/sample.jsx b/samples/JSX/sample.jsx new file mode 100644 index 00000000..2020618d --- /dev/null +++ b/samples/JSX/sample.jsx @@ -0,0 +1,23 @@ +'use strict'; + +const React = require('react') + +module.exports = React.createClass({ + render: function() { + let {feeds, log} = this.props; + + log.info(feeds); + return
+

News Feed's

+
    + {feeds.map(function(feed) { + return
  • + {feed.data && feed.data.length > 0 ? + {feed.name} ({feed.data.length}) + : 'feed.name' } +
  • + })} +
+
; + } +}); diff --git a/vendor/grammars/language-babel b/vendor/grammars/language-babel new file mode 160000 index 00000000..c79ac897 --- /dev/null +++ b/vendor/grammars/language-babel @@ -0,0 +1 @@ +Subproject commit c79ac8979cff724e7db8933044f00b975dc4f277 From b275b5d728fd0330f8df29513a8c935528e2bc36 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 4 Sep 2015 10:24:06 +0200 Subject: [PATCH 04/26] Soften memory pressure --- lib/linguist/generated.rb | 8 ++++++-- lib/linguist/heuristics.rb | 3 ++- lib/linguist/lazy_blob.rb | 4 ++++ lib/linguist/repository.rb | 7 +++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index f1fb2d19..d107e737 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -241,22 +241,26 @@ module Linguist return lines[0].include?("Code generated by") end + PROTOBUF_EXTENSIONS = ['.py', '.java', '.h', '.cc', '.cpp'] + # Internal: Is the blob a C++, Java or Python source file generated by the # Protocol Buffer compiler? # # Returns true of false. def generated_protocol_buffer? - return false unless ['.py', '.java', '.h', '.cc', '.cpp'].include?(extname) + return false unless PROTOBUF_EXTENSIONS.include?(extname) return false unless lines.count > 1 return lines[0].include?("Generated by the protocol buffer compiler. DO NOT EDIT!") end + APACHE_THRIFT_EXTENSIONS = ['.rb', '.py', '.go', '.js', '.m', '.java', '.h', '.cc', '.cpp'] + # Internal: Is the blob generated by Apache Thrift compiler? # # Returns true or false def generated_apache_thrift? - return false unless ['.rb', '.py', '.go', '.js', '.m', '.java', '.h', '.cc', '.cpp'].include?(extname) + return false unless APACHE_THRIFT_EXTENSIONS.include?(extname) return false unless lines.count > 1 return lines[0].include?("Autogenerated by Thrift Compiler") || lines[1].include?("Autogenerated by Thrift Compiler") diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 1660d99f..11f58b28 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -56,7 +56,8 @@ module Linguist # Internal: Check if this heuristic matches the candidate languages. def matches?(filename) - @extensions.any? { |ext| filename.downcase.end_with?(ext) } + filename = filename.downcase + @extensions.any? { |ext| filename.end_with?(ext) } end # Internal: Perform the heuristic diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 55c10309..28fb78f3 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -79,6 +79,10 @@ module Linguist @size end + def cleanup! + @data.clear if @data + end + protected # Returns true if the attribute is present and not the string "false". diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 181ddf0e..01e595da 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -157,8 +157,11 @@ module Linguist blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8)) - next unless blob.include_in_language_stats? - file_map[new] = [blob.language.group.name, blob.size] + if blob.include_in_language_stats? + file_map[new] = [blob.language.group.name, blob.size] + end + + blob.cleanup! end end From b1bcabd6e6896b00dc06f6be9ef482729d645807 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 8 Sep 2015 12:25:05 +0100 Subject: [PATCH 05/26] Adding Handlebars to the HTML group --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 7be29046..8409337b 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1367,6 +1367,7 @@ Haml: Handlebars: type: markup color: "#01a9d6" + group: HTML aliases: - hbs - htmlbars From 13d1f662d1ec2bf1ce3af6eef2459f520f9701fe Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 4 Sep 2015 15:11:29 +0200 Subject: [PATCH 06/26] Add the `git-linguist` helper --- bin/git-linguist | 141 ++++++++++++++++++++++++++++++++++++++++ github-linguist.gemspec | 2 +- lib/linguist/version.rb | 2 +- 3 files changed, 143 insertions(+), 2 deletions(-) create mode 100755 bin/git-linguist diff --git a/bin/git-linguist b/bin/git-linguist new file mode 100755 index 00000000..f761cfaf --- /dev/null +++ b/bin/git-linguist @@ -0,0 +1,141 @@ +#!/usr/bin/env ruby + +require 'linguist' +require 'rugged' +require 'optparse' +require 'json' +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 + @incremental = incremental + end + + def linguist + repo = Linguist::Repository.new(rugged, commit_oid) + + if incremental && stats = load_language_stats + old_commit_oid, old_stats = stats + + # A cache with NULL oid means that we want to froze + # these language stats in place and stop computing + # them (for performance reasons) + return old_stats if old_commit_oid == NULL_OID + repo.load_existing_stats(old_commit_oid, old_stats) + end + + result = yield repo + + 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] + end + end + + def save_language_stats(commit_oid, stats) + cache = [LANGUAGE_STATS_CACHE_VERSION, commit_oid, stats] + write_cache(cache) + end + + def clear_language_stats + File.unlink(cache_file) + end + + def disable_language_stats + save_language_stats(NULL_OID, {}) + end + + protected + NULL_OID = ("0" * 40).freeze + + LANGUAGE_STATS_CACHE = 'language-stats.cache' + LANGUAGE_STATS_CACHE_VERSION = "v3:#{Linguist::VERSION}" + + def rugged + @rugged ||= Rugged::Repository.bare(repo_path) + end + + def cache_file + File.join(repo_path, LANGUAGE_STATS_CACHE) + end + + def write_cache(object) + 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 + end + + def load_cache + marshal = File.open(cache_file, "rb") { |f| Zlib::Inflate.inflate(f.read) } + Marshal.load(marshal) + rescue SystemCallError, ::Zlib::DataError, ::Zlib::BufError, TypeError + nil + end +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 + + wrapper = GitLinguist.new(git_dir, commit, incremental) + + case args.pop + when "stats" + wrapper.linguist do |linguist| + puts JSON.dump(linguist.languages) + end + when "breakdown" + wrapper.linguist do |linguist| + puts JSON.dump(linguist.breakdown_by_file) + end + when "dump-cache" + puts JSON.dump(wrapper.load_language_stats) + when "clear" + wrapper.clear_language_stats + when "disable" + wrapper.disable_language_stats + else + $stderr.print(parser.help) + exit 1 + end +end + +git_linguist(ARGV) diff --git a/github-linguist.gemspec b/github-linguist.gemspec index 87bbc8bf..8e043857 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.license = "MIT" s.files = Dir['lib/**/*'] - ['lib/linguist/grammars.rb'] - s.executables << 'linguist' + s.executables = ['linguist', 'git-linguist'] s.add_dependency 'charlock_holmes', '~> 0.7.3' s.add_dependency 'escape_utils', '~> 1.1.0' diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index dbdb7d7f..0ee8b185 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.5.15" + VERSION = "4.6.0.rc3" end From c2c068e9db1fdb900716dcc9373e37ff5d2a4ca2 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 14 Sep 2015 08:43:10 -0700 Subject: [PATCH 07/26] Bump version to 4.6.0 --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 0ee8b185..a90a01fa 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.6.0.rc3" + VERSION = "4.6.0" end From 0145a0adb2633d99255c01239fab90fe93dd13d2 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 16 Sep 2015 05:40:55 -0700 Subject: [PATCH 08/26] git-linguist: Delay loading @commit_oid --- bin/git-linguist | 29 ++++++++++++++--------------- lib/linguist/version.rb | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bin/git-linguist b/bin/git-linguist index f761cfaf..03408ee5 100755 --- a/bin/git-linguist +++ b/bin/git-linguist @@ -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,11 +63,11 @@ 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) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index a90a01fa..7f5e1750 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.6.0" + VERSION = "4.6.1" end From b54a9c7412d7659f0920a8bc5f9e8447be87b50e Mon Sep 17 00:00:00 2001 From: wizawu Date: Mon, 21 Sep 2015 13:48:30 +0800 Subject: [PATCH 09/26] Add new extension .tsx for TypeScript TypeScript 1.6 has introduced a new .tsx file extension. --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 8409337b..ddb18e78 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3441,6 +3441,7 @@ TypeScript: - ts extensions: - .ts + - .tsx tm_scope: source.ts ace_mode: typescript From 6a2d33a4b345039661ff37167bbdceaaf8875306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 21 Sep 2015 19:04:30 +0200 Subject: [PATCH 10/26] Bump language-javascript for syntax highlighting fix This is primarily to pull https://github.com/atom/language-javascript/pull/227 Full changelog: https://github.com/atom/language-javascript/compare/c5c381e...7b14bbb#diff-46d5c1ca71eaebb92619d6c7abc9388d --- vendor/grammars/language-javascript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/grammars/language-javascript b/vendor/grammars/language-javascript index c5c381e3..7b14bbb0 160000 --- a/vendor/grammars/language-javascript +++ b/vendor/grammars/language-javascript @@ -1 +1 @@ -Subproject commit c5c381e37812219db84cb5916094ca3b8dce62db +Subproject commit 7b14bbb041abcb39522defceca509cd35b6a7449 From 090ea576b956bc812498f99da2604e95b2e3ee70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 21 Sep 2015 21:23:40 +0200 Subject: [PATCH 11/26] github-linguist-grammars 4.6.2 --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 7f5e1750..60bc59e0 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.6.1" + VERSION = "4.6.2" end From a354eddf4bce62acbc5f4b140dd64da71750a751 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 22 Sep 2015 16:33:08 -0400 Subject: [PATCH 12/26] Update github-linguist.gemspec --- github-linguist.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-linguist.gemspec b/github-linguist.gemspec index 8e043857..bdba3e6b 100644 --- a/github-linguist.gemspec +++ b/github-linguist.gemspec @@ -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' From c624d686283df346ab8b24efdb2a81c98aaf16cf Mon Sep 17 00:00:00 2001 From: Jared Petersen Date: Wed, 23 Sep 2015 20:29:07 -0700 Subject: [PATCH 13/26] Added .pck PLSQL file extension --- lib/linguist/languages.yml | 1 + samples/PLSQL/plsqlguide.pck | 90 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 samples/PLSQL/plsqlguide.pck diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 8409337b..abac6618 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2456,6 +2456,7 @@ PLSQL: color: "#dad8d8" extensions: - .pls + - .pck - .pkb - .pks - .plb diff --git a/samples/PLSQL/plsqlguide.pck b/samples/PLSQL/plsqlguide.pck new file mode 100644 index 00000000..d31830ba --- /dev/null +++ b/samples/PLSQL/plsqlguide.pck @@ -0,0 +1,90 @@ +create or replace package plsqlguide is + +-- Author : Jared Petersen +-- Created : 9/22/2015 12:26:22 AM +-- Purpose : Basic PLSQL template/guide + +/* Procedures */ +procedure p_main; + +end plsqlguide; +/ +create or replace package body plsqlguide is + +/* Main entry point (homepage) */ +procedure p_main + is +begin + +htp.prn(' + + + + + + + + PL/SQL Sample Application + + + + + + + + + + + +
+ + + + + + + + +'); + +-- Fill out the parts table +for row in (select * from parts) loop + htp.prn(' + + + + + + + + '); +end loop; + +htp.prn(' +
#NameDescriptionQuantityPrice
'||row.pid||''||row.name||''||row.description||''||row.quantity||''||row.price||'
+
+ + + + + + + +'); + +end p_main; + +begin + -- Initialization + null; +end plsqlguide; +/ From 040af5dad204b01cd312ac0434e90b90bc753e77 Mon Sep 17 00:00:00 2001 From: Ingo Blechschmidt Date: Fri, 25 Sep 2015 19:14:40 +0200 Subject: [PATCH 14/26] Clarify that only nonprimary extensions should be sorted --- lib/linguist/languages.yml | 3 ++- test/test_pedantic.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 8409337b..0de559ee 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -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 diff --git a/test/test_pedantic.rb b/test/test_pedantic.rb index 2d0372cc..d34f292e 100644 --- a/test/test_pedantic.rb +++ b/test/test_pedantic.rb @@ -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 From 41911d6921d7277c6606b6054dcf12ed5a599cd9 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 25 Sep 2015 08:26:27 -0700 Subject: [PATCH 15/26] git-linguist: Properly handle $GIT_DIR from git --- bin/git-linguist | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/git-linguist b/bin/git-linguist index 03408ee5..170406de 100755 --- a/bin/git-linguist +++ b/bin/git-linguist @@ -96,24 +96,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 From 41d438b47e8ee83a66705f6c04106662e6ea922f Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 25 Sep 2015 08:35:34 -0700 Subject: [PATCH 16/26] repository: Do not attempt to scan large repos --- lib/linguist/repository.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 01e595da..51040734 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -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 From 7c759d4d293412d23de180e5fd54a4192ac4382f Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 28 Sep 2015 01:45:04 -0700 Subject: [PATCH 17/26] git-linguist: Do not write cache if repo is gone --- bin/git-linguist | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bin/git-linguist b/bin/git-linguist index 170406de..9541cf82 100755 --- a/bin/git-linguist +++ b/bin/git-linguist @@ -71,17 +71,20 @@ class GitLinguist end def write_cache(object) - tmp_path = Dir::Tmpname.make_tmpname(cache_file, nil) + return unless File.directory? @repo_path - File.open(tmp_path, "wb") do |f| - marshal = Marshal.dump(object) - f.write(Zlib::Deflate.deflate(marshal)) + 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) + rescue => e + (File.unlink(tmp_path) rescue nil) + raise e end - - File.rename(tmp_path, cache_file) - tmp_path = nil - ensure - (File.unlink(tmp_path) rescue nil) if tmp_path end def load_cache From d8e3bec499a16eefc0f191db463b291d10204c9c Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 25 Sep 2015 08:36:20 -0700 Subject: [PATCH 18/26] Bump version --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 60bc59e0..3de24f3d 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.6.2" + VERSION = "4.6.3" end From 3426165621a5ff0261b10f70947841117fe82dbf Mon Sep 17 00:00:00 2001 From: wizawu Date: Wed, 30 Sep 2015 13:45:38 +0800 Subject: [PATCH 19/26] Add a TypeScript sample with .tsx extension --- samples/TypeScript/app.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 samples/TypeScript/app.tsx diff --git a/samples/TypeScript/app.tsx b/samples/TypeScript/app.tsx new file mode 100644 index 00000000..43155ceb --- /dev/null +++ b/samples/TypeScript/app.tsx @@ -0,0 +1,9 @@ +import * as React from 'react'; + +export class App extends React.Component { + + render() { + return