Skip to content

Fix infinite loop when rendering merge request file tree

Mark Florian requested to merge long-path-mr-bug into master

What does this MR do?

If you create an MR which changes files in a directory more than 20 levels deep, the file tree will never render, since the WebWorker(s) responsible for generating the data structure will enter an infinite loop (spiking CPU usage).

This is because the truncation algorithm doesn't handle the case when a path, fully-ellipsised, is still longer than the specified maxWidth.

The depth of 20 mentioned above is due to the fact that a maxWidth of 40 is hard-coded for the tree view. For a path with 21 segments, the string the util would build is …/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/…, which is 41 characters long, so the while condition is never false, leading to the infinite loop.

This adds a condition to handle that case, returning a truncated string that never exceeds the maxWidth, no matter how deep the path is.

There are a few issues(#35815 (closed), #27533 (closed)) about this truncation being less than ideal. For this MR, the intention is to keep the existing behaviour, but fix a pathological case in the simplest way possible.

Example MR demonstrating bug

markrian/project-with-very-deep-path!1 (diffs)

Screenshots

Before After
Screenshot_from_2020-06-09_11-19-17 Screenshot_from_2020-06-09_11-18-40

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Mark Florian

Merge request reports