Skip to content

Show only changed portions for .bsdoc diffs#94

Draft
google-labs-jules[bot] wants to merge 2 commits intomainfrom
bsdoc-zero-context-diff-9117756162973571265
Draft

Show only changed portions for .bsdoc diffs#94
google-labs-jules[bot] wants to merge 2 commits intomainfrom
bsdoc-zero-context-diff-9117756162973571265

Conversation

@google-labs-jules
Copy link

Introduce zero-context diffing for .bsdoc files to improve frontend rendering and avoid redundant HTML context.


PR created automatically by Jules for task 9117756162973571265 started by @davidgraymi

This commit introduces a `Context` option to the backend diff service,
allowing the use of custom git diff context (e.g., `-U0`).

Routers for Pull Requests, Commit Diffs, and Editor Previews have been
updated to use zero context for `.bsdoc` files and extensionless files
(excluding `LICENSE`) when fetching rendered diffs. This ensures that
visually appealing HTML-based diffs only show the modified parts without
redundant context that could break HTML structure.

Modified:
- services/gitdiff/gitdiff.go: Add Context to DiffOptions and use it in GetDiff.
- services/repository/files/temp_repo.go: Update DiffIndex to support DiffOptions.
- services/repository/files/diff.go: Update GetDiffPreview to support DiffOptions.
- services/repository/files/diff_test.go: Update tests for new signature.
- routers/web/repo/pull.go, routers/web/repo/editor.go, routers/web/repo/compare.go, routers/web/repo/commit.go:
  Set zero context for .bsdoc files during diff rendering.
@google-labs-jules
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

This commit implements a structural context filter for HTML-based `.bsdoc`
files. Instead of showing the entire file or broken HTML hunks, the backend
now uses an indentation-based heuristic to identify and include the
necessary ancestor and closer tags for each changed line.

This ensures that the resulting diff:
1. Shows only the relevant portions that have changed.
2. Maintains HTML structural integrity (balanced tags) for correct
   rendering on the frontend.

The implementation is contained within `GetComputedSectionDiffForSnap` in
`services/gitdiff/gitdiff.go`, which is specifically used for `.bsdoc` files.
By relying on the default `-W` (full context) provided by the backend, the
filter has access to all lines needed to rebuild the structural context.

Tests have been added to verify the filtering logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants