Provide diff metadata and more to Repository.get_file()/get_file_exists().

Review Request #11805 — Created Sept. 1, 2021 and submitted — Latest diff uploaded

Information

Review Board
release-4.0.x

Reviewers

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
DiffSet.extra_data and FileDiff.extra_data. However, there was no
way of getting access to this information, and bolting on several new
parameters to get_file()/get_file_exists() (and SCM and hosting
service backends) seemed like an unsustainable approach.

This change introduces a new FileLookupContext object, which is a
container for contextual information that might be useful for file
lookups. It effectively replaces the base_commit_id and request
on the Repository functions, and adds extra_data attributes for the
FileDiff, DiffCommit, and DiffSet (or the Parsed* equivalents
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.

base_commit_id and request are now soft-deprecated. The Repository
functions still accept them and will pass them on, and the SCMTool
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
integration.

Commits

Files