Provide diff metadata and more to Repository.get_file()/get_file_exists().
Review Request #11805 — Created Sept. 1, 2021 and updated
Originally, repository file lookups required a path within the
repository and a revision, which was fine for a lot of SCMs but wasn't
sufficient for others. Later, we added
base_commit_id, a somewhat
loosely-defined identifier that represented some commit that the helped
locate the files on some SCMs/hosting services.
While working to integrate with another new SCM, we've found that these
three identifiers really aren't enough, and we need other information
parsed in a diff, made available through the DiffX parser and stored in
FileDiff.extra_data. However, there was no
way of getting access to this information, and bolting on several new
get_file_exists()(and SCM and hosting
service backends) seemed like an unsustainable approach.
This change introduces a new
FileLookupContextobject, which is a
container for contextual information that might be useful for file
lookups. It effectively replaces the
Repositoryfunctions, and adds
extra_dataattributes for the
during diff parsing/validation).
This gives implementations access to any metadata parsed from the diff,
along with the user accessing the repository, the active HTTP request,
and the base commit ID. In the future, we'll be able to add new context
(or even functions for permanently caching computed lookup state from
these functions) without having to funnel new parameters everywhere.
requestare now soft-deprecated. The
functions still accept them and will pass them on, and the
implementations still receive them. We'll probably want to include
deprecation warnings in a future major version.
Unit tests pass.
This is pending extensive testing with the development of a new SCM
- Removed unused imports.
- Fixed a duplicate test name.
Revision 2 (+1756 -426)