Преглед изворни кода

Renames some members for consistency

main
Eric Amodio пре 5 година
родитељ
комит
6d9a666d12
10 измењених фајлова са 75 додато и 72 уклоњено
  1. +2
    -2
      src/annotations/annotations.ts
  2. +1
    -1
      src/commands/diffLineWithWorking.ts
  3. +2
    -2
      src/commands/diffWithWorking.ts
  4. +22
    -20
      src/git/git.ts
  5. +36
    -35
      src/git/gitService.ts
  6. +4
    -4
      src/git/gitUri.ts
  7. +1
    -1
      src/git/models/commit.ts
  8. +2
    -2
      src/quickpicks/repoStatusQuickPick.ts
  9. +2
    -2
      src/views/nodes/fileHistoryNode.ts
  10. +3
    -3
      src/views/nodes/statusFilesNode.ts

+ 2
- 2
src/annotations/annotations.ts Прегледај датотеку

@ -121,7 +121,7 @@ export class Annotations {
let message: string;
if (commit.isUncommitted) {
if (uri.sha !== undefined && GitService.isStagedUncommitted(uri.sha)) {
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
message = `[\`Changes\`](${DiffWithCommand.getMarkdownCommandArgs(
commit,
editorLine
@ -173,7 +173,7 @@ export class Annotations {
): Promise<Partial<DecorationOptions>> {
let ref;
if (commit.isUncommitted) {
if (uri.sha !== undefined && GitService.isStagedUncommitted(uri.sha)) {
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
ref = uri.sha;
}
}

+ 1
- 1
src/commands/diffLineWithWorking.ts Прегледај датотеку

@ -52,7 +52,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
args.commit = args.commit.with({
sha:
status !== undefined && status.indexStatus !== undefined
? GitService.stagedUncommittedSha
? GitService.uncommittedStagedSha
: args.commit.previousSha!,
fileName: args.commit.previousFileName!,
originalFileName: null,

+ 2
- 2
src/commands/diffWithWorking.ts Прегледај датотеку

@ -61,12 +61,12 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
}
// If we are a fake "staged" sha, check the status
if (GitService.isStagedUncommitted(gitUri.sha!)) {
if (GitService.isUncommittedStaged(gitUri.sha!)) {
gitUri.sha = undefined;
const status = await Container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
if (status !== undefined && status.indexStatus !== undefined) {
let sha = GitService.stagedUncommittedSha;
let sha = GitService.uncommittedStagedSha;
if (args.inDiffEditor) {
const commit = await Container.git.getCommitForFile(gitUri.repoPath!, gitUri.fsPath);
if (commit === undefined) return Messages.showCommitHasNoPreviousCommitWarningMessage();

+ 22
- 20
src/git/git.ts Прегледај датотеку

@ -206,10 +206,10 @@ export class Git {
static shaRegex = /(^[0-9a-f]{40}$)|(^[0]{40}(:|-)$)/;
static shaParentRegex = /^[0-9a-f]{40}\^[0-3]?$/;
static shaShortenRegex = /^(.*?)([\^@~:].*)?$/;
static stagedUncommittedRegex = /^[0]{40}([\^@~]\S*)?:$/;
static stagedUncommittedSha = '0000000000000000000000000000000000000000:';
static uncommittedRegex = /^[0]{40}(?:[\^@~:]\S*)?:?$/;
static uncommittedSha = '0000000000000000000000000000000000000000';
static uncommittedStagedRegex = /^[0]{40}([\^@~]\S*)?:$/;
static uncommittedStagedSha = '0000000000000000000000000000000000000000:';
static getEncoding(encoding: string | undefined) {
return encoding !== undefined && iconv.encodingExists(encoding) ? encoding : 'utf8';
@ -247,27 +247,29 @@ export class Git {
return Git.shaParentRegex.test(ref);
}
static isStagedUncommitted(ref: string | undefined): boolean {
return ref ? Git.stagedUncommittedRegex.test(ref) : false;
}
static isUncommitted(ref: string | undefined) {
return ref ? Git.uncommittedRegex.test(ref) : false;
}
static isUncommittedStaged(ref: string | undefined): boolean {
return ref ? Git.uncommittedStagedRegex.test(ref) : false;
}
static shortenSha(
ref: string,
strings: { stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
ref: string | undefined,
{
stagedUncommitted = 'Index',
uncommitted = 'Working Tree',
working = emptyStr
}: { stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
) {
strings = { stagedUncommitted: 'Index', uncommitted: 'Working Tree', working: emptyStr, ...strings };
if (ref == null || ref.length === 0) return strings.working;
if (ref == null || ref.length === 0) return working;
if (Git.isUncommitted(ref)) {
if (Git.isStagedUncommitted(ref)) return strings.stagedUncommitted;
return strings.uncommitted;
return Git.isUncommittedStaged(ref) ? stagedUncommitted : uncommitted;
}
if (!Git.isShaLike(ref)) return ref;
// Don't allow shas to be shortened to less than 5 characters
const len = Math.max(5, Container.config.advanced.abbreviatedShaLength);
@ -343,7 +345,7 @@ export class Git {
let stdin;
if (ref) {
if (Git.isStagedUncommitted(ref)) {
if (Git.isUncommittedStaged(ref)) {
// Pipe the blame contents to stdin
params.push('--contents', '-');
@ -496,10 +498,10 @@ export class Git {
if (ref1.endsWith('^3^')) {
ref1 = rootSha;
}
params.push(Git.isStagedUncommitted(ref1) ? '--staged' : ref1);
params.push(Git.isUncommittedStaged(ref1) ? '--staged' : ref1);
}
if (ref2) {
params.push(Git.isStagedUncommitted(ref2) ? '--staged' : ref2);
params.push(Git.isUncommittedStaged(ref2) ? '--staged' : ref2);
}
const encoding: BufferEncoding = options.encoding === 'utf8' ? 'utf8' : 'binary';
@ -637,7 +639,7 @@ export class Git {
params.push('--use-mailmap', ...authors.map(a => `--author=${a}`));
}
if (ref && !Git.isStagedUncommitted(ref)) {
if (ref && !Git.isUncommittedStaged(ref)) {
// If we are reversing, we must add a range (with HEAD) because we are using --ancestry-path for better reverse walking
if (reverse) {
params.push('--reverse', '--ancestry-path', `${ref}..HEAD`);
@ -697,7 +699,7 @@ export class Git {
params.push(`-L ${startLine},${endLine == null ? startLine : endLine}:${file}`);
}
if (ref && !Git.isStagedUncommitted(ref)) {
if (ref && !Git.isUncommittedStaged(ref)) {
// If we are reversing, we must add a range (with HEAD) because we are using --ancestry-path for better reverse walking
if (reverse) {
params.push('--reverse', '--ancestry-path', `${ref}..HEAD`);
@ -868,7 +870,7 @@ export class Git {
): Promise<TOut | undefined> {
const [file, root] = Git.splitPath(fileName, repoPath);
if (Git.isStagedUncommitted(ref)) {
if (Git.isUncommittedStaged(ref)) {
ref = ':';
}
if (Git.isUncommitted(ref)) throw new Error(`ref=${ref} is uncommitted`);

+ 36
- 35
src/git/gitService.ts Прегледај датотеку

@ -93,12 +93,9 @@ export enum GitRepoSearchBy {
Sha = 'sha'
}
export class GitService implements Disposable {
static emptyPromise: Promise<GitBlame | GitDiff | GitLog | undefined> = Promise.resolve(undefined);
static deletedOrMissingSha = Git.deletedOrMissingSha;
static stagedUncommittedSha = Git.stagedUncommittedSha;
static uncommittedSha = Git.uncommittedSha;
const emptyPromise: Promise<GitBlame | GitDiff | GitLog | undefined> = Promise.resolve(undefined);
export class GitService implements Disposable {
private _onDidChangeRepositories = new EventEmitter<void>();
get onDidChangeRepositories(): Event<void> {
return this._onDidChangeRepositories.event;
@ -672,7 +669,7 @@ export class GitService implements Disposable {
): Promise<GitBlame | undefined> {
if (!(await this.isTracked(uri))) {
Logger.log(cc, `Skipping blame; '${uri.fsPath}' is not tracked`);
return GitService.emptyPromise as Promise<GitBlame>;
return emptyPromise as Promise<GitBlame>;
}
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
@ -692,14 +689,14 @@ export class GitService implements Disposable {
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
const value: CachedBlame = {
item: GitService.emptyPromise as Promise<GitBlame>,
item: emptyPromise as Promise<GitBlame>,
errorMessage: msg
};
document.state.set<CachedBlame>(key, value);
document.setBlameFailure();
return GitService.emptyPromise as Promise<GitBlame>;
return emptyPromise as Promise<GitBlame>;
}
return undefined;
@ -756,7 +753,7 @@ export class GitService implements Disposable {
): Promise<GitBlame | undefined> {
if (!(await this.isTracked(uri))) {
Logger.log(cc, `Skipping blame; '${uri.fsPath}' is not tracked`);
return GitService.emptyPromise as Promise<GitBlame>;
return emptyPromise as Promise<GitBlame>;
}
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
@ -777,13 +774,13 @@ export class GitService implements Disposable {
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
const value: CachedBlame = {
item: GitService.emptyPromise as Promise<GitBlame>,
item: emptyPromise as Promise<GitBlame>,
errorMessage: msg
};
document.state.set<CachedBlame>(key, value);
document.setBlameFailure();
return GitService.emptyPromise as Promise<GitBlame>;
return emptyPromise as Promise<GitBlame>;
}
return undefined;
@ -1169,7 +1166,7 @@ export class GitService implements Disposable {
try {
let data;
if (ref1 !== undefined && ref2 === undefined && !GitService.isStagedUncommitted(ref1)) {
if (ref1 !== undefined && ref2 === undefined && !GitService.isUncommittedStaged(ref1)) {
data = await Git.show__diff(root, file, ref1, originalFileName, {
similarityThreshold: Container.config.advanced.similarityThreshold
});
@ -1192,12 +1189,12 @@ export class GitService implements Disposable {
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
const value: CachedDiff = {
item: GitService.emptyPromise as Promise<GitDiff>,
item: emptyPromise as Promise<GitDiff>,
errorMessage: msg
};
document.state.set<CachedDiff>(key, value);
return GitService.emptyPromise as Promise<GitDiff>;
return emptyPromise as Promise<GitDiff>;
}
return undefined;
@ -1216,7 +1213,7 @@ export class GitService implements Disposable {
let diff = await this.getDiffForFile(uri, ref1, ref2, originalFileName);
// If we didn't find a diff & ref1 is undefined (meaning uncommitted), check for a staged diff
if (diff === undefined && ref1 === undefined) {
diff = await this.getDiffForFile(uri, Git.stagedUncommittedSha, ref2, originalFileName);
diff = await this.getDiffForFile(uri, Git.uncommittedStagedSha, ref2, originalFileName);
}
if (diff === undefined) return undefined;
@ -1537,7 +1534,7 @@ export class GitService implements Disposable {
): Promise<GitLog | undefined> {
if (!(await this.isTracked(fileName, repoPath, { ref: ref }))) {
Logger.log(cc, `Skipping log; '${fileName}' is not tracked`);
return GitService.emptyPromise as Promise<GitLog>;
return emptyPromise as Promise<GitLog>;
}
const [file, root] = Git.splitPath(fileName, repoPath, false);
@ -1582,12 +1579,12 @@ export class GitService implements Disposable {
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
const value: CachedLog = {
item: GitService.emptyPromise as Promise<GitLog>,
item: emptyPromise as Promise<GitLog>,
errorMessage: msg
};
document.state.set<CachedLog>(key, value);
return GitService.emptyPromise as Promise<GitLog>;
return emptyPromise as Promise<GitLog>;
}
return undefined;
@ -1641,7 +1638,7 @@ export class GitService implements Disposable {
const fileName = GitUri.getRelativePath(uri, repoPath);
if (Git.isStagedUncommitted(ref)) {
if (Git.isUncommittedStaged(ref)) {
return {
current: GitUri.fromFile(fileName, repoPath, ref),
next: GitUri.fromFile(fileName, repoPath, undefined)
@ -1656,7 +1653,7 @@ export class GitService implements Disposable {
if (status.indexStatus !== undefined) {
return {
current: GitUri.fromFile(fileName, repoPath, ref),
next: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha)
next: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha)
};
}
}
@ -1682,7 +1679,7 @@ export class GitService implements Disposable {
// editorLine?: number
): Promise<GitUri | undefined> {
// If we have no ref (or staged ref) there is no next commit
if (ref === undefined || ref.length === 0 || Git.isStagedUncommitted(ref)) return undefined;
if (ref === undefined || ref.length === 0 || Git.isUncommittedStaged(ref)) return undefined;
let filters: GitLogDiffFilter[] | undefined;
if (ref === GitService.deletedOrMissingSha) {
@ -1746,18 +1743,18 @@ export class GitService implements Disposable {
if (skip === 0) {
return {
current: GitUri.fromFile(fileName, repoPath, ref),
previous: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha)
previous: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha)
};
}
return {
current: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha),
current: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha),
previous: await this.getPreviousUri(repoPath, uri, ref, skip - 1, editorLine)
};
}
}
}
else if (GitService.isStagedUncommitted(ref)) {
else if (GitService.isUncommittedStaged(ref)) {
const current =
skip === 0
? GitUri.fromFile(fileName, repoPath, ref)
@ -1791,6 +1788,9 @@ export class GitService implements Disposable {
editorLine?: number
): Promise<GitUri | undefined> {
if (ref === GitService.deletedOrMissingSha) return undefined;
if (ref === GitService.uncommittedSha) {
ref = undefined;
}
if (ref !== undefined) {
skip++;
@ -2130,14 +2130,14 @@ export class GitService implements Disposable {
): Promise<Uri | undefined> {
if (ref === GitService.deletedOrMissingSha) return undefined;
if (!ref || (Git.isUncommitted(ref) && !Git.isStagedUncommitted(ref))) {
if (!ref || (Git.isUncommitted(ref) && !Git.isUncommittedStaged(ref))) {
const data = await Git.ls_files(repoPath!, fileName);
if (data !== undefined) return GitUri.file(fileName);
return undefined;
}
if (Git.isStagedUncommitted(ref)) {
if (Git.isUncommittedStaged(ref)) {
return GitUri.git(fileName, repoPath);
}
@ -2435,24 +2435,25 @@ export class GitService implements Disposable {
return Git.getEncoding(workspace.getConfiguration('files', uri).get<string>('encoding'));
}
static deletedOrMissingSha = Git.deletedOrMissingSha;
static getGitPath = Git.getGitPath;
static getGitVersion = Git.getGitVersion;
static isShaLike = Git.isShaLike;
static isShaParent = Git.isShaParent;
static isStagedUncommitted = Git.isStagedUncommitted;
static isUncommitted = Git.isUncommitted;
static isUncommittedStaged = Git.isUncommittedStaged;
static uncommittedSha = Git.uncommittedSha;
static uncommittedStagedSha = Git.uncommittedStagedSha;
static shortenSha(
ref: string | undefined,
strings: { deletedOrMissing?: string; stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
{
deletedOrMissing = '(deleted)',
...strings
}: { deletedOrMissing?: string; stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
) {
if (ref === undefined) return undefined;
strings = { deletedOrMissing: '(deleted)', working: emptyStr, ...strings };
if (ref == null || ref.length === 0) return strings.working;
if (ref === GitService.deletedOrMissingSha) return strings.deletedOrMissing;
if (ref === GitService.deletedOrMissingSha) return deletedOrMissing;
return Git.isShaLike(ref) || Git.isStagedUncommitted(ref) ? Git.shortenSha(ref, strings) : ref;
return Git.shortenSha(ref, strings);
}
}

+ 4
- 4
src/git/gitUri.ts Прегледај датотеку

@ -68,7 +68,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
});
this.repoPath = data.repoPath;
if (GitService.isStagedUncommitted(data.ref) || !GitService.isUncommitted(data.ref)) {
if (GitService.isUncommittedStaged(data.ref) || !GitService.isUncommitted(data.ref)) {
this.sha = data.ref;
}
@ -123,7 +123,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
});
this.repoPath = commitOrRepoPath.repoPath;
this.versionedPath = commitOrRepoPath.versionedPath;
if (GitService.isStagedUncommitted(commitOrRepoPath.sha) || !GitService.isUncommitted(commitOrRepoPath.sha)) {
if (GitService.isUncommittedStaged(commitOrRepoPath.sha) || !GitService.isUncommitted(commitOrRepoPath.sha)) {
this.sha = commitOrRepoPath.sha;
}
}
@ -257,7 +257,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
switch (data.ref) {
case emptyStr:
case '~':
ref = GitService.stagedUncommittedSha;
ref = GitService.uncommittedStagedSha;
break;
case null:
@ -397,7 +397,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
}
if (ref === undefined || GitService.isUncommitted(ref)) {
if (GitService.isStagedUncommitted(ref)) {
if (GitService.isUncommittedStaged(ref)) {
return GitUri.git(fileName, repoPath);
}

+ 1
- 1
src/git/models/commit.ts Прегледај датотеку

@ -98,7 +98,7 @@ export abstract class GitCommit {
private _isStagedUncommitted: boolean | undefined;
get isStagedUncommitted(): boolean {
if (this._isStagedUncommitted === undefined) {
this._isStagedUncommitted = Git.isStagedUncommitted(this.sha);
this._isStagedUncommitted = Git.isUncommittedStaged(this.sha);
}
return this._isStagedUncommitted;
}

+ 2
- 2
src/quickpicks/repoStatusQuickPick.ts Прегледај датотеку

@ -54,7 +54,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
this.commit = new GitLogCommit(
GitCommitType.LogFile,
status.repoPath,
GitService.stagedUncommittedSha,
GitService.uncommittedStagedSha,
'You',
undefined,
new Date(),
@ -82,7 +82,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
[status],
status.status,
status.originalFileName,
realIndexStatus !== undefined ? GitService.stagedUncommittedSha : 'HEAD',
realIndexStatus !== undefined ? GitService.uncommittedStagedSha : 'HEAD',
status.fileName
);
}

+ 2
- 2
src/views/nodes/fileHistoryNode.ts Прегледај датотеку

@ -41,14 +41,14 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
if (status.workingTreeStatus !== undefined) {
sha = GitService.uncommittedSha;
if (status.indexStatus !== undefined) {
previousSha = GitService.stagedUncommittedSha;
previousSha = GitService.uncommittedStagedSha;
}
else if (status.workingTreeStatus !== '?') {
previousSha = 'HEAD';
}
}
else {
sha = GitService.stagedUncommittedSha;
sha = GitService.uncommittedStagedSha;
previousSha = 'HEAD';
}

+ 3
- 3
src/views/nodes/statusFilesNode.ts Прегледај датотеку

@ -67,12 +67,12 @@ export class StatusFilesNode extends ViewNode {
older.setMilliseconds(older.getMilliseconds() - 1);
return [
this.toStatusFile(s, GitService.uncommittedSha, GitService.stagedUncommittedSha),
this.toStatusFile(s, GitService.stagedUncommittedSha, 'HEAD', older)
this.toStatusFile(s, GitService.uncommittedSha, GitService.uncommittedStagedSha),
this.toStatusFile(s, GitService.uncommittedStagedSha, 'HEAD', older)
];
}
else if (s.indexStatus !== undefined) {
return [this.toStatusFile(s, GitService.stagedUncommittedSha, 'HEAD')];
return [this.toStatusFile(s, GitService.uncommittedStagedSha, 'HEAD')];
}
return [this.toStatusFile(s, GitService.uncommittedSha, 'HEAD')];

Loading…
Откажи
Сачувај