提交 acb83d00 编写于 作者: J Joao Moreno

remove Resource from git model method interfaces

上级 b9eb8bae
......@@ -145,9 +145,9 @@ export class CommandCenter {
});
}
private groupByModel(resources: Resource[]): [Model | undefined, Resource[]][] {
private groupByModel(resources: Uri[]): [Model | undefined, Uri[]][] {
return resources.reduce((result, resource) => {
const model = this.modelRegistry.getModel(resource.resourceUri);
const model = this.modelRegistry.getModel(resource);
const pair = result.filter(p => p[0] === model)[0];
if (pair) {
......@@ -157,7 +157,7 @@ export class CommandCenter {
}
return result;
}, [] as [Model | undefined, Resource[]][]);
}, [] as [Model | undefined, Uri[]][]);
}
@command('git.refresh', { model: true })
......@@ -442,16 +442,19 @@ export class CommandCenter {
resourceStates = [resource];
}
const resources = resourceStates
const scmResources = resourceStates
.filter(s => s instanceof Resource && (s.resourceGroup instanceof WorkingTreeGroup || s.resourceGroup instanceof MergeGroup)) as Resource[];
if (!resources.length) {
if (!scmResources.length) {
return;
}
await Promise.all(this.groupByModel(resources).map(async ([model, resources]) => {
const resources = scmResources.map(r => r.resourceUri);
const resourcesByModel = this.groupByModel(resources);
await Promise.all(resourcesByModel.map(async ([model, resources]) => {
if (!model) {
return;
return; // TODO@joao
}
await model.add(...resources);
......@@ -553,13 +556,15 @@ export class CommandCenter {
resourceStates = [resource];
}
const resources = resourceStates
const scmResources = resourceStates
.filter(s => s instanceof Resource && s.resourceGroup instanceof IndexGroup) as Resource[];
if (!resources.length) {
if (!scmResources.length) {
return;
}
const resources = scmResources.map(r => r.resourceUri);
return await model.revertFiles(...resources);
}
......@@ -620,14 +625,15 @@ export class CommandCenter {
}
const resources = resourceStates
.filter(s => s instanceof Resource && s.resourceGroup instanceof WorkingTreeGroup) as Resource[];
.filter(s => s instanceof Resource && s.resourceGroup instanceof WorkingTreeGroup)
.map(r => r.resourceUri);
if (!resources.length) {
return;
}
const message = resources.length === 1
? localize('confirm discard', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].resourceUri.fsPath))
? localize('confirm discard', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].fsPath))
: localize('confirm discard multiple', "Are you sure you want to discard changes in {0} files?", resources.length);
const yes = localize('discard', "Discard Changes");
......@@ -650,7 +656,7 @@ export class CommandCenter {
return;
}
await model.clean(...model.workingTreeGroup.resources);
await model.clean(...model.workingTreeGroup.resources.map(r => r.resourceUri));
}
private async smartCommit(
......
......@@ -7,7 +7,7 @@
import { Uri, Command, EventEmitter, Event, SourceControlResourceState, SourceControlResourceDecorations, Disposable, ProgressLocation, window, workspace, WorkspaceEdit } from 'vscode';
import { Git, Repository, Ref, Branch, Remote, Commit, GitErrorCodes } from './git';
import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose } from './util';
import { anyEvent, eventToPromise, filterEvent, EmptyDisposable, combinedDisposable, dispose, find } from './util';
import { memoize, throttle, debounce } from './decorators';
import * as path from 'path';
import * as nls from 'vscode-nls';
......@@ -397,8 +397,8 @@ export class Model implements Disposable {
await this.run(Operation.Status);
}
async add(...resources: Resource[]): Promise<void> {
await this.run(Operation.Add, () => this.repository.add(resources.map(r => r.resourceUri.fsPath)));
async add(...resources: Uri[]): Promise<void> {
await this.run(Operation.Add, () => this.repository.add(resources.map(r => r.fsPath)));
}
async stage(uri: Uri, contents: string): Promise<void> {
......@@ -406,8 +406,8 @@ export class Model implements Disposable {
await this.run(Operation.Stage, () => this.repository.stage(relativePath, contents));
}
async revertFiles(...resources: Resource[]): Promise<void> {
await this.run(Operation.RevertFiles, () => this.repository.revertFiles('HEAD', resources.map(r => r.resourceUri.fsPath)));
async revertFiles(...resources: Uri[]): Promise<void> {
await this.run(Operation.RevertFiles, () => this.repository.revertFiles('HEAD', resources.map(r => r.fsPath)));
}
async commit(message: string, opts: CommitOptions = Object.create(null)): Promise<void> {
......@@ -420,20 +420,27 @@ export class Model implements Disposable {
});
}
async clean(...resources: Resource[]): Promise<void> {
async clean(...resources: Uri[]): Promise<void> {
await this.run(Operation.Clean, async () => {
const toClean: string[] = [];
const toCheckout: string[] = [];
resources.forEach(r => {
switch (r.type) {
const raw = r.toString();
const scmResource = find(this.workingTreeGroup.resources, sr => sr.resourceUri.toString() === raw);
if (!scmResource) {
return;
}
switch (scmResource.type) {
case Status.UNTRACKED:
case Status.IGNORED:
toClean.push(r.resourceUri.fsPath);
toClean.push(r.fsPath);
break;
default:
toCheckout.push(r.resourceUri.fsPath);
toCheckout.push(r.fsPath);
break;
}
});
......
......@@ -162,4 +162,19 @@ export function uniqueFilter<T>(keyFn: (t: T) => string): (t: T) => boolean {
seen[key] = true;
return true;
};
}
export function find<T>(array: T[], fn: (t: T) => boolean): T | undefined {
let result: T | undefined = undefined;
array.some(e => {
if (fn(e)) {
result = e;
return true;
}
return false;
});
return result;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册