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

Perforce Change List Number Support in URLs #40330

@ryphil

Description

@ryphil

Requested by: https://github.com/sourcegraph/accounts/issues/6716, https://github.com/sourcegraph/accounts/issues/583

Problem to solve

Perforce has the concept of changelists, which is analogous to git commit history but not exactly the same.

A Perforce changelist is a list of files, their revision numbers, and operations to be performed on these files.

Sourcegraph doesn't currently support changelists: instead, we convert everything into a git commit history. This breaks an expectation for Perforce users who use and rely on changelists. The changelist number functions the same as a git hash, but has slightly different properties. Currently, p4-fusion adds the changelist number to the commit message when we convert a Perforce change to a git commit. This preserves the mapping of git commit -> Perforce change, but is challenging for customers to query and use.

One particular customer use case:

They tightly integrate ChangeList Numbers with their code review process and often use ChangeList Numbers to navigate the code. They claim it would too severely interrupt their workflows by losing this number.

Another customer anecdoet:

Because a Perforce depot is converted to a Git repo, each Changelist is converted to a Git commit. In this process, the Changelist Number is effectively lost and instead a seemingly random Git hash is created in its place. This creates problems in DR scenarios or blue-green style deployments because the Git hash will get regenerated each time. So, permalinks are no longer permanent and users who have bookmarked pages will lose those bookmarks. This happened in a recent re-deployment to a new cluster. Many users' permalinks were no longer valid because the Perforce depot's git repo was re-created.

Measure of success

This issue will focus on adding support for Changelist Ids in Sourcegraph URLs. For example, instead of URLS in the format of https://sourcegraph.com/CODE-HOST/DEPOT-NAME/-/commit/42a19df7824e4c23bb6013b23acc361ba3208828, we want URLs in a format like https://sourcegraph.com/CODE-HOST/DEPOT-NAME/change/1234.

Permalink changes will follow with #50488.

UI changes (for example, to show wording like "changelist" instead of "commit") are covered in #46488.

Solution summary

Will probably need a database table containing mappings from changelist id to commit hash. The alternative is to use git log to find the commit with the changelist id in the message, which doesn't scale at all. The table will need to be repopulated on every clone; we'll need to figure out what index to use - probably code host name + depot name or whatever is in repositoryPathPattern. That's what's in the current URLs.

Artifacts:

  • TO DO
  • populate repo_commits table with mappings. Do the population after clone/fetch
  • set up a temporary cache in gitserver to use when the repo_commits table is not populated
  • write GQL API for use by the route handler to resolve CID to SHA so that the URLs /{repo}/-/changelist/12345 can be translated to commit SHAs
  • Write route handler to display pages for /{repo}/-/changelist/12345 URLs

/cc @ryphil

Metadata

Metadata

Assignees

Labels

estimate/12dfirst-class-perforceIssues associated with make Perforce a first class code hostperforceperforce-changelistsIssues around Changelist Ids for Perforce depotsperforce-improvementsLabel for the "Improved Perforce Support" tracking issue

Type

No type
No fields configured for issues without a type.

Projects

Status
✅ Done - Released (available to install)

Relationships

None yet

Development

No branches or pull requests

Issue actions