Skip to content

web: migrate the commit compare page to React - #8534

Merged
unknwon merged 9 commits into
mainfrom
compare-react-flamego
Nov 16, 2026
Merged

unknwon merged 9 commits into
mainfrom
compare-react-flamego

Conversation

@unknwon

@unknwon unknwon commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Migrates the comparison of two commits (/{owner}/{repo}/compare/{before}...{after}) to React. This is the page the activity feed and push notifications link to. It is backed by GET /api/web/{owner}/{repo}/compare/{before}...{after}, and the raw diff is served at the same path with a .diff suffix.

Two commits:

  1. Shared diff view. The commit page's diff workspace (full-width layout, toolbar, file tree with its mobile sheet, line expansion, search params) moves into DiffWorkspace, which takes the raw diff and both commits. The commit page only keeps its header. No visible change.
  2. Compare page. A "N commits" heading with both short SHAs linking to their commit pages, a "diff" link to the raw diff, the commits in the range, one line each with the title, author, time and SHA, then DiffWorkspace from before to after. Unified and split, whitespace options, the file tree and "Expand all lines" all work as on the commit page, and expanding reads the files at before and after.
  • Access is the same as legacy. Readers of a non-empty repository see the page, and everyone else gets 404. Only full SHA-1 or SHA-256 commit IDs are compared here. Branch comparisons (/compare/master...feature) still go to the pull request compare page.
  • Commit rows: CommitList takes compact, which lists the commits without day headings, each on one line: the title, then the avatar, author and time, then the SHA, without the copy and browse buttons. Below sm the author and time go under the title. Only the compare page uses it, and the commit history keeps its two-line rows.
  • Long ranges: the page lists at most the 50 newest commits, and the heading counts all of them. It shows the first 10 until "Show N more commits", and a cut-off list ends with "Showing the 50 most recent commits." and a link to the full history. The .diff no longer lists commits at all.
  • Git: Log and RevList read the commits they list with one git cat-file --batch instead of two processes per commit. This also speeds up the commit history and every other commit list.
  • Git: RawDiffOptions.Base diffs from a base commit instead of the parent. A commit that is not in the repository gets 404 on both the compare page and its .diff.
  • Removed: the legacy CompareDiff handler and repo/diff/page.tmpl. commits_table.tmpl stays for the pull request pages.
  • Added repo.commits.n_commit and repo.commits.n_commits. Documented DiffWorkspace in web/DESIGN.md.

Behavior changes from legacy

  • The heading is "1 commit" or "N commits" instead of "N Commits".
  • Commits are grouped by day instead of shown in a table.
  • An unknown SHA gets 404 instead of 500.
  • A range with no changes shows "No commits found." without an empty diff.
  • A range from an empty commit ID, e.g., the push of a new branch, compares from where the branch left the default branch, or from the empty tree when it shares no history with it, as repo: compare a created branch against where it forked #8510 does for the legacy page. The page shows that base, and the empty tree is not a link.

Screenshots

Comparing two commits

Comparing two commits

Expanded lines of long.go, with search in diff

Expanded lines with search in diff

Dark

Dark

Split

Split

No changes

No changes

Commit page, unchanged

Commit page

300 commits, first 10 shown

300 commits, first 10 shown

300 commits, after "Show 40 more commits"

Cut-off list with a link to the full history

300 commits, dark

300 commits, dark

300 commits, 375px
300 commits, 375px
Compare, 375px
Compare, 375px

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. go test ./cmd/gogs/internal/web/ ./internal/git/ ./internal/route/... passes. TestRequireViewAccess covers both new endpoints, TestRepository_RawDiff covers Base, and TestRepository_CatFileCommit covers a missing full-length ID (it fails without the fix). moon run gogs:lint and moon run web:lint report 0 issues.
  2. Ran a -tags prod build with SQLite. Seed: alice owns the public widgets and the private secret. bob can read secret, and carol has no access.
  3. API: widgets compare returns the commits newest first. .diff returns the raw diff, also with ?whitespace=ignore-all. A missing SHA on either side gets 404 on both endpoints. carol gets 404 on secret, and bob gets 200. /compare/master...master still reaches the legacy pull request compare page.
  4. Browser, at 1280, dark and 375: compared a 2-commit and a 1-commit range, switched to split (?style=split), and expanded all lines of long.go, which fetched /raw/{before}/… and /raw/{after}/…. Opened an equal range and an unknown SHA (404). Rechecked the commit page: split mode, collapse and expand all, and line expansion against the parent. No sideways scroll at 375.
  5. Rebased on main after web: migrate the repository commit history pages to React #8533, rebuilt with -tags prod and rechecked in the browser. The compare page shows "2 commits 6a7956f...09880f1" with 5 files, +7 and -4, matching git diff --stat -M. "Expand all lines" on long.go fetched /raw/{before}/long.go and /raw/{after}/long.go with 200, and search in diff jumps to the change. .diff is text/plain, an equal range shows "No commits found", and an unknown SHA gets 404 from the API and .diff. With the repository private, signed out and bob get 404 from the API and .diff, and alice gets 200. scrollWidth is 375 at 375px. The commit page still shows "3 changed files" in unified and split.
  6. Long range: pushed a long-history branch with 300 commits. TestCompareRange_ListCommits covers 51, 50 and 3 commits and the push of the default branch, and fails without the cap. The API returns 50 commits, newest first, with totalCommits 300, for both {base}...{tip} and the empty ID. Listing 250 commits took 10s before the cat-file --batch change and 0.2s after, and the commit history API also takes 0.2s. In the browser, the heading says "300 commits" and the list shows 10 commits and "Show 40 more commits". Clicking it shows 50 and the cut-off note, and "View the full history" opens /commits/{tip}. The 2-commit range shows no button and no note. scrollWidth is 375 at 375px.
  7. Compact rows: no day headings on the compare page, and the commit history keeps them. Each row is 43px, with the title and the author vertically centered, at 1280 and 55px at 375, and the commit history rows are unchanged. A 200-character title is cut off with an ellipsis and the row stays one line. The SHA links to the commit page, and the 2-commit range shows alice and bob. Checked in dark mode, and scrollWidth is 375 at 375px.

unknwon added a commit that referenced this pull request Nov 13, 2026
@unknwon
unknwon added this pull request to stack #8457 November 13, 2026 13:51
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from 2bd0113 to a1f3d6b Compare November 14, 2026 05:43
@unknwon
unknwon force-pushed the compare-react-flamego branch 3 times, most recently from d71211d to f762988 Compare November 14, 2026 13:23
@unknwon
unknwon force-pushed the compare-react-flamego branch 3 times, most recently from 9a6998a to 55dd177 Compare November 14, 2026 17:11
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from 6e317a2 to 9850d91 Compare November 14, 2026 19:00
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from c1366fa to f7efb35 Compare November 14, 2026 19:34
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from 4ae184d to 93a531d Compare November 14, 2026 20:21
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from 2fae4eb to ae8bda3 Compare November 14, 2026 21:47
@unknwon
unknwon force-pushed the compare-react-flamego branch 3 times, most recently from afcedfd to 39f48c8 Compare November 14, 2026 23:00
@unknwon
unknwon force-pushed the compare-react-flamego branch 6 times, most recently from 61df07b to 6e192af Compare November 15, 2026 22:18
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from 2552c00 to ed6df3d Compare November 16, 2026 00:46
@unknwon
unknwon force-pushed the compare-react-flamego branch 2 times, most recently from ac33d0b to af070cb Compare November 16, 2026 02:24
@unknwon
unknwon force-pushed the compare-react-flamego branch from af070cb to 6cae75a Compare November 16, 2026 03:07
Base automatically changed from commits-react-flamego to main November 16, 2026 03:48
@unknwon
unknwon marked this pull request as ready for review November 16, 2026 03:48
@unknwon
unknwon force-pushed the compare-react-flamego branch from 6cae75a to aa4b843 Compare November 16, 2026 03:52
The commit page keeps its header and renders DiffWorkspace, which takes the
patch with the old and new revisions, so other pages can show a diff the
same way. The commit page does not change.
The comparison of two commits, e.g., of a push in the activity feed, is now
a React page backed by /api/web/{owner}/{repo}/compare/{before}...{after}.
It lists the commits in the range and shows the diff in DiffWorkspace, the
same view as the commit page, with the raw diff served at the same path
with a ".diff" suffix.

Looking up a full-length commit ID that does not exist now reports the
revision as missing instead of failing, so such links return 404.
Log and RevList started two git processes for every commit they list,
which takes seconds for a few hundred commits.
The heading counts every commit, the list shows the first 10 until
"Show more", and a cut-off list links to the full history.
The compare page is mostly read for its diff, so each commit takes one
line with its author, time and SHA, as on GitHub.
@unknwon
unknwon force-pushed the compare-react-flamego branch from f0fc805 to 1be923d Compare November 16, 2026 04:49
@unknwon
unknwon merged commit ffe0387 into main Nov 16, 2026
12 checks passed
@unknwon
unknwon deleted the compare-react-flamego branch November 16, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant