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

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

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.

Summary ID
Provide diff metadata and more to Repository.get_file()/get_file_exists().
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.
c3df973942b43b0c344c347bc2d5c6e1edc82a07
Description From Last Updated

F811 redefinition of unused 'test_with_filediff_with_repository_encoding_set' from line 3799

reviewbotreviewbot

F401 'json' imported but unused

reviewbotreviewbot

F401 'reviewboard.scmtools.core.HEAD' imported but unused

reviewbotreviewbot

TODO is more appropriate than FIXME I think

daviddavid
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. 
      
  2. TODO is more appropriate than FIXME I think

    1. Probably. Older comment (from you! :)) that I just moved.

    2. I'm actually going to remove the comment entirely, because permission's probably bigger than this area.

  3. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.0.x (5c44d91)
Loading...