Give FileDiffs control over handling of encodings for source files.
Review Request #10775 — Created Nov. 1, 2019 and submitted
Historically, Review Board has depended on source files to either us a
UTF-8 or ISO-8859-15 encoding, or for the repository to supply a list of
compatible encodings. If a special encoding were ever used for a file,
and the repository later had its encodings list changed to exclude it,
file would no longer be able to be viewed in the diff viewer.This encoding list was computed up-front when generating a diff for
file. We'd fetch the repository encoding list, pass it to calls like
get_original_file()
, which would then pass that on to
convert_to_unicode()
, which would try the built-in encodings and the
provided list of encodings. The caller was always responsible for
fetching or computing that encoding list up-front before calling any of
these methods.This change rewrites all of this to make the process more dependent on
theFileDiff
we're working on, and to record a known working encoding
for future use.
FileDiff.extra_data
can now contain an'encoding'
key (conveniently
exposed asFileDiff.encoding
), which specifies an explicit encoding to
use. This could in theory be set during diff parsing (which requires
some additional work still), but it will be set after we've successfully
converted a source file to Unicode and back.If not set, we still respect the provided encoding list (though this is
now deprecated inget_original_file()
), and then look up from the
repository. This will allow us to later work withFileDiffs
backed by
multiple repositories without placing unnecessary burdens on the caller.The machinery for diff chunk generation has been updated as well. Now,
RawDiffChunkGenerator.generate_chunks()
can be given an encoding list
for the old and new content. This defaults to the encoding list normally
provided to the chunk generator, but subclasses (DiffChunkGenerator
)
can pass in separate encoding lists, allowing for twoFileDiff
s on an
interdiff to be in separate encodings without breaking chunk generation.Note that it's still possible for a patch to contain content in another
encoding that doesn't match what's inFileDiff.encoding
. The chunk
generator will still try to do the right thing in this case, falling
back to the repository encodings.
Unit tests passed.
Made sure my various test diffs and interdiffs were still working as
expected.
- Change Summary:
-
Fixed a name conflict for a test function, and a broken check it masked.
- Commit:
-
9216e0cc38e69b039efff62c874a2ba18c32de057a5524f1d894c0d747fe94ebf2b2e2f5af09e2de
- Diff:
-
Revision 2 (+733 -94)
Checks run (2 succeeded)
- Change Summary:
-
- Based this on top of /r/10776/, which implements
FileDiff.get_repository()
(instead of including it in this change) - Updated a couple more calls to
get_original_file()
.
- Based this on top of /r/10776/, which implements
- Depends On:
-
- Commit:
7a5524f1d894c0d747fe94ebf2b2e2f5af09e2deb09f47b5bc34ba33fdfae987121f1fd28826abd9- Diff:
Revision 3 (+731 -104)
Checks run (2 succeeded)
flake8 passed.JSHint passed.
- Change Summary:
-
Renamed
DEFAULT_ENCODING
toFALLBACK_ENCODING
. - Commit:
-
b09f47b5bc34ba33fdfae987121f1fd28826abd978b4aa407eb6c2a2549a8408b46d906e79b4f38d
- Diff:
-
Revision 4 (+734 -104)