Add support for self-hosted GitLab instances for Git permalinks (#19909)

This PR adds support for self-hosted GitLab instances when generating
Git permalinks.

If the `origin` Git remote contains `gitlab` in the URL hostname we will
then attempt to register it as a self-hosted GitLab instance.

A note on this: I don't think relying on specific keywords is going to
be a suitable long-term solution to detection. In reality the
self-hosted instance could be hosted anywhere (e.g.,
`vcs.my-company.com`), so we will ultimately need a way to have the user
indicate which Git provider they are using (perhaps via a setting).

Closes https://github.com/zed-industries/zed/issues/18012.

Release Notes:

- Added support for self-hosted GitLab instances when generating Git
permalinks.
- The instance URL must have `gitlab` somewhere in the host in order to
be recognized.
This commit is contained in:
Marshall Bowers 2024-10-29 12:31:51 -04:00 committed by GitHub
parent 3e2f1d733c
commit 322aa41ad6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 142 additions and 23 deletions

View file

@ -29,6 +29,7 @@ fs.workspace = true
futures.workspace = true
fuzzy.workspace = true
git.workspace = true
git_hosting_providers.workspace = true
gpui.workspace = true
ignore.workspace = true
language.workspace = true

View file

@ -19,6 +19,7 @@ use futures::{
FutureExt as _, Stream, StreamExt,
};
use fuzzy::CharBag;
use git::GitHostingProviderRegistry;
use git::{
repository::{GitFileStatus, GitRepository, RepoPath},
status::GitStatus,
@ -299,6 +300,7 @@ struct BackgroundScannerState {
removed_entries: HashMap<u64, Entry>,
changed_paths: Vec<Arc<Path>>,
prev_snapshot: Snapshot,
git_hosting_provider_registry: Option<Arc<GitHostingProviderRegistry>>,
}
#[derive(Debug, Clone)]
@ -1004,6 +1006,7 @@ impl LocalWorktree {
let share_private_files = self.share_private_files;
let next_entry_id = self.next_entry_id.clone();
let fs = self.fs.clone();
let git_hosting_provider_registry = GitHostingProviderRegistry::try_global(cx);
let settings = self.settings.clone();
let (scan_states_tx, mut scan_states_rx) = mpsc::unbounded();
let background_scanner = cx.background_executor().spawn({
@ -1039,6 +1042,7 @@ impl LocalWorktree {
paths_to_scan: Default::default(),
removed_entries: Default::default(),
changed_paths: Default::default(),
git_hosting_provider_registry,
}),
phase: BackgroundScannerPhase::InitialScan,
share_private_files,
@ -2948,6 +2952,13 @@ impl BackgroundScannerState {
log::trace!("constructed libgit2 repo in {:?}", t0.elapsed());
let work_directory = RepositoryWorkDirectory(work_dir_path.clone());
if let Some(git_hosting_provider_registry) = self.git_hosting_provider_registry.clone() {
git_hosting_providers::register_additional_providers(
git_hosting_provider_registry,
repository.clone(),
);
}
self.snapshot.repository_entries.insert(
work_directory.clone(),
RepositoryEntry {