Improve layering for git model (#272857)

* Improve layering for git model
- Git clone doesn't belong in the model, removed it
- All the extra repo picking didn't seem to fit into `Git` though, as that is really about git operations
- Added a `CloneUtils` namespace for all the clone stuff to live.

* Update extensions/git/src/clone.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* CloneManager class

* public/private
This commit is contained in:
Alex Ross
2025-10-23 16:04:35 +02:00
committed by GitHub
parent 43ce6485c5
commit 3cc447e709
6 changed files with 296 additions and 257 deletions

View File

@@ -15,6 +15,7 @@ import { GitExtensionImpl } from './extension';
import { GitBaseApi } from '../git-base';
import { PickRemoteSourceOptions } from '../typings/git-base';
import { OperationKind, OperationResult } from '../operation';
import { CloneManager } from '../cloneManager';
class ApiInputBox implements InputBox {
#inputBox: SourceControlInputBox;
@@ -331,10 +332,12 @@ export class ApiGit implements Git {
export class ApiImpl implements API {
#model: Model;
#cloneManager: CloneManager;
readonly git: ApiGit;
constructor(model: Model) {
this.#model = model;
constructor(privates: { model: Model; cloneManager: CloneManager }) {
this.#model = privates.model;
this.#cloneManager = privates.cloneManager;
this.git = new ApiGit(this.#model);
}
@@ -401,7 +404,7 @@ export class ApiImpl implements API {
async clone(uri: Uri, options?: CloneOptions): Promise<Uri | null> {
const parentPath = options?.parentPath?.fsPath;
const result = await this.#model.clone(uri.toString(), { parentPath, recursive: options?.recursive, ref: options?.ref, postCloneAction: options?.postCloneAction, skipCache: options?.skipCache });
const result = await this.#cloneManager.clone(uri.toString(), { parentPath, recursive: options?.recursive, ref: options?.ref, postCloneAction: options?.postCloneAction, skipCache: options?.skipCache });
return result ? Uri.file(result) : null;
}

View File

@@ -7,6 +7,7 @@ import { Model } from '../model';
import { GitExtension, Repository, API } from './git';
import { ApiRepository, ApiImpl } from './api1';
import { Event, EventEmitter } from 'vscode';
import { CloneManager } from '../cloneManager';
function deprecated(original: any, context: ClassMemberDecoratorContext) {
if (context.kind !== 'method') {
@@ -28,6 +29,7 @@ export class GitExtensionImpl implements GitExtension {
readonly onDidChangeEnablement: Event<boolean> = this._onDidChangeEnablement.event;
private _model: Model | undefined = undefined;
private _cloneManager: CloneManager | undefined = undefined;
set model(model: Model | undefined) {
this._model = model;
@@ -46,10 +48,15 @@ export class GitExtensionImpl implements GitExtension {
return this._model;
}
constructor(model?: Model) {
if (model) {
set cloneManager(cloneManager: CloneManager | undefined) {
this._cloneManager = cloneManager;
}
constructor(privates?: { model: Model; cloneManager: CloneManager }) {
if (privates) {
this.enabled = true;
this._model = model;
this._model = privates.model;
this._cloneManager = privates.cloneManager;
}
}
@@ -72,7 +79,7 @@ export class GitExtensionImpl implements GitExtension {
}
getAPI(version: number): API {
if (!this._model) {
if (!this._model || !this._cloneManager) {
throw new Error('Git model not found');
}
@@ -80,6 +87,6 @@ export class GitExtensionImpl implements GitExtension {
throw new Error(`No API version ${version} found.`);
}
return new ApiImpl(this._model);
return new ApiImpl({ model: this._model, cloneManager: this._cloneManager });
}
}