Skip to content

Draft: View correct content when blob is a symlink

Joe Woodward requested to merge feature/show_link_file_content into master

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
image image
image image

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
  1. Create a symlinked file
  2. Push to GDK
  3. 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.

  1. Create new project
  2. Import project
  3. Repository by URL
  4. Fill in URL with https://gitlab.com/gl-demo-ultimate-jwoodward/symlink-render.git
  5. Select group
  6. 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
  7. View LINKED_README.md and MULTILINKED_README.md

Additional context about how this works

  1. When we visit the blob view we render the blob viewer view
  2. 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]
  3. The markup method calls the Markup::RenderingService which in turn calls Banzai.render
  4. 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.

Edited by Joe Woodward

Merge request reports

Loading