Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs to git scc provider. #60048

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions extensions/git/src/api/api1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Model } from '../model';
import { Repository as BaseRepository, Resource } from '../repository';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit, Change, RepositoryUIState } from './git';
import { InputBox, Git, API, Repository, Remote, RepositoryState, Branch, Ref, Submodule, Commit, Change, RepositoryUIState, Status } from './git';
import { Event, SourceControlInputBox, Uri, SourceControl } from 'vscode';
import { mapEvent } from '../util';

Expand All @@ -17,7 +17,23 @@ class ApiInputBox implements InputBox {

export class ApiChange implements Change {

constructor(_resource: Resource) { }
constructor(private readonly resource: Resource) { }

public get resourceUri(): Uri {
return this.resource.resourceUri;
}

public get status(): Status {
return this.resource.type;
}

public get original(): Uri {
return this.resource.original;
}

public get renameResourceUri(): Uri | undefined {
return this.resource.renameResourceUri;
}
}

export class ApiRepositoryState implements RepositoryState {
Expand Down Expand Up @@ -79,6 +95,14 @@ export class ApiRepository implements Repository {
return this._repository.getObjectDetails(treeish, path);
}

detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }> {
return this._repository.detectObjectType(object);
}

buffer(ref: string, filePath: string): Promise<Buffer> {
return this._repository.buffer(ref, filePath);
}

diffWithHEAD(path: string): Promise<string> {
return this._repository.diffWithHEAD(path);
}
Expand Down Expand Up @@ -150,6 +174,10 @@ export class ApiRepository implements Repository {
pull(): Promise<void> {
return this._repository.pull();
}

clean(filePaths: string[]) {
return this._repository.clean(filePaths.map(p => Uri.file(p)));
}
}

export class ApiGit implements Git {
Expand Down
30 changes: 29 additions & 1 deletion extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,32 @@ export interface Remote {
readonly isReadOnly: boolean;
}

export const enum Status {
INDEX_MODIFIED,
INDEX_ADDED,
INDEX_DELETED,
INDEX_RENAMED,
INDEX_COPIED,

MODIFIED,
DELETED,
UNTRACKED,
IGNORED,

ADDED_BY_US,
ADDED_BY_THEM,
DELETED_BY_US,
DELETED_BY_THEM,
BOTH_ADDED,
BOTH_DELETED,
BOTH_MODIFIED
}

export interface Change {
// TODO
readonly resourceUri: Uri;
readonly status: Status;
readonly original: Uri;
readonly renameResourceUri: Uri | undefined;
}

export interface RepositoryState {
Expand Down Expand Up @@ -93,6 +117,8 @@ export interface Repository {
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string, object: string, size: number }>;
detectObjectType(object: string): Promise<{ mimetype: string, encoding?: string }>;
buffer(ref: string, filePath: string): Promise<Buffer>;

diffWithHEAD(path: string): Promise<string>;
diffWith(ref: string, path: string): Promise<string>;
Expand All @@ -118,6 +144,8 @@ export interface Repository {

fetch(remote?: string, ref?: string): Promise<void>;
pull(): Promise<void>;

clean(filePaths: string[]): Promise<void>;
}

export interface API {
Expand Down
4 changes: 2 additions & 2 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Uri, commands, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn, ProgressLocation, TextEditor, MessageOptions, WorkspaceFolder } from 'vscode';
import { Git, CommitOptions, Stash, ForcePushMode } from './git';
import { Repository, Resource, Status, ResourceGroupType } from './repository';
import { Repository, Resource, ResourceGroupType } from './repository';
import { Model } from './model';
import { toGitUri, fromGitUri } from './uri';
import { grep, isDescendant, pathEquals } from './util';
Expand All @@ -15,7 +15,7 @@ import { lstat, Stats } from 'fs';
import * as os from 'os';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
import { Ref, RefType, Branch, GitErrorCodes } from './api/git';
import { Ref, RefType, Branch, GitErrorCodes, Status } from './api/git';

const localize = nls.loadMessageBundle();

Expand Down
4 changes: 2 additions & 2 deletions extensions/git/src/decorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { window, workspace, Uri, Disposable, Event, EventEmitter, DecorationData, DecorationProvider, ThemeColor } from 'vscode';
import * as path from 'path';
import { Repository, GitResourceGroup, Status } from './repository';
import { Repository, GitResourceGroup } from './repository';
import { Model } from './model';
import { debounce } from './decorators';
import { filterEvent, dispose, anyEvent, fireEvent } from './util';
import { GitErrorCodes } from './api/git';
import { GitErrorCodes, Status } from './api/git';

type Callback = { resolve: (status: boolean) => void, reject: (err: any) => void };

Expand Down
34 changes: 9 additions & 25 deletions extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as path from 'path';
import * as nls from 'vscode-nls';
import * as fs from 'fs';
import { StatusBarCommands } from './statusbar';
import { Branch, Ref, Remote, RefType, GitErrorCodes } from './api/git';
import { Branch, Ref, Remote, RefType, GitErrorCodes, Status } from './api/git';

const timeout = (millis: number) => new Promise(c => setTimeout(c, millis));

Expand All @@ -29,27 +29,6 @@ export const enum RepositoryState {
Disposed
}

export const enum Status {
INDEX_MODIFIED,
INDEX_ADDED,
INDEX_DELETED,
INDEX_RENAMED,
INDEX_COPIED,

MODIFIED,
DELETED,
UNTRACKED,
IGNORED,

ADDED_BY_US,
ADDED_BY_THEM,
DELETED_BY_US,
DELETED_BY_THEM,
BOTH_ADDED,
BOTH_DELETED,
BOTH_MODIFIED
}

export const enum ResourceGroupType {
Merge,
Index,
Expand Down Expand Up @@ -104,7 +83,7 @@ export class Resource implements SourceControlResourceState {
}
};

private getIconPath(theme: string): Uri {
private getIconPath(theme: string): Uri | undefined {
switch (this.type) {
case Status.INDEX_MODIFIED: return Resource.Icons[theme].Modified;
case Status.MODIFIED: return Resource.Icons[theme].Modified;
Expand All @@ -122,6 +101,7 @@ export class Resource implements SourceControlResourceState {
case Status.DELETED_BY_US: return Resource.Icons[theme].Conflict;
case Status.BOTH_ADDED: return Resource.Icons[theme].Conflict;
case Status.BOTH_MODIFIED: return Resource.Icons[theme].Conflict;
default: return;
}
}

Expand Down Expand Up @@ -180,7 +160,7 @@ export class Resource implements SourceControlResourceState {
return { strikeThrough, faded, tooltip, light, dark, letter, color, source: 'git.resource' /*todo@joh*/ };
}

get letter(): string {
get letter(): string | undefined {
switch (this.type) {
case Status.INDEX_MODIFIED:
case Status.MODIFIED:
Expand All @@ -207,10 +187,12 @@ export class Resource implements SourceControlResourceState {
case Status.BOTH_ADDED:
case Status.BOTH_MODIFIED:
return 'C';
default:
return;
}
}

get color(): ThemeColor {
get color(): ThemeColor | undefined {
switch (this.type) {
case Status.INDEX_MODIFIED:
case Status.MODIFIED:
Expand All @@ -234,6 +216,8 @@ export class Resource implements SourceControlResourceState {
case Status.BOTH_ADDED:
case Status.BOTH_MODIFIED:
return new ThemeColor('gitDecoration.conflictingResourceForeground');
default:
return;
}
}

Expand Down