Skip to content

repo: compare a created branch against where it forked - #8510

Merged
unknwon merged 7 commits into
mainfrom
jc/compare-unknown-base
Nov 13, 2026
Merged

unknwon merged 7 commits into
mainfrom
jc/compare-unknown-base

Conversation

@unknwon

@unknwon unknwon commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

When a mirror sync creates a branch, its "Compare N commits" link in the news feed points to compare/0000000...<sha>, and opening it returns a 500 with fatal: bad object 0000000000000000000000000000000000000000. This also happens on main.

  • The compare page treats an empty base ID, of either object format, as the merge base of the head and the default branch, so it shows the commits and changes the branch adds. When the head adds nothing to the default branch (e.g., it is the default branch) or they share no history (e.g., an orphan branch, or a default branch that does not exist), it compares against the empty tree and lists every commit of the head. The base label of that compare is not linked, since the empty tree is not a commit.
  • CatFileCommit returns ErrRevisionNotExist when git cat-file reports a bad file, i.e., the object does not exist or is not a commit. Other failures, e.g., an unreadable repository, are still errors. git rev-parse passes a full-length ID through without checking that the object exists, so an unknown 40- or 64-character ID used to surface as a raw Git error. The compare page checks its base commit as well as its head, so an unknown base or head renders as not found.
  • A branch created by a mirror sync records the same commits in the news feed, so "Compare N commits" matches the compare page. It used to record up to 10 of its latest commits, including ones from the default branch.
  • The new 500 errors of the compare page are logged in the handler.

Link to the issue: n/a

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 or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  • TestObjectFormat_EmptyTreeID checks both empty tree IDs against git hash-object -t tree. TestRepository_CatFileCommit expects ErrRevisionNotExist for the empty ID, an unknown full-length ID and a tree ID, and fails without the fix.

  • In a prod build on SQLite with Git 2.55, a mirror of a repository with main (3 commits) synced three new branches, recording feed entries that link to compare/0000000...<head>:

    Branch Before After
    feature, 2 commits on top of main~1 500 200, feature commit 1 and 2, feat.txt only
    orphan, 2 commits with no shared history 500 200, both commits, o.txt added
    same, at the head of main 500 200, nothing to compare
    Unknown base or head 500 404

    In a SHA-256 repository, a 64- and a 40-character empty base both resolve to the merge base with main, and an orphan branch compares against the SHA-256 empty tree.

  • On SQLite, the compare page of an orphan branch against the empty ID shows the empty tree base as a plain label, and the head as a link. A forked branch still links both.

  • With an unreadable objects directory, git cat-file exits 128 with "not a git repository" instead of "bad file", so it is no longer mistaken for a missing revision.

  • On SQLite, the first push to an empty mirror recorded all 3 commits of main, and so did a branch created at its head. Their compare pages list the same 3.

  • On SQLite, a mirror synced two new branches. feature2, 2 commits on top of main~1, recorded 2 commits in the feed, and its compare page lists 2. orphan2, 12 commits with no shared history, recorded a count of 12 and kept the latest 5 for display, and its compare page lists 12.

  • Tests under ./internal/... and ./cmd/... pass, and lint is clean.

Screenshots

New branch from a mirror sync, compared against where it forked from main:

Compare page of a new mirrored branch listing its two commits and the diff of feat.txt

Orphan branch, compared against the empty tree:

Compare page of an orphan branch listing its two commits and the diff adding o.txt

AI usage

Claude Code

@unknwon unknwon changed the title repo, database: return 404 for compare URLs with an unknown base repo: compare a created branch against where it forked Nov 12, 2026
unknwon added a commit that referenced this pull request Nov 12, 2026
unknwon added a commit that referenced this pull request Nov 12, 2026
@unknwon
unknwon force-pushed the jc/compare-unknown-base branch from a7a83d2 to 0c80750 Compare November 12, 2026 03:59
@unknwon
unknwon changed the base branch from jc/internal-git-sha256 to jc/internal-git-functional-options November 12, 2026 03:59
@unknwon
unknwon added this pull request to stack #8442 November 12, 2026 04:00
@unknwon
unknwon deleted the branch jc/internal-git-functional-options November 12, 2026 23:22
@unknwon unknwon closed this Nov 12, 2026
@unknwon
unknwon removed this pull request from stack #8442 November 12, 2026 23:24
@unknwon unknwon reopened this Nov 12, 2026
@unknwon
unknwon changed the base branch from jc/internal-git-functional-options to jc/internal-git-hook-tracing November 12, 2026 23:27
@unknwon
unknwon added this pull request to stack #8522 November 12, 2026 23:29
@unknwon
unknwon force-pushed the jc/compare-unknown-base branch from 0c80750 to e467f33 Compare November 12, 2026 23:29
@unknwon
unknwon force-pushed the jc/compare-unknown-base branch from e467f33 to 02cc21a Compare November 13, 2026 02:00
Base automatically changed from jc/internal-git-hook-tracing to main November 13, 2026 02:26
A mirror sync that creates a branch recorded a compare URL from the
empty ID, so the "Compare N commits" link in the news feed led to a
500 with "fatal: bad object 0000000...". MirrorSyncPush now leaves the
compare URL empty for new references, as CommitRepo already does.

CatFileCommit returns ErrRevisionNotExist for a full-length object ID
that does not exist, and the compare page checks its base commit, so
links already recorded with the empty ID and any other unknown base
or head render as not found instead of a server error.
The compare page treats an empty base ID, which the news feed links to
for a branch created by a mirror sync, as the merge base of the branch
and the default branch. When they share no history, it compares against
the empty tree and lists every commit of the branch. MirrorSyncPush
keeps recording the compare URL for new references, so the link shows
what the branch adds instead of a 404.
@unknwon
unknwon force-pushed the jc/compare-unknown-base branch from 02cc21a to 7996a21 Compare November 13, 2026 02:27
The base of a compare against the empty tree is not a commit, so its
label linked to a commit page that does not exist.

CatFileCommit only reports a revision as not existing when Git says the
object is a bad file, so other failures, e.g., an unreadable repository,
are still reported as errors.
A branch created by a mirror sync recorded up to 10 of its latest commits
in the news feed, including ones from the default branch, so the feed
did not match the compare page it links to. It now records the commits
since the branch forked from the default branch, or all of its commits
when they share no history, with the count of all of them.

The compare page logs its new 500 errors where they happen.
Comment thread internal/database/mirror.go Fixed
ᴜɴᴋɴᴡᴏɴ and others added 2 commits November 12, 2026 21:58
A mirror sync that created the default branch, e.g., the first push to
an empty mirror, recorded no commits, because the branch is its own merge
base with the default branch. Such a branch, or one at the head of the
default branch, now records all of its commits, and its compare page
shows them against the empty tree.
@unknwon
unknwon merged commit 7e9b946 into main Nov 13, 2026
11 checks passed
@unknwon
unknwon deleted the jc/compare-unknown-base branch November 13, 2026 03:14
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.

2 participants