Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

web: navigate to file@commit instead of file@branch#58381

Merged
stefanhengl merged 6 commits intomainfrom
sh/navigate-to-commit-instead-of-head
Nov 20, 2023
Merged

web: navigate to file@commit instead of file@branch#58381
stefanhengl merged 6 commits intomainfrom
sh/navigate-to-commit-instead-of-head

Conversation

@stefanhengl
Copy link
Member

@stefanhengl stefanhengl commented Nov 16, 2023

With this change we always jump to blob@commit instead of blob@head if a user clicks on a search result. This avoids inconsistencies in line numbers if indexing lags behind repo syncing.

We keep the old logic, for displaying commit SHAs or branches on the search results page.

As a consequence

  • file URLs will contain the commit hash (see updated tests)
  • we will always display the commit hash (instead of the branch) at the top of the blob view, even if commit = HEAD.

image

While touching the code, I also refactored getRevision. I think the code is more readable now.

Test plan:

  • manual testing
    • for a couple of searches, I checked the commit returned by the Stream API and verified that it matches the commit ID of the blob we display.
  • updated test

@stefanhengl stefanhengl requested a review from fkling November 16, 2023 16:03
@cla-bot cla-bot bot added the cla-signed label Nov 16, 2023
@stefanhengl stefanhengl force-pushed the sh/navigate-to-commit-instead-of-head branch from a66d7b4 to 0269b6f Compare November 17, 2023 14:32
@stefanhengl stefanhengl requested a review from a team November 17, 2023 14:41
@stefanhengl stefanhengl marked this pull request as ready for review November 17, 2023 14:41
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Nov 17, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff 206a997...5c76ab1.

Notify File(s)
@fkling client/shared/src/search/stream.ts
client/web/src/search/results/export/searchResultsExport.test.ts

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Nov 17, 2023

📖 Storybook live preview

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is def changelog worthy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ain't know TS programmer but I think this can be shorted with the elvis operator:

Suggested change
if (branches && branches.length > 0) {
if (branches?.length > 0) {

Copy link
Member Author

@stefanhengl stefanhengl Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a TS programmer either, but I believe typescript doesn't let us compare "undefined" to a number literal, which would happen if branches is undefined.

Comment on lines 596 to 595
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should document why you don't use getRevision and maybe add a docstring to getRevision saying it prefers branches to version.

Also elvis comes to the party again (I think)

const revision = fileMatch.commit ?? fileMatch.branches?.[0]

Clicking on a search result might jump to the wrong line in the file if
HEAD on gitserver is ahead of the commit we indexed with Zoekt.

With this change we always jump to the commit of the search result we
display.

As a consequence
- file URLs will contain the commit hash
- we will always display the commit hash (instead of the branch) at the
top of the blob view, even if commit = HEAD.

While touching the code, I also refactored getRevision. I think the code
is more readable now.

Test plan:
- manual testing
@stefanhengl stefanhengl force-pushed the sh/navigate-to-commit-instead-of-head branch from 0269b6f to a063f1e Compare November 20, 2023 10:00
@stefanhengl
Copy link
Member Author

rebased to pull in latest CHANGELOG changes.

@stefanhengl stefanhengl merged commit e45c2ed into main Nov 20, 2023
@stefanhengl stefanhengl deleted the sh/navigate-to-commit-instead-of-head branch November 20, 2023 12:05
@jtibshirani
Copy link
Contributor

@stefanhengl I noticed some confusing behavior on S2 after this was merged. The search indexes are fully up-to-date, but clicking on a search result brings me to a specific commit SHA. I think this SHA actually represents HEAD (a commit only 2 hours ago), but our blob view claims this commit is from 3 days ago 🤔

Screenshot 2023-11-20 at 1 01 35 PM

@stefanhengl
Copy link
Member Author

stefanhengl commented Nov 21, 2023

That's expected, but admittedly confusing. With the change, we always show the SHA, even if it represents HEAD. The blob view shows the date (3 days ago) of the last commit that changed this file, not the date of the index. The commit message is shown next to it.

@stefanhengl
Copy link
Member Author

stefanhengl commented Nov 21, 2023

Suggestion: We add a little prefix "committed" or "authored" to the date, depending on whether we show the committer.date (default) or author.date (fallback). WDYT?

image

@jtibshirani
Copy link
Contributor

I see, thanks for the explanation! If I was confused, it's likely we'll have some confused users too! Could we avoid showing the hash if it's up-to-date? It feels best to maintain the previous "happy path" behavior that was clean and unsurprising.

vovakulikov pushed a commit that referenced this pull request Dec 12, 2023
With this change we always jump to blob@commit instead of blob@head if a user clicks on a search result. This avoids inconsistencies in line numbers if indexing lags behind repo syncing.

We keep the old logic, for displaying commit SHAs or branches on the search results page.

As a consequence
- file URLs will contain the commit hash (see updated tests)
- we will always display the commit hash (instead of the branch) at the top of the blob view, even if commit = HEAD.

While touching the code, I also refactored `getRevision`. I think the code is more readable now.

Test plan:
- manual testing
  - for a couple of searches, I checked the commit returned by the Stream API and verified that it matches the commit ID of the blob we display.  
- updated test
jtibshirani added a commit that referenced this pull request May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants