Refactor Linguist::Repository
to isolate Rugged usage
#7094
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The goal of this change is to add flexibility to how repository data is accessed by
Linguist::Repository
&Linguist::LazyBlob
, allowing users to easily configure an alternative toRugged
.Internally,
Linguist::Repository
andLinguist::LazyBlob
use Rugged to read Git repository data, including diff, attribute, and blob information. While this works for most repositories, it has limits:The approach taken here is to replace the
Rugged::Repository
instance in theLinguist::Repository
with a newLinguist::Source::Repository
instance. The "source" repository contains functions wrapping what were previously Rugged operations (diff, attribute lookup, etc.). Users can then write their custom implementations of those functions and pass theirLinguist::Source::Repository
intoLinguist::Repository
to use them seamlessly.This isn't intended to be a breaking change, so there are a few extra things done to avoid compatibility issues with existing usage:
Rugged::Repository
is passed in as the first argument to either theLinguist::Repository
orLazyBlob
initializer, it is wrapped in aLinguist::Source::RuggedRepository
internally.GIT_ATTR_OPTS
&GIT_ATTR_FLAGS
are Rugged-specific so they're moved toRuggedRepository
, but theLazyBlob
constants are not removed and instead point to theirRuggedRepository
counterparts.current_tree
andread_index
don't make sense for non-Rugged repos (the former returns a Rugged tree instance, the latter is specific to how Rugged needs to look up attributes). They raiseNotImplementedError
with a message referencing deprecation only if called on a non-Rugged repository instance; otherwise they behave the same way as before.method_missing
implementation is added toLinguist::RuggedRepository
to delegate any unmatched method calls to the internalRugged::Repository
instance (in case users are callingLinguist::Repository.repository
directly).The only possible compatibility issue I can imagine is if a user does some kind of type check on
Linguist::Repository.repository
(previously it was aRugged::Repository
, now it'll be aLinguist::Source::RuggedRepository
). That seems highly unlikely, though, and should be a simple fix if needed.The commits on this branch are organized to be atomic and incrementally reviewable:
Linguist::Source:Repository
andLinguist::Source::Diff
interfaces, with all methods raisingNotImplementedError
to ensure they are overridden by a subclass implementation.Linguist::Source::Repository
matching existing usage incompute_stats
andLinguist::LazyBlob
.Linguist::Repository
to use aLinguist::Source::Repository
instead of aRugged::Repository
to read repository content.method_missing
implementation toRuggedRepository
.Checklist:
I am adding a new extension to a language.
I am adding a new language.
#RRGGBB
I am fixing a misclassified language
I am changing the source of a syntax highlighting grammar
I am updating a grammar submodule
I am adding new or changing current functionality
I am changing the color associated with a language