Draft: View correct content when blob is a symlink
What does this MR do and why?
This is the continuation of a Community contribution Support for displaying soft link file content (!59108 - closed)
View correct content when blob is a symlink
When we create a symlink, git stores this as a blob with mode 120000 and the data will be the path to the linked file.
Prior to this change we would render the path to the linked file in the UI when it would make more sense to render the linked file.
Now when we visit a symlink we see the correct content e.g.
blob_a is README.md blob_b is a symlink to ./README.md
Viewing blob_b now displays the contents of README.md from blob_a.
Changelog: added
Co-authored-by: Joe Woodward jwoodward@gitlab.com
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
NOTE: Banzai caches the rendering so you can either clear you cache between tests or add false &&
to Banzai::Renderer
line 23.
if false && cache_key
- Create a symlinked file
- Push to GDK
- View file
Should now see the actual file rather than the file path that is linked.
Alternatively, you can import a project from gitlab.com that I have setup.
- Create new project
- Import project
- Repository by URL
- Fill in URL with
https://gitlab.com/gl-demo-ultimate-jwoodward/symlink-render.git
- Select group
- Open a rails console and run
Rails.cache.clear
or if you don't want to wipe out the entire cache you can update your local markdown version https://gitlab.com/gitlab-org/gitlab/-/blob/russell/add-billing-policy/doc/administration/invalidate_markdown_cache.md - View LINKED_README.md and MULTILINKED_README.md
Additional context about how this works
- When we visit the blob view we render the blob viewer view
- We then render the
blob.viewer.partial_path
, for markdown this is viewers/_markup.html.haml which calls the markup helper passing in the viewer.banzai_render_context which includes the cache key['blob', blob.id, 'commit', blob.commit_id]
- The markup method calls the Markup::RenderingService which in turn calls
Banzai.render
-
Banzai.render
calls Banzai::Render.new(...).execute which uses the cache key when rendering the blob.
The other file viewers work following the same mechanisms except they aren't cached.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.