Provide diff metadata and more to Repository.get_file()/get_file_exists().
Review Request #11805 — Created Sept. 1, 2021 and submitted
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 addedbase_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
andFileDiff.extra_data
. However, there was no
way of getting access to this information, and bolting on several new
parameters toget_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 thebase_commit_id
andrequest
on theRepository
functions, and addsextra_data
attributes for the
FileDiff
,DiffCommit
, andDiffSet
(or theParsed*
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
andrequest
are now soft-deprecated. TheRepository
functions still accept them and will pass them on, and theSCMTool
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.
Summary | ID |
---|---|
c3df973942b43b0c344c347bc2d5c6e1edc82a07 |
- Change Summary:
-
- Removed unused imports.
- Fixed a duplicate test name.
- Commits:
-
Summary ID 8cffd344d860641993c91751cfffeba23c51a7d4 c3df973942b43b0c344c347bc2d5c6e1edc82a07 - Diff:
-
Revision 2 (+1756 -426)