Browse Source

Unifies file status model

main
Eric Amodio 7 years ago
parent
commit
296e562d9f
6 changed files with 26 additions and 22 deletions
  1. +3
    -9
      src/git/models/logCommit.ts
  2. +14
    -2
      src/git/models/status.ts
  3. +3
    -3
      src/git/parsers/logParser.ts
  4. +2
    -2
      src/git/parsers/statusParser.ts
  5. +2
    -2
      src/quickPicks/gitQuickPicks.ts
  6. +2
    -4
      src/quickPicks/repoStatus.ts

+ 3
- 9
src/git/models/logCommit.ts View File

@ -1,21 +1,15 @@
'use strict';
import { Uri } from 'vscode';
import { GitCommit, IGitCommitLine } from './commit';
import { GitStatusFileStatus } from './status';
import { IGitStatusFile, GitStatusFileStatus } from './status';
import * as path from 'path';
export type GitLogType = 'file' | 'repo';
export interface IGitLogFileStatusEntry {
status: GitStatusFileStatus;
fileName: string;
originalFileName?: string;
}
export class GitLogCommit extends GitCommit {
fileNames: string;
fileStatuses: IGitLogFileStatusEntry[];
fileStatuses: IGitStatusFile[];
nextSha?: string;
nextFileName?: string;
parentShas: string[];
@ -30,7 +24,7 @@ export class GitLogCommit extends GitCommit {
date: Date,
message: string,
status?: GitStatusFileStatus,
fileStatuses?: IGitLogFileStatusEntry[],
fileStatuses?: IGitStatusFile[],
lines?: IGitCommitLine[],
originalFileName?: string,
previousSha?: string,

+ 14
- 2
src/git/models/status.ts View File

@ -1,4 +1,6 @@
'use strict';
import { Uri } from 'vscode';
import * as path from 'path';
export interface IGitStatus {
@ -16,17 +18,27 @@ export interface IGitStatus {
export declare type GitStatusFileStatus = '!' | '?' | 'A' | 'C' | 'D' | 'M' | 'R' | 'U';
export class GitStatusFile {
export interface IGitStatusFile {
status: GitStatusFileStatus;
fileName: string;
originalFileName?: string;
}
export class GitStatusFile implements IGitStatusFile {
originalFileName?: string;
constructor(public repoPath: string, public status: GitStatusFileStatus, public staged: boolean, public fileName: string, originalFileName?: string) {
constructor(public repoPath: string, public status: GitStatusFileStatus, public fileName: string, public staged: boolean, originalFileName?: string) {
this.originalFileName = originalFileName;
}
getIcon() {
return getGitStatusIcon(this.status);
}
get Uri(): Uri {
return Uri.file(path.resolve(this.repoPath, this.fileName));
}
}
const statusOcticonsMap = {

+ 3
- 3
src/git/parsers/logParser.ts View File

@ -1,6 +1,6 @@
'use strict';
import { Range } from 'vscode';
import { Git, GitStatusFileStatus, GitLogCommit, GitLogType, IGitAuthor, IGitLog, IGitLogFileStatusEntry } from './../git';
import { Git, GitStatusFileStatus, GitLogCommit, GitLogType, IGitAuthor, IGitLog, IGitStatusFile } from './../git';
// import { Logger } from '../../logger';
import * as moment from 'moment';
import * as path from 'path';
@ -18,7 +18,7 @@ interface ILogEntry {
fileName?: string;
originalFileName?: string;
fileStatuses?: IGitLogFileStatusEntry[];
fileStatuses?: IGitStatusFile[];
status?: GitStatusFileStatus;
@ -134,7 +134,7 @@ export class GitLogParser {
status: line[0] as GitStatusFileStatus,
fileName: line.substring(1),
originalFileName: undefined as string
} as IGitLogFileStatusEntry;
} as IGitStatusFile;
this._parseFileName(status);
entry.fileStatuses.push(status);

+ 2
- 2
src/git/parsers/statusParser.ts View File

@ -67,7 +67,7 @@ export class GitStatusParser {
else {
entry = this._parseFileEntry(rawStatus, fileName);
}
status.files.push(new GitStatusFile(repoPath, entry.status, entry.staged, entry.fileName, entry.originalFileName));
status.files.push(new GitStatusFile(repoPath, entry.status, entry.fileName, entry.staged, entry.originalFileName));
}
}
}
@ -115,7 +115,7 @@ export class GitStatusParser {
}
if (entry) {
status.files.push(new GitStatusFile(repoPath, entry.status, entry.staged, entry.fileName, entry.originalFileName));
status.files.push(new GitStatusFile(repoPath, entry.status, entry.fileName, entry.staged, entry.originalFileName));
}
}
}

+ 2
- 2
src/quickPicks/gitQuickPicks.ts View File

@ -1,6 +1,6 @@
'use strict';
import { QuickPickItem, Uri } from 'vscode';
import { getGitStatusIcon, Git, GitCommit, GitStatusFileStatus, GitService, GitUri, IGitLogFileStatusEntry } from '../gitService';
import { getGitStatusIcon, Git, GitCommit, GitStatusFileStatus, GitService, GitUri, IGitStatusFile } from '../gitService';
import { OpenFileCommandQuickPickItem } from './quickPicks';
import * as moment from 'moment';
import * as path from 'path';
@ -26,7 +26,7 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI
shortSha: string;
status: GitStatusFileStatus;
constructor(commit: GitCommit, status: IGitLogFileStatusEntry) {
constructor(commit: GitCommit, status: IGitStatusFile) {
const icon = getGitStatusIcon(status.status);
let directory = Git.normalizePath(path.dirname(status.fileName));

+ 2
- 4
src/quickPicks/repoStatus.ts View File

@ -9,7 +9,6 @@ import * as path from 'path';
export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPickItem {
constructor(status: GitStatusFile, item?: QuickPickItem) {
const uri = Uri.file(path.resolve(status.repoPath, status.fileName));
const icon = status.getIcon();
let directory = Git.normalizePath(path.dirname(status.fileName));
@ -21,7 +20,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
? `${directory || ''} \u00a0\u2190\u00a0 ${status.originalFileName}`
: directory;
super(uri, item || {
super(status.Uri, item || {
label: `${status.staged ? '$(check)' : '\u00a0\u00a0\u00a0'}\u00a0\u00a0${icon}\u00a0\u00a0\u00a0${path.basename(status.fileName)}`,
description: description
});
@ -31,8 +30,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
export class OpenStatusFilesCommandQuickPickItem extends CommandQuickPickItem {
constructor(statuses: GitStatusFile[], item?: QuickPickItem) {
const repoPath = statuses.length && statuses[0].repoPath;
const uris = statuses.map(_ => Uri.file(path.resolve(repoPath, _.fileName)));
const uris = statuses.map(_ => _.Uri);
super(item || {
label: `$(file-symlink-file) Open Changed Files`,

Loading…
Cancel
Save