Repository navigation
Allow POD with Perl shebangs - #3735
Conversation
07760c1 to
779250d
Compare
|
Well, I'll be. Linguist allows more than one language to use the same interpreter. Guess my last comment regarding TypeScript was kinda nonsensical... |
|
We currently don't have any sample Pod file with a shebang. |
|
On second through, looking at the code, I don't think we support having several languages with the same interpreter. Interpreters are indexed in an associative array, and the next strategy, @Alhadis I guess you were right 😜 |
|
@Alhadis I'm not sure I understand... There was initially a sample in this pull request? |
|
If it was deleted, it would've appeared in the changes... :\ @kivikakk This looks to be a bug with GitHub's diff-displaying. |
|
You might've missed this: I removed it as it wasn't actually appropriate, as it's a test for the classifier (only), not the whole detection process.
When a strategy doesn't return any results, results from the previous strategy are retained. This fix is for cases where a script has a (If there is an extension, then iow, I think this does what we want, but I'll add some test cases to demonstrate. |
Nope, it missed me. I can't see that listed anywhere, and trying to open Anyway, doesn't matter. =) |
|
(This in fact won't do what I want it to, after reviewing what I wrote above, because the heuristic for |
|
Okay — new sample added, and some changes to heuristics so we can accept a list of candidates as input. In other words, if filename extension disambiguation fails, we can optionally disambiguate the list of candidates previous strategies have given us. (So far this just adds the one case for disambiguating Perl/Pod.) Anyone got 👀 for this? |
|
LGTM. 👍 Also, please tell me |
pchaigno
left a comment
There was a problem hiding this comment.
The heuristic strategy modification feels a bit hackish to me, but I can't find a better way (unless we rewrite the whole ordering of strategies...) :-/
We can always change it latter if we find another approach. LGTM 👍
| @heuristics.each do |heuristic| | ||
| if heuristic.matches?(blob.name) | ||
| languages = Array(heuristic.call(data)) | ||
| return languages if languages.any? || languages.all? { |l| candidates.include?(l) } |
There was a problem hiding this comment.
Any reason why you removed the second check (languages.all? { |l| candidates.include?(l) })? This is in place to make sure heuristic rule don't return new languages we've already crossed off the list.
There was a problem hiding this comment.
languages.any? || languages.all? { … } is always true; if languages.any? is false, then languages.all? { … } will always return true (because .any? on an empty list is always true). So the if was always happening.
There was a problem hiding this comment.
Oo 😱 You're right, that should've been an AND. And I'm the one who switched it to an OR 😓
This was for cases where we'd use the same set of heuristic rules for two extensions with different candidates. For example if we use heuristic rules on C, C++, and Objective-C for both .h (the three languages are candidates) and .inc (only C and C++ are candidates). In that case, the extra check would ensure Objective-C is never returned for the .inc extension.
We currently don't have any such case, so we're probably fine.
There was a problem hiding this comment.
Ohh, I see now. Feel free to reintroduce it in a PR if you like!
| @@ -50,14 +50,19 @@ def self.disambiguate(*extensions, &heuristic) | |||
|
|
|||
| # Internal | |||
| def initialize(extensions, &heuristic) | |||
There was a problem hiding this comment.
We should probably rename extensions to something more appropriate...?
|
I'm not sure it is caused by this change but perl script with out file extention seems to be recognized as pod. So no way to look the code. |
|
This change recognizes files with no extension and a perl shebang and POD contents as POD files, but I'd expect them to be shown as syntax-highlighted perl e.g. https://github.com/sitaramc/gitolite/blob/5c2fe87019dadbecb1883bedd075cd07b07b2078/src/gitolite previously displayed as a highlighted perl script (good), but now displays as the embedded POD (requiring me to use the Raw view to be able to see the code). Please fix it to correctly detect these kinds of files as perl (not POD) or revert it, thanks! |



Right now a POD-extension file with a Perl shebang will only get recognised as Perl. This lets the Shebang classifier not narrow too much.