Kaynağa Gözat

Marks model props readonly

main
Eric Amodio 6 yıl önce
ebeveyn
işleme
3c5920d019
7 değiştirilmiş dosya ile 104 ekleme ve 79 silme
  1. +11
    -11
      src/git/models/blame.ts
  2. +14
    -8
      src/git/models/branch.ts
  3. +5
    -5
      src/git/models/diff.ts
  4. +8
    -8
      src/git/models/log.ts
  5. +2
    -2
      src/git/models/stash.ts
  6. +11
    -11
      src/git/models/status.ts
  7. +53
    -34
      src/git/parsers/statusParser.ts

+ 11
- 11
src/git/models/blame.ts Dosyayı Görüntüle

@ -3,24 +3,24 @@ import { GitAuthor, GitCommitLine } from './commit';
import { GitBlameCommit } from './blameCommit';
export interface GitBlame {
repoPath: string;
authors: Map<string, GitAuthor>;
commits: Map<string, GitBlameCommit>;
lines: GitCommitLine[];
readonly repoPath: string;
readonly authors: Map<string, GitAuthor>;
readonly commits: Map<string, GitBlameCommit>;
readonly lines: GitCommitLine[];
}
export interface GitBlameLine {
author: GitAuthor;
commit: GitBlameCommit;
line: GitCommitLine;
readonly author: GitAuthor;
readonly commit: GitBlameCommit;
readonly line: GitCommitLine;
}
export interface GitBlameLines extends GitBlame {
allLines: GitCommitLine[];
readonly allLines: GitCommitLine[];
}
export interface GitBlameCommitLines {
author: GitAuthor;
commit: GitBlameCommit;
lines: GitCommitLine[];
readonly author: GitAuthor;
readonly commit: GitBlameCommit;
readonly lines: GitCommitLine[];
}

+ 14
- 8
src/git/models/branch.ts Dosyayı Görüntüle

@ -2,11 +2,11 @@
export class GitBranch {
current: boolean;
name: string;
remote: boolean;
tracking?: string;
state: {
readonly current: boolean;
readonly name: string;
readonly remote: boolean;
readonly tracking?: string;
readonly state: {
ahead: number;
behind: number;
};
@ -36,15 +36,21 @@ export class GitBranch {
};
}
private _name: string | undefined;
getName(): string {
return this.remote
? this.name.substring(this.name.indexOf('/') + 1)
: this.name;
if (this._name === undefined) {
this._name = this.remote
? this.name.substring(this.name.indexOf('/') + 1)
: this.name;
}
return this._name;
}
getRemote(): string | undefined {
if (this.remote) return GitBranch.getRemote(this.name);
if (this.tracking !== undefined) return GitBranch.getRemote(this.tracking);
return undefined;
}

+ 5
- 5
src/git/models/diff.ts Dosyayı Görüntüle

@ -34,13 +34,13 @@ export class GitDiffChunk {
}
export interface GitDiff {
chunks: GitDiffChunk[];
readonly chunks: GitDiffChunk[];
diff?: string;
readonly diff?: string;
}
export interface GitDiffShortStat {
files: number;
insertions: number;
deletions: number;
readonly files: number;
readonly insertions: number;
readonly deletions: number;
}

+ 8
- 8
src/git/models/log.ts Dosyayı Görüntüle

@ -4,15 +4,15 @@ import { GitAuthor } from './commit';
import { GitLogCommit } from './logCommit';
export interface GitLog {
repoPath: string;
authors: Map<string, GitAuthor>;
commits: Map<string, GitLogCommit>;
readonly repoPath: string;
readonly authors: Map<string, GitAuthor>;
readonly commits: Map<string, GitLogCommit>;
sha: string | undefined;
count: number;
maxCount: number | undefined;
range: Range;
truncated: boolean;
readonly sha: string | undefined;
readonly count: number;
readonly maxCount: number | undefined;
readonly range: Range;
readonly truncated: boolean;
query: (maxCount: number | undefined) => Promise<GitLog | undefined>;
}

+ 2
- 2
src/git/models/stash.ts Dosyayı Görüntüle

@ -2,6 +2,6 @@
import { GitStashCommit } from './stashCommit';
export interface GitStash {
repoPath: string;
commits: Map<string, GitStashCommit>;
readonly repoPath: string;
readonly commits: Map<string, GitStashCommit>;
}

+ 11
- 11
src/git/models/status.ts Dosyayı Görüntüle

@ -8,30 +8,30 @@ import * as path from 'path';
export interface GitStatus {
branch: string;
repoPath: string;
sha: string;
state: {
readonly branch: string;
readonly repoPath: string;
readonly sha: string;
readonly state: {
ahead: number;
behind: number;
};
upstream?: string;
readonly upstream?: string;
files: GitStatusFile[];
readonly files: GitStatusFile[];
}
export declare type GitStatusFileStatus = '!' | '?' | 'A' | 'C' | 'D' | 'M' | 'R' | 'T' | 'U' | 'X' | 'B';
export interface IGitStatusFile {
status: GitStatusFileStatus;
fileName: string;
originalFileName?: string;
workTreeStatus: GitStatusFileStatus;
indexStatus: GitStatusFileStatus;
readonly fileName: string;
readonly originalFileName?: string;
readonly workTreeStatus: GitStatusFileStatus;
readonly indexStatus: GitStatusFileStatus;
}
export interface IGitStatusFileWithCommit extends IGitStatusFile {
commit: GitLogCommit;
readonly commit: GitLogCommit;
}
export class GitStatusFile implements IGitStatusFile {

+ 53
- 34
src/git/parsers/statusParser.ts Dosyayı Görüntüle

@ -13,43 +13,35 @@ export class GitStatusParser {
const lines = data.split('\n').filter(l => !!l);
if (lines.length === 0) return undefined;
const status = {
branch: '',
repoPath: Strings.normalizePath(repoPath),
sha: '',
state: {
ahead: 0,
behind: 0
},
files: []
};
if (porcelainVersion < 2) return this.parseV1(lines, repoPath);
if (porcelainVersion >= 2) {
this.parseV2(lines, repoPath, status);
}
else {
this.parseV1(lines, repoPath, status);
}
return status;
return this.parseV2(lines, repoPath);
}
private static parseV1(lines: string[], repoPath: string, status: GitStatus) {
private static parseV1(lines: string[], repoPath: string): GitStatus {
let branch: string | undefined;
const files = [];
const state = {
ahead: 0,
behind: 0
};
let upstream;
let position = -1;
while (++position < lines.length) {
const line = lines[position];
// Header
if (line.startsWith('##')) {
const lineParts = line.split(' ');
[status.branch, status.upstream] = lineParts[1].split('...');
[branch, upstream] = lineParts[1].split('...');
if (lineParts.length > 2) {
const upstreamStatus = lineParts.slice(2).join(' ');
const aheadStatus = aheadStatusV1Regex.exec(upstreamStatus);
status.state.ahead = aheadStatus == null ? 0 : +aheadStatus[1] || 0;
state.ahead = aheadStatus == null ? 0 : +aheadStatus[1] || 0;
const behindStatus = behindStatusV1Regex.exec(upstreamStatus);
status.state.behind = behindStatus == null ? 0 : +behindStatus[1] || 0;
state.behind = behindStatus == null ? 0 : +behindStatus[1] || 0;
}
}
else {
@ -57,16 +49,34 @@ export class GitStatusParser {
const fileName = line.substring(3);
if (rawStatus[0] === 'R') {
const [file1, file2] = fileName.replace(/\"/g, '').split('->');
status.files.push(this.parseStatusFile(repoPath, rawStatus, file2.trim(), file1.trim()));
files.push(this.parseStatusFile(repoPath, rawStatus, file2.trim(), file1.trim()));
}
else {
status.files.push(this.parseStatusFile(repoPath, rawStatus, fileName));
files.push(this.parseStatusFile(repoPath, rawStatus, fileName));
}
}
}
return {
branch: branch || '',
repoPath: Strings.normalizePath(repoPath),
sha: '',
state: state,
files: files,
upstream: upstream
};
}
private static parseV2(lines: string[], repoPath: string, status: GitStatus) {
private static parseV2(lines: string[], repoPath: string): GitStatus {
let branch: string | undefined;
const files = [];
let sha: string | undefined;
const state = {
ahead: 0,
behind: 0
};
let upstream;
let position = -1;
while (++position < lines.length) {
const line = lines[position];
@ -75,17 +85,17 @@ export class GitStatusParser {
const lineParts = line.split(' ');
switch (lineParts[1]) {
case 'branch.oid':
status.sha = lineParts[2];
sha = lineParts[2];
break;
case 'branch.head':
status.branch = lineParts[2];
branch = lineParts[2];
break;
case 'branch.upstream':
status.upstream = lineParts[2];
upstream = lineParts[2];
break;
case 'branch.ab':
status.state.ahead = +lineParts[2].substring(1);
status.state.behind = +lineParts[3].substring(1);
state.ahead = +lineParts[2].substring(1);
state.behind = +lineParts[3].substring(1);
break;
}
}
@ -93,21 +103,30 @@ export class GitStatusParser {
const lineParts = line.split(' ');
switch (lineParts[0][0]) {
case '1': // normal
status.files.push(this.parseStatusFile(repoPath, lineParts[1], lineParts.slice(8).join(' ')));
files.push(this.parseStatusFile(repoPath, lineParts[1], lineParts.slice(8).join(' ')));
break;
case '2': // rename
const file = lineParts.slice(9).join(' ').split('\t');
status.files.push(this.parseStatusFile(repoPath, lineParts[1], file[0], file[1]));
files.push(this.parseStatusFile(repoPath, lineParts[1], file[0], file[1]));
break;
case 'u': // unmerged
status.files.push(this.parseStatusFile(repoPath, lineParts[1], lineParts.slice(10).join(' ')));
files.push(this.parseStatusFile(repoPath, lineParts[1], lineParts.slice(10).join(' ')));
break;
case '?': // untracked
status.files.push(this.parseStatusFile(repoPath, ' ?', lineParts.slice(1).join(' ')));
files.push(this.parseStatusFile(repoPath, ' ?', lineParts.slice(1).join(' ')));
break;
}
}
}
return {
branch: branch || '',
repoPath: Strings.normalizePath(repoPath),
sha: sha || '',
state: state,
files: files,
upstream: upstream
};
}
static parseStatusFile(repoPath: string, rawStatus: string, fileName: string, originalFileName?: string): GitStatusFile {

Yükleniyor…
İptal
Kaydet