Page MenuHomePhabricator

Enable visual image differences in Gerrit (was: Install gerrit image-diff plugin)
Open, Needs TriagePublic

Assigned To
None
Authored By
hashar
Jul 6 2023, 8:45 PM
Referenced Files
F56217014: newdiff_ignore_alpha.png
Jul 4 2024, 7:59 AM
F56217003: newdiff_ignore_colors_changes.png
Jul 4 2024, 7:59 AM
F56216998: newdiff_ignore_anti-aliasing.png
Jul 4 2024, 7:59 AM
F56216982: newdiff_all_differences.png
Jul 4 2024, 7:59 AM
F56216962: newdiff_enabled.png
Jul 4 2024, 7:59 AM
F56201840: newdiff_options_reworded.png
Jul 3 2024, 2:01 PM
F56174818: newdiff_hidden_radio.png
Jul 2 2024, 3:59 PM
F56145742: newdiff_alpha.png
Jul 1 2024, 9:41 PM

Description

Upstream patches:


Mentioned by Tyler during a meeting: add the ability to diff images in Gerrit. Upstream has the image-diff JavaScript plugin for it. See README/screenshots at https://github.com/GerritCodeReview/plugins_image-diff#image-diff

That requires an inline build with bazel build plugins/image-diff to install the dependencies.

We also found out a diff is included inside Gerrit core itself albeit hidden behind a feature flag (UiFeature__new_image_diff_ui), this approach is privileged instead of relying on the plugin.

The plugin or experiment integrates the Resemble.js library and can be tested against:

Image from ResembleJS demo site: https://gerrit.wikimedia.org/r/c/test/gerrit-ping/+/1051109/1..2/People.jpg

https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/902211/1/static/images/project-logos/dkwikimedia.png which slightly change the Danmark Wikimedia logo:

BeforeAfter
before.png (155×135 px, 8 KB)
after.png (139×135 px, 3 KB)

Which then let you see the differences (using cyan but that can be changed via a color picker):

diff.png (245×679 px, 22 KB)

Make the images transparent to better see the diff:

transparent.png (245×679 px, 21 KB)

Or go in gray mode:

graymode.png (245×679 px, 24 KB)

There are some CSS glitches though but that do not seem too worry some.

Event Timeline

+ @Paladox since I am pretty sure you talked about image-diff in the future and you have the relevant expertise for PolyGerrit plugins :)

If course I had to send a few patches due to the plugin depending on Resemble.JS 3.2.4 which hard depend on canvascairosome missing system libs. I have send some fixes to upstream:

The patches have been merged upstream thanks to @Paladox

Change #1050334 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@wmf/stable-3.10] Add image-diff plugin

https://gerrit.wikimedia.org/r/1050334

Change #1050395 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.10] Add image-diff plugin

https://gerrit.wikimedia.org/r/1050395

Change #1050334 merged by jenkins-bot:

[operations/software/gerrit@wmf/stable-3.10] Add image-diff plugin

https://gerrit.wikimedia.org/r/1050334

Change #1050395 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.10] Add image-diff JavaScript plugin

https://gerrit.wikimedia.org/r/1050395

Mentioned in SAL (#wikimedia-operations) [2024-06-27T15:04:32Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@9652bc3]: Add image-diff JavaScript plugin - T341291

Mentioned in SAL (#wikimedia-operations) [2024-06-27T15:04:40Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@9652bc3]: Add image-diff JavaScript plugin - T341291 (duration: 00m 07s)

Change #1050399 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.10] Revert "Add image-diff JavaScript plugin"

https://gerrit.wikimedia.org/r/1050399

Change #1050399 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.10] Revert "Add image-diff JavaScript plugin"

https://gerrit.wikimedia.org/r/1050399

Change #1050420 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@wmf/stable-3.10] Handle image-diff external dependencies

https://gerrit.wikimedia.org/r/1050420

Change #1050428 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.10] Add image-diff JavaScript plugin (take 2)

https://gerrit.wikimedia.org/r/1050428

Change #1050428 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.10] Add image-diff JavaScript plugin (take 2)

https://gerrit.wikimedia.org/r/1050428

Mentioned in SAL (#wikimedia-operations) [2024-06-27T17:13:34Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@8c6ae73]: Add image-diff JavaScript plugin (take 2) - T341291

Mentioned in SAL (#wikimedia-operations) [2024-06-27T17:13:41Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@8c6ae73]: Add image-diff JavaScript plugin (take 2) - T341291 (duration: 00m 07s)

Change #1050420 merged by jenkins-bot:

[operations/software/gerrit@wmf/stable-3.10] Handle image-diff external dependencies

https://gerrit.wikimedia.org/r/1050420

when looking at the test file https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/902211/1/static/images/project-logos/dkwikimedia.png , Gerrit retrieves the image using
https://gerrit.wikimedia.org/r/r/changes/operations%2Fmediawiki-config~902211/revisions/1/files/static%2Fimages%2Fproject-logos%2Fdkwikimedia.png/content . That has two /r which causes some HTML error to be sent and thus an invalid image. That is similar to T355931 which also was mishandling our URL prefix.

Also, I am confused since Gerrit 3.5 has code to triggers ResembleJS https://gerrit-review.googlesource.com/c/gerrit/+/310486 . Then that refers to a <gr-image-viewer> element and I can't find it :/

Apparently the image diff had been broken for quite a while and @Paladox has a fix for the /r/r in URL with: https://gerrit-review.googlesource.com/c/gerrit/+/431757

The ResembleJS code I have found in Gerrit core apparently comes from an experiment made around 2021 but which is behind a feature flag https://gerrit-review.googlesource.com/c/gerrit/+/296987/1/polygerrit-ui/app/services/flags/flags.ts :

NEW_IMAGE_DIFF_UI = 'UiFeature__new_image_diff_ui'

My guess is we could turn it on, polish up the code in Gerrit core itself and aim for having it ready for Gerrit 3.11 release. That would then make the image-diff plugin obsolete.

Change #1050595 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/software/gerrit@deploy/wmf/stable-3.10] Update Gerrit 3.10 snapshot

https://gerrit.wikimedia.org/r/1050595

Change #1050595 merged by jenkins-bot:

[operations/software/gerrit@deploy/wmf/stable-3.10] Update Gerrit 3.10 snapshot

https://gerrit.wikimedia.org/r/1050595

Mentioned in SAL (#wikimedia-operations) [2024-06-28T12:55:19Z] <hashar@deploy1002> Started deploy [gerrit/gerrit@0db053e]: Upgrade Gerrit 3.10.0-32-gf77960412e to 3.10.0-71-gf6e9431fff - T367029 T341291

Mentioned in SAL (#wikimedia-operations) [2024-06-28T12:55:35Z] <hashar@deploy1002> Finished deploy [gerrit/gerrit@0db053e]: Upgrade Gerrit 3.10.0-32-gf77960412e to 3.10.0-71-gf6e9431fff - T367029 T341291 (duration: 00m 09s)

NEW_IMAGE_DIFF_UI = 'UiFeature__new_image_diff_ui'

If I craw through the DOM to reach the <gr-diff> element then enable the feature via the console using: $0.useNewImageDiffUi = true I get the new UI:

gerrit_useNewImageDiffUi.png (634×959 px, 70 KB)

A checkbox highlights the differences, that is powered by ResembleJS

gerrit_useNewImageDiffUi_highlight_differences.png (634×959 px, 63 KB)

And there is even a blinking feature to alternate between the versions:

Change #1050614 had a related patch set uploaded (by Hashar; author: Hashar):

[operations/puppet@production] gerrit: enable "new" image diff UI

https://gerrit.wikimedia.org/r/1050614

We can enable the feature on Monday when there is plenty of time to deal with the potential aftermaths ;)

Change #1050614 merged by Jelto:

[operations/puppet@production] gerrit: enable "new" image diff UI

https://gerrit.wikimedia.org/r/1050614

Mentioned in SAL (#wikimedia-releng) [2024-07-01T11:09:00Z] <hashar> Restarting Gerrit to apply configuration change | T341291

Change #1051109 had a related patch set uploaded (by Hashar; author: Hashar):

[test/gerrit-ping@master] Test image differences

https://gerrit.wikimedia.org/r/1051109

Change #1051109 abandoned by Hashar:

[test/gerrit-ping@master] Test image differences

Reason:

https://gerrit.wikimedia.org/r/1051109

Change #1051109 restored by Paladox:

[test/gerrit-ping@master] Test image differences

https://gerrit.wikimedia.org/r/1051109

Change #1051109 abandoned by Paladox:

[test/gerrit-ping@master] Test image differences

Reason:

https://gerrit.wikimedia.org/r/1051109

The Gerrit core built-in UiFeature__new_image_diff_ui experiment generates a strict difference so that even a very slight change to colors/alpha/brightness cause the diff to be marked. There is a note left in the code about making it configurable which I have proposed upstream ( https://gerrit-review.googlesource.com/c/gerrit/+/432057 ).


newdiff_hidden_radio.png (574×889 px, 131 KB)
default view, Highlight differences is disabled, radio buttons are hidden


newdiff_enabled.png (574×889 px, 142 KB)

Highlight differences is enabled, default to ignore "Only substantial differences"


newdiff_all_differences.png (574×889 px, 67 KB)
"All differences" selected even the slightest change is shown


newdiff_ignore_anti-aliasing.png (574×889 px, 150 KB)
Ignore anti aliasing


newdiff_ignore_colors_changes.png (574×889 px, 149 KB)
Ignore colors


newdiff_ignore_alpha.png (574×889 px, 142 KB)
Ignore alpha

After renaming the options:

newdiff_options_reworded.png (574×889 px, 142 KB)

hashar renamed this task from Install gerrit image-diff plugin to Enable visual image differencein Gerrit (was Install gerrit image-diff plugin).Jul 4 2024, 9:52 AM
hashar updated the task description. (Show Details)

The patches I wrote got reverted by upstream. I was upgrading Resemble.JS which is fine in the Open Source version of Gerrit but went to conflict within Google monorepository. The code I wrote should thus be adjusted to support both the old version of the library AND the newer version of it which would allow Google to import my patches internally.

IIRC that is https://gerrit-review.googlesource.com/c/gerrit/+/432142 which switches to a new compare() which accepts an object for configuration ({ ignore: 'nothing'}) while the old version uses chainable methods (.compareTo().ignoreNothing()). In https://gerrit-review.googlesource.com/c/gerrit/+/432057/10/polygerrit-ui/app/embed/diff/gr-diff-image-viewer/gr-image-viewer.ts , I have mapped a UI radio group value to the ignore value and the old API doesn't even support all those ignores iirc.

So it is not that complicated to implement, but still requires some time :-]

I might want to also reach out to Google engineers and ask them to upgrade Resemble.JS internally, but I imagine it would be a very low priority for them.

Aklapper renamed this task from Enable visual image differencein Gerrit (was Install gerrit image-diff plugin) to Enable visual image differences in Gerrit (was: Install gerrit image-diff plugin).Oct 30 2024, 12:30 PM