mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-22 17:26:10 -05:00
Enables typescript strict mode
Fixes all the compile/lint issues
This commit is contained in:
@@ -10,7 +10,7 @@ interface IBlameEntry {
|
||||
originalLine: number;
|
||||
lineCount: number;
|
||||
|
||||
author?: string;
|
||||
author: string;
|
||||
// authorEmail?: string;
|
||||
authorDate?: string;
|
||||
authorTimeZone?: string;
|
||||
@@ -30,7 +30,7 @@ interface IBlameEntry {
|
||||
|
||||
export class GitBlameParser {
|
||||
|
||||
private static _parseEntries(data: string): IBlameEntry[] {
|
||||
private static _parseEntries(data: string): IBlameEntry[] | undefined {
|
||||
if (!data) return undefined;
|
||||
|
||||
const lines = data.split('\n');
|
||||
@@ -38,7 +38,7 @@ export class GitBlameParser {
|
||||
|
||||
const entries: IBlameEntry[] = [];
|
||||
|
||||
let entry: IBlameEntry;
|
||||
let entry: IBlameEntry | undefined = undefined;
|
||||
let position = -1;
|
||||
while (++position < lines.length) {
|
||||
let lineParts = lines[position].split(' ');
|
||||
@@ -46,13 +46,13 @@ export class GitBlameParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entry) {
|
||||
if (entry === undefined) {
|
||||
entry = {
|
||||
sha: lineParts[0],
|
||||
originalLine: parseInt(lineParts[1], 10) - 1,
|
||||
line: parseInt(lineParts[2], 10) - 1,
|
||||
lineCount: parseInt(lineParts[3], 10)
|
||||
};
|
||||
} as IBlameEntry;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export class GitBlameParser {
|
||||
return entries;
|
||||
}
|
||||
|
||||
static parse(data: string, repoPath: string, fileName: string): IGitBlame {
|
||||
static parse(data: string, repoPath: string | undefined, fileName: string): IGitBlame | undefined {
|
||||
const entries = this._parseEntries(data);
|
||||
if (!entries) return undefined;
|
||||
|
||||
@@ -129,24 +129,26 @@ export class GitBlameParser {
|
||||
for (let i = 0, len = entries.length; i < len; i++) {
|
||||
const entry = entries[i];
|
||||
|
||||
if (i === 0 && !repoPath) {
|
||||
if (i === 0 && repoPath === undefined) {
|
||||
// Try to get the repoPath from the most recent commit
|
||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
|
||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
||||
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||
}
|
||||
|
||||
let commit = commits.get(entry.sha);
|
||||
if (!commit) {
|
||||
let author = authors.get(entry.author);
|
||||
if (!author) {
|
||||
author = {
|
||||
name: entry.author,
|
||||
lineCount: 0
|
||||
};
|
||||
authors.set(entry.author, author);
|
||||
if (commit === undefined) {
|
||||
if (entry.author !== undefined) {
|
||||
let author = authors.get(entry.author);
|
||||
if (author === undefined) {
|
||||
author = {
|
||||
name: entry.author,
|
||||
lineCount: 0
|
||||
};
|
||||
authors.set(entry.author, author);
|
||||
}
|
||||
}
|
||||
|
||||
commit = new GitCommit('blame', repoPath, entry.sha, relativeFileName, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary);
|
||||
commit = new GitCommit('blame', repoPath!, entry.sha, relativeFileName!, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary!);
|
||||
|
||||
if (relativeFileName !== entry.fileName) {
|
||||
commit.originalFileName = entry.fileName;
|
||||
@@ -176,7 +178,14 @@ export class GitBlameParser {
|
||||
}
|
||||
}
|
||||
|
||||
commits.forEach(c => authors.get(c.author).lineCount += c.lines.length);
|
||||
commits.forEach(c => {
|
||||
if (c.author === undefined) return;
|
||||
|
||||
const author = authors.get(c.author);
|
||||
if (author === undefined) return;
|
||||
|
||||
author.lineCount += c.lines.length;
|
||||
});
|
||||
|
||||
const sortedAuthors: Map<string, IGitAuthor> = new Map();
|
||||
// const values =
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as path from 'path';
|
||||
interface ILogEntry {
|
||||
sha: string;
|
||||
|
||||
author?: string;
|
||||
author: string;
|
||||
authorDate?: string;
|
||||
|
||||
// committer?: string;
|
||||
@@ -29,7 +29,7 @@ const diffRegex = /diff --git a\/(.*) b\/(.*)/;
|
||||
|
||||
export class GitLogParser {
|
||||
|
||||
private static _parseEntries(data: string, type: GitCommitType, maxCount: number | undefined, reverse: boolean): ILogEntry[] {
|
||||
private static _parseEntries(data: string, type: GitCommitType, maxCount: number | undefined, reverse: boolean): ILogEntry[] | undefined {
|
||||
if (!data) return undefined;
|
||||
|
||||
const lines = data.split('\n');
|
||||
@@ -37,7 +37,7 @@ export class GitLogParser {
|
||||
|
||||
const entries: ILogEntry[] = [];
|
||||
|
||||
let entry: ILogEntry;
|
||||
let entry: ILogEntry | undefined = undefined;
|
||||
let position = -1;
|
||||
while (++position < lines.length) {
|
||||
// Since log --reverse doesn't properly honor a max count -- enforce it here
|
||||
@@ -48,12 +48,12 @@ export class GitLogParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entry) {
|
||||
if (entry === undefined) {
|
||||
if (!Git.shaRegex.test(lineParts[0])) continue;
|
||||
|
||||
entry = {
|
||||
sha: lineParts[0]
|
||||
};
|
||||
} as ILogEntry;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -118,10 +118,12 @@ export class GitLogParser {
|
||||
if (lineParts[0] === 'diff') {
|
||||
diff = true;
|
||||
const matches = diffRegex.exec(line);
|
||||
entry.fileName = matches[1];
|
||||
const originalFileName = matches[2];
|
||||
if (entry.fileName !== originalFileName) {
|
||||
entry.originalFileName = originalFileName;
|
||||
if (matches != null) {
|
||||
entry.fileName = matches[1];
|
||||
const originalFileName = matches[2];
|
||||
if (entry.fileName !== originalFileName) {
|
||||
entry.originalFileName = originalFileName;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -133,7 +135,7 @@ export class GitLogParser {
|
||||
const status = {
|
||||
status: line[0] as GitStatusFileStatus,
|
||||
fileName: line.substring(1),
|
||||
originalFileName: undefined as string
|
||||
originalFileName: undefined
|
||||
} as IGitStatusFile;
|
||||
this._parseFileName(status);
|
||||
|
||||
@@ -164,7 +166,7 @@ export class GitLogParser {
|
||||
return entries;
|
||||
}
|
||||
|
||||
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range): IGitLog {
|
||||
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range | undefined): IGitLog | undefined {
|
||||
const entries = this._parseEntries(data, type, maxCount, reverse);
|
||||
if (!entries) return undefined;
|
||||
|
||||
@@ -172,7 +174,7 @@ export class GitLogParser {
|
||||
const commits: Map<string, GitLogCommit> = new Map();
|
||||
|
||||
let relativeFileName: string;
|
||||
let recentCommit: GitLogCommit;
|
||||
let recentCommit: GitLogCommit | undefined = undefined;
|
||||
|
||||
if (repoPath !== undefined) {
|
||||
repoPath = Git.normalizePath(repoPath);
|
||||
@@ -184,28 +186,30 @@ export class GitLogParser {
|
||||
|
||||
const entry = entries[i];
|
||||
|
||||
if (i === 0 && type === 'file' && !repoPath) {
|
||||
if (i === 0 && repoPath === undefined && type === 'file' && fileName !== undefined) {
|
||||
// Try to get the repoPath from the most recent commit
|
||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
|
||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
||||
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||
}
|
||||
else {
|
||||
relativeFileName = entry.fileName;
|
||||
relativeFileName = entry.fileName!;
|
||||
}
|
||||
|
||||
let commit = commits.get(entry.sha);
|
||||
if (!commit) {
|
||||
let author = authors.get(entry.author);
|
||||
if (!author) {
|
||||
author = {
|
||||
name: entry.author,
|
||||
lineCount: 0
|
||||
};
|
||||
authors.set(entry.author, author);
|
||||
if (commit === undefined) {
|
||||
if (entry.author !== undefined) {
|
||||
let author = authors.get(entry.author);
|
||||
if (author === undefined) {
|
||||
author = {
|
||||
name: entry.author,
|
||||
lineCount: 0
|
||||
};
|
||||
authors.set(entry.author, author);
|
||||
}
|
||||
}
|
||||
|
||||
commit = new GitLogCommit(type, repoPath, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary, entry.status, entry.fileStatuses, undefined, entry.originalFileName);
|
||||
commit.parentShas = entry.parentShas;
|
||||
commit = new GitLogCommit(type, repoPath!, entry.sha, relativeFileName, entry.author, moment(entry.authorDate).toDate(), entry.summary!, entry.status, entry.fileStatuses, undefined, entry.originalFileName);
|
||||
commit.parentShas = entry.parentShas!;
|
||||
|
||||
if (relativeFileName !== entry.fileName) {
|
||||
commit.originalFileName = entry.fileName;
|
||||
@@ -217,7 +221,7 @@ export class GitLogParser {
|
||||
// Logger.log(`merge commit? ${entry.sha}`);
|
||||
// }
|
||||
|
||||
if (recentCommit) {
|
||||
if (recentCommit !== undefined) {
|
||||
recentCommit.previousSha = commit.sha;
|
||||
|
||||
// If the commit sha's match (merge commit), just forward it along
|
||||
@@ -232,7 +236,14 @@ export class GitLogParser {
|
||||
recentCommit = commit;
|
||||
}
|
||||
|
||||
commits.forEach(c => authors.get(c.author).lineCount += c.lines.length);
|
||||
commits.forEach(c => {
|
||||
if (c.author === undefined) return;
|
||||
|
||||
const author = authors.get(c.author);
|
||||
if (author === undefined) return;
|
||||
|
||||
author.lineCount += c.lines.length;
|
||||
});
|
||||
|
||||
const sortedAuthors: Map<string, IGitAuthor> = new Map();
|
||||
// const values =
|
||||
@@ -258,10 +269,12 @@ export class GitLogParser {
|
||||
}
|
||||
|
||||
private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) {
|
||||
if (entry.fileName === undefined) return;
|
||||
|
||||
const index = entry.fileName.indexOf('\t') + 1;
|
||||
if (index) {
|
||||
if (index > 0) {
|
||||
const next = entry.fileName.indexOf('\t', index) + 1;
|
||||
if (next) {
|
||||
if (next > 0) {
|
||||
entry.originalFileName = entry.fileName.substring(index, next - 1);
|
||||
entry.fileName = entry.fileName.substring(next);
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ import * as moment from 'moment';
|
||||
interface IStashEntry {
|
||||
sha: string;
|
||||
date?: string;
|
||||
fileNames?: string;
|
||||
fileNames: string;
|
||||
fileStatuses?: IGitStatusFile[];
|
||||
summary?: string;
|
||||
stashName?: string;
|
||||
summary: string;
|
||||
stashName: string;
|
||||
}
|
||||
|
||||
export class GitStashParser {
|
||||
|
||||
private static _parseEntries(data: string): IStashEntry[] {
|
||||
private static _parseEntries(data: string): IStashEntry[] | undefined {
|
||||
if (!data) return undefined;
|
||||
|
||||
const lines = data.split('\n');
|
||||
@@ -22,7 +22,7 @@ export class GitStashParser {
|
||||
|
||||
const entries: IStashEntry[] = [];
|
||||
|
||||
let entry: IStashEntry;
|
||||
let entry: IStashEntry | undefined = undefined;
|
||||
let position = -1;
|
||||
while (++position < lines.length) {
|
||||
let lineParts = lines[position].split(' ');
|
||||
@@ -30,12 +30,12 @@ export class GitStashParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entry) {
|
||||
if (entry === undefined) {
|
||||
if (!Git.shaRegex.test(lineParts[0])) continue;
|
||||
|
||||
entry = {
|
||||
sha: lineParts[0]
|
||||
};
|
||||
} as IStashEntry;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ export class GitStashParser {
|
||||
const status = {
|
||||
status: line[0] as GitStatusFileStatus,
|
||||
fileName: line.substring(1),
|
||||
originalFileName: undefined as string
|
||||
originalFileName: undefined
|
||||
} as IGitStatusFile;
|
||||
this._parseFileName(status);
|
||||
|
||||
@@ -109,9 +109,9 @@ export class GitStashParser {
|
||||
return entries;
|
||||
}
|
||||
|
||||
static parse(data: string, repoPath: string): IGitStash {
|
||||
static parse(data: string, repoPath: string): IGitStash | undefined {
|
||||
const entries = this._parseEntries(data);
|
||||
if (!entries) return undefined;
|
||||
if (entries === undefined) return undefined;
|
||||
|
||||
const commits: Map<string, GitStashCommit> = new Map();
|
||||
|
||||
@@ -119,8 +119,8 @@ export class GitStashParser {
|
||||
const entry = entries[i];
|
||||
|
||||
let commit = commits.get(entry.sha);
|
||||
if (!commit) {
|
||||
commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, moment(entry.date).toDate(), entry.summary, undefined, entry.fileStatuses);
|
||||
if (commit !== undefined) {
|
||||
commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, moment(entry.date).toDate(), entry.summary, undefined, entry.fileStatuses) as GitStashCommit;
|
||||
commits.set(entry.sha, commit);
|
||||
}
|
||||
}
|
||||
@@ -132,10 +132,12 @@ export class GitStashParser {
|
||||
}
|
||||
|
||||
private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) {
|
||||
if (entry.fileName === undefined) return;
|
||||
|
||||
const index = entry.fileName.indexOf('\t') + 1;
|
||||
if (index) {
|
||||
if (index > 0) {
|
||||
const next = entry.fileName.indexOf('\t', index) + 1;
|
||||
if (next) {
|
||||
if (next > 0) {
|
||||
entry.originalFileName = entry.fileName.substring(index, next - 1);
|
||||
entry.fileName = entry.fileName.substring(next);
|
||||
}
|
||||
|
||||
@@ -13,20 +13,22 @@ const behindStatusV1Regex = /(?:behind ([0-9]+))/;
|
||||
|
||||
export class GitStatusParser {
|
||||
|
||||
static parse(data: string, repoPath: string, porcelainVersion: number): IGitStatus {
|
||||
static parse(data: string, repoPath: string, porcelainVersion: number): IGitStatus | undefined {
|
||||
if (!data) return undefined;
|
||||
|
||||
const lines = data.split('\n').filter(_ => !!_);
|
||||
if (!lines.length) return undefined;
|
||||
|
||||
const status = {
|
||||
branch: '',
|
||||
repoPath: Git.normalizePath(repoPath),
|
||||
sha: '',
|
||||
state: {
|
||||
ahead: 0,
|
||||
behind: 0
|
||||
},
|
||||
files: []
|
||||
} as IGitStatus;
|
||||
};
|
||||
|
||||
if (porcelainVersion >= 2) {
|
||||
this._parseV2(lines, repoPath, status);
|
||||
@@ -50,10 +52,10 @@ export class GitStatusParser {
|
||||
const upstreamStatus = lineParts.slice(2).join(' ');
|
||||
|
||||
const aheadStatus = aheadStatusV1Regex.exec(upstreamStatus);
|
||||
status.state.ahead = +aheadStatus[1] || 0;
|
||||
status.state.ahead = aheadStatus == null ? 0 : +aheadStatus[1] || 0;
|
||||
|
||||
const behindStatus = behindStatusV1Regex.exec(upstreamStatus);
|
||||
status.state.behind = +behindStatus[1] || 0;
|
||||
status.state.behind = behindStatus == null ? 0 : +behindStatus[1] || 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -97,7 +99,7 @@ export class GitStatusParser {
|
||||
}
|
||||
else {
|
||||
let lineParts = line.split(' ');
|
||||
let entry: IFileStatusEntry;
|
||||
let entry: IFileStatusEntry | undefined = undefined;
|
||||
switch (lineParts[0][0]) {
|
||||
case '1': // normal
|
||||
entry = this._parseFileEntry(lineParts[1], lineParts.slice(8).join(' '));
|
||||
@@ -114,7 +116,7 @@ export class GitStatusParser {
|
||||
break;
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
if (entry !== undefined) {
|
||||
status.files.push(new GitStatusFile(repoPath, entry.status, entry.fileName, entry.staged, entry.originalFileName));
|
||||
}
|
||||
}
|
||||
@@ -130,6 +132,6 @@ export class GitStatusParser {
|
||||
fileName: fileName,
|
||||
originalFileName: originalFileName,
|
||||
staged: !!indexStatus
|
||||
};
|
||||
} as IFileStatusEntry;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user