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

feat(search): Make search aware of perforce changelist id mapping#63563

Merged
mmanela merged 23 commits into
mainfrom
mmanela-splf-116-perforce-searching-by-perforce-changelist-id
Jul 9, 2024
Merged

feat(search): Make search aware of perforce changelist id mapping#63563
mmanela merged 23 commits into
mainfrom
mmanela-splf-116-perforce-searching-by-perforce-changelist-id

Conversation

@mmanela

@mmanela mmanela commented Jun 29, 2024

Copy link
Copy Markdown
Contributor

https://linear.app/sourcegraph/issue/SPLF-116/perforce-searching-by-perforce-changelist-id

Details

We have had requests from our customers using Perforce to be able to search inside of a changelist id. For a commit sha we support doing this

context:global repo:^perforce-sgdev-org/rhia-depot-test$@345c17c` some text

But for perforce they want to do the same thing but with the change list ids. Which would look like this

context:global repo:^perforce-sgdev-org/rhia-depot-test$@changelist/83732` some text

To support this, I am attempting to smartly detect when we should do a DB round trip and look up the proper mapping. I built a simple heuristic that is

  1. Is perforce changelist mapping feature flag enabled
  2. Is this a perforce repo?
  3. Is the revision request a integer ?

This mapping is just a best effort, if it fails it just falls back on current behavior.

We are doing with a syntax of @changelist/CL_ID instead of supporting @CL_ID to future proof us. This lookup focuses on finding the mapping in the DB but in the future we may want to pre-create these refs in the db duing mapping of perforce CLs to git commits.

Limitations

This works well in testing however, the repo name@changelist/rev we return contains the sha
image

I investigated changing this but it would required a larger change in resolving the stream results. While that would be nice to have, I decided to keep this minimal for now and add that later if needed

Test plan

  • added unit tests
  • manually test both with and without perforce enabled and with and without shas and change list ids

Changelog

  • For perforce depots, support searching within a specific changelist by specifying a ref like context:global repo:^repo/name$@changelist/83854

@cla-bot cla-bot Bot added the cla-signed label Jun 29, 2024
@mmanela mmanela changed the title WIP: Make search aware of perforce changelist id mapping RFC: Make search aware of perforce changelist id mapping Jun 29, 2024

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not a search expert - so leaving the real review to someone else. but this seems like a nice low-level integration to me

left a few suggestions/considerations inline

Comment thread internal/search/repos/repos.go Outdated
Comment thread internal/search/repos/repos.go Outdated
Comment thread internal/search/repos/repos.go Outdated

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks very reasonable to me and doesn't feel too messy. The repo resolver is the central place in search where we interpret the repository specifications in the query. We will need good test coverage though, this is core code and there may be subtle interactions!

A couple high-level comments:

  • I'd prefer simpler semantics for the translation: if the changelist ID mapping feature is enabled, then all revisions in queries should be interpreted as changelists. If they cannot be, then we fail with a clear error like "invalid changelist ID". Our goal would be for end users not to be aware of the changelist ID -> commit hash mapping. What do you think?
  • We should double-check this interacts okay with Zoekt's repo partitioning and other downstream revision logic. It looks fine to me, just something to be aware of!

Comment thread internal/search/repos/repos.go Outdated
@mmanela mmanela marked this pull request as ready for review July 8, 2024 16:45

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

General comment: is this the right layer to handle this?

My thinking is: what if we handled this with git refs during perforce -> git translation? If a changelist really does just resolve to a commit, couldn't we just create a symbolic "refs/changelists/80132"? That feels less risky to me than trying to add perforce emulation back on top of our git translation.

Comment thread internal/search/repos/repos.go Outdated
Comment thread internal/database/repo_commits_changelists.go Outdated
@jtibshirani

Copy link
Copy Markdown
Contributor

My thinking is: what if we handled this with git refs during perforce -> git translation?

This is a good question -- I believe we discussed this offline, but would be good to document the reasoning here!

@mmanela mmanela changed the title RFC: Make search aware of perforce changelist id mapping feat(search): Make search aware of perforce changelist id mapping Jul 8, 2024

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me. I left a few small comments.

Comment thread .vscode/settings.json
Comment thread internal/search/repos/repos.go Outdated
Comment thread internal/types/types.go
Comment thread internal/search/repos/repos.go Outdated

@jtibshirani jtibshirani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

GetRepoCommitChangelist(ctx context.Context, repoID api.RepoID, changelistID int64) (*types.RepoCommit, error)

// GetRepoCommitChangelistBatch bulk loads repo commits for given repo ids and changelistIds
GetRepoCommitChangelistBatch(ctx context.Context, rcs ...RepoChangelistIDs) (map[api.RepoID]map[int64]*types.RepoCommit, error)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tiny thing I noticed: It looks like our naming standard is to use Batch at the start as in BatchInsertCommitSHAsWithPerforceChangelistID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will change

Comment thread internal/search/repos/repos.go Outdated
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