Skip to content

Commit 6d9a666

Browse files
committed
Renames some members for consistency
1 parent 4c79d0f commit 6d9a666

File tree

10 files changed

+75
-72
lines changed

10 files changed

+75
-72
lines changed

src/annotations/annotations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Annotations {
121121

122122
let message: string;
123123
if (commit.isUncommitted) {
124-
if (uri.sha !== undefined && GitService.isStagedUncommitted(uri.sha)) {
124+
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
125125
message = `[\`Changes\`](${DiffWithCommand.getMarkdownCommandArgs(
126126
commit,
127127
editorLine
@@ -173,7 +173,7 @@ export class Annotations {
173173
): Promise<Partial<DecorationOptions>> {
174174
let ref;
175175
if (commit.isUncommitted) {
176-
if (uri.sha !== undefined && GitService.isStagedUncommitted(uri.sha)) {
176+
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
177177
ref = uri.sha;
178178
}
179179
}

src/commands/diffLineWithWorking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
5252
args.commit = args.commit.with({
5353
sha:
5454
status !== undefined && status.indexStatus !== undefined
55-
? GitService.stagedUncommittedSha
55+
? GitService.uncommittedStagedSha
5656
: args.commit.previousSha!,
5757
fileName: args.commit.previousFileName!,
5858
originalFileName: null,

src/commands/diffWithWorking.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
6161
}
6262

6363
// If we are a fake "staged" sha, check the status
64-
if (GitService.isStagedUncommitted(gitUri.sha!)) {
64+
if (GitService.isUncommittedStaged(gitUri.sha!)) {
6565
gitUri.sha = undefined;
6666

6767
const status = await Container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath);
6868
if (status !== undefined && status.indexStatus !== undefined) {
69-
let sha = GitService.stagedUncommittedSha;
69+
let sha = GitService.uncommittedStagedSha;
7070
if (args.inDiffEditor) {
7171
const commit = await Container.git.getCommitForFile(gitUri.repoPath!, gitUri.fsPath);
7272
if (commit === undefined) return Messages.showCommitHasNoPreviousCommitWarningMessage();

src/git/git.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ export class Git {
206206
static shaRegex = /(^[0-9a-f]{40}$)|(^[0]{40}(:|-)$)/;
207207
static shaParentRegex = /^[0-9a-f]{40}\^[0-3]?$/;
208208
static shaShortenRegex = /^(.*?)([\^@~:].*)?$/;
209-
static stagedUncommittedRegex = /^[0]{40}([\^@~]\S*)?:$/;
210-
static stagedUncommittedSha = '0000000000000000000000000000000000000000:';
211209
static uncommittedRegex = /^[0]{40}(?:[\^@~:]\S*)?:?$/;
212210
static uncommittedSha = '0000000000000000000000000000000000000000';
211+
static uncommittedStagedRegex = /^[0]{40}([\^@~]\S*)?:$/;
212+
static uncommittedStagedSha = '0000000000000000000000000000000000000000:';
213213

214214
static getEncoding(encoding: string | undefined) {
215215
return encoding !== undefined && iconv.encodingExists(encoding) ? encoding : 'utf8';
@@ -247,27 +247,29 @@ export class Git {
247247
return Git.shaParentRegex.test(ref);
248248
}
249249

250-
static isStagedUncommitted(ref: string | undefined): boolean {
251-
return ref ? Git.stagedUncommittedRegex.test(ref) : false;
252-
}
253-
254250
static isUncommitted(ref: string | undefined) {
255251
return ref ? Git.uncommittedRegex.test(ref) : false;
256252
}
257253

254+
static isUncommittedStaged(ref: string | undefined): boolean {
255+
return ref ? Git.uncommittedStagedRegex.test(ref) : false;
256+
}
257+
258258
static shortenSha(
259-
ref: string,
260-
strings: { stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
259+
ref: string | undefined,
260+
{
261+
stagedUncommitted = 'Index',
262+
uncommitted = 'Working Tree',
263+
working = emptyStr
264+
}: { stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
261265
) {
262-
strings = { stagedUncommitted: 'Index', uncommitted: 'Working Tree', working: emptyStr, ...strings };
263-
264-
if (ref == null || ref.length === 0) return strings.working;
266+
if (ref == null || ref.length === 0) return working;
265267
if (Git.isUncommitted(ref)) {
266-
if (Git.isStagedUncommitted(ref)) return strings.stagedUncommitted;
267-
268-
return strings.uncommitted;
268+
return Git.isUncommittedStaged(ref) ? stagedUncommitted : uncommitted;
269269
}
270270

271+
if (!Git.isShaLike(ref)) return ref;
272+
271273
// Don't allow shas to be shortened to less than 5 characters
272274
const len = Math.max(5, Container.config.advanced.abbreviatedShaLength);
273275

@@ -343,7 +345,7 @@ export class Git {
343345

344346
let stdin;
345347
if (ref) {
346-
if (Git.isStagedUncommitted(ref)) {
348+
if (Git.isUncommittedStaged(ref)) {
347349
// Pipe the blame contents to stdin
348350
params.push('--contents', '-');
349351

@@ -496,10 +498,10 @@ export class Git {
496498
if (ref1.endsWith('^3^')) {
497499
ref1 = rootSha;
498500
}
499-
params.push(Git.isStagedUncommitted(ref1) ? '--staged' : ref1);
501+
params.push(Git.isUncommittedStaged(ref1) ? '--staged' : ref1);
500502
}
501503
if (ref2) {
502-
params.push(Git.isStagedUncommitted(ref2) ? '--staged' : ref2);
504+
params.push(Git.isUncommittedStaged(ref2) ? '--staged' : ref2);
503505
}
504506

505507
const encoding: BufferEncoding = options.encoding === 'utf8' ? 'utf8' : 'binary';
@@ -637,7 +639,7 @@ export class Git {
637639
params.push('--use-mailmap', ...authors.map(a => `--author=${a}`));
638640
}
639641

640-
if (ref && !Git.isStagedUncommitted(ref)) {
642+
if (ref && !Git.isUncommittedStaged(ref)) {
641643
// If we are reversing, we must add a range (with HEAD) because we are using --ancestry-path for better reverse walking
642644
if (reverse) {
643645
params.push('--reverse', '--ancestry-path', `${ref}..HEAD`);
@@ -697,7 +699,7 @@ export class Git {
697699
params.push(`-L ${startLine},${endLine == null ? startLine : endLine}:${file}`);
698700
}
699701

700-
if (ref && !Git.isStagedUncommitted(ref)) {
702+
if (ref && !Git.isUncommittedStaged(ref)) {
701703
// If we are reversing, we must add a range (with HEAD) because we are using --ancestry-path for better reverse walking
702704
if (reverse) {
703705
params.push('--reverse', '--ancestry-path', `${ref}..HEAD`);
@@ -868,7 +870,7 @@ export class Git {
868870
): Promise<TOut | undefined> {
869871
const [file, root] = Git.splitPath(fileName, repoPath);
870872

871-
if (Git.isStagedUncommitted(ref)) {
873+
if (Git.isUncommittedStaged(ref)) {
872874
ref = ':';
873875
}
874876
if (Git.isUncommitted(ref)) throw new Error(`ref=${ref} is uncommitted`);

src/git/gitService.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,9 @@ export enum GitRepoSearchBy {
9393
Sha = 'sha'
9494
}
9595

96-
export class GitService implements Disposable {
97-
static emptyPromise: Promise<GitBlame | GitDiff | GitLog | undefined> = Promise.resolve(undefined);
98-
static deletedOrMissingSha = Git.deletedOrMissingSha;
99-
static stagedUncommittedSha = Git.stagedUncommittedSha;
100-
static uncommittedSha = Git.uncommittedSha;
96+
const emptyPromise: Promise<GitBlame | GitDiff | GitLog | undefined> = Promise.resolve(undefined);
10197

98+
export class GitService implements Disposable {
10299
private _onDidChangeRepositories = new EventEmitter<void>();
103100
get onDidChangeRepositories(): Event<void> {
104101
return this._onDidChangeRepositories.event;
@@ -672,7 +669,7 @@ export class GitService implements Disposable {
672669
): Promise<GitBlame | undefined> {
673670
if (!(await this.isTracked(uri))) {
674671
Logger.log(cc, `Skipping blame; '${uri.fsPath}' is not tracked`);
675-
return GitService.emptyPromise as Promise<GitBlame>;
672+
return emptyPromise as Promise<GitBlame>;
676673
}
677674

678675
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
@@ -692,14 +689,14 @@ export class GitService implements Disposable {
692689
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
693690

694691
const value: CachedBlame = {
695-
item: GitService.emptyPromise as Promise<GitBlame>,
692+
item: emptyPromise as Promise<GitBlame>,
696693
errorMessage: msg
697694
};
698695
document.state.set<CachedBlame>(key, value);
699696

700697
document.setBlameFailure();
701698

702-
return GitService.emptyPromise as Promise<GitBlame>;
699+
return emptyPromise as Promise<GitBlame>;
703700
}
704701

705702
return undefined;
@@ -756,7 +753,7 @@ export class GitService implements Disposable {
756753
): Promise<GitBlame | undefined> {
757754
if (!(await this.isTracked(uri))) {
758755
Logger.log(cc, `Skipping blame; '${uri.fsPath}' is not tracked`);
759-
return GitService.emptyPromise as Promise<GitBlame>;
756+
return emptyPromise as Promise<GitBlame>;
760757
}
761758

762759
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
@@ -777,13 +774,13 @@ export class GitService implements Disposable {
777774
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
778775

779776
const value: CachedBlame = {
780-
item: GitService.emptyPromise as Promise<GitBlame>,
777+
item: emptyPromise as Promise<GitBlame>,
781778
errorMessage: msg
782779
};
783780
document.state.set<CachedBlame>(key, value);
784781

785782
document.setBlameFailure();
786-
return GitService.emptyPromise as Promise<GitBlame>;
783+
return emptyPromise as Promise<GitBlame>;
787784
}
788785

789786
return undefined;
@@ -1169,7 +1166,7 @@ export class GitService implements Disposable {
11691166

11701167
try {
11711168
let data;
1172-
if (ref1 !== undefined && ref2 === undefined && !GitService.isStagedUncommitted(ref1)) {
1169+
if (ref1 !== undefined && ref2 === undefined && !GitService.isUncommittedStaged(ref1)) {
11731170
data = await Git.show__diff(root, file, ref1, originalFileName, {
11741171
similarityThreshold: Container.config.advanced.similarityThreshold
11751172
});
@@ -1192,12 +1189,12 @@ export class GitService implements Disposable {
11921189
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
11931190

11941191
const value: CachedDiff = {
1195-
item: GitService.emptyPromise as Promise<GitDiff>,
1192+
item: emptyPromise as Promise<GitDiff>,
11961193
errorMessage: msg
11971194
};
11981195
document.state.set<CachedDiff>(key, value);
11991196

1200-
return GitService.emptyPromise as Promise<GitDiff>;
1197+
return emptyPromise as Promise<GitDiff>;
12011198
}
12021199

12031200
return undefined;
@@ -1216,7 +1213,7 @@ export class GitService implements Disposable {
12161213
let diff = await this.getDiffForFile(uri, ref1, ref2, originalFileName);
12171214
// If we didn't find a diff & ref1 is undefined (meaning uncommitted), check for a staged diff
12181215
if (diff === undefined && ref1 === undefined) {
1219-
diff = await this.getDiffForFile(uri, Git.stagedUncommittedSha, ref2, originalFileName);
1216+
diff = await this.getDiffForFile(uri, Git.uncommittedStagedSha, ref2, originalFileName);
12201217
}
12211218

12221219
if (diff === undefined) return undefined;
@@ -1537,7 +1534,7 @@ export class GitService implements Disposable {
15371534
): Promise<GitLog | undefined> {
15381535
if (!(await this.isTracked(fileName, repoPath, { ref: ref }))) {
15391536
Logger.log(cc, `Skipping log; '${fileName}' is not tracked`);
1540-
return GitService.emptyPromise as Promise<GitLog>;
1537+
return emptyPromise as Promise<GitLog>;
15411538
}
15421539

15431540
const [file, root] = Git.splitPath(fileName, repoPath, false);
@@ -1582,12 +1579,12 @@ export class GitService implements Disposable {
15821579
Logger.debug(cc, `Cache replace (with empty promise): '${key}'`);
15831580

15841581
const value: CachedLog = {
1585-
item: GitService.emptyPromise as Promise<GitLog>,
1582+
item: emptyPromise as Promise<GitLog>,
15861583
errorMessage: msg
15871584
};
15881585
document.state.set<CachedLog>(key, value);
15891586

1590-
return GitService.emptyPromise as Promise<GitLog>;
1587+
return emptyPromise as Promise<GitLog>;
15911588
}
15921589

15931590
return undefined;
@@ -1641,7 +1638,7 @@ export class GitService implements Disposable {
16411638

16421639
const fileName = GitUri.getRelativePath(uri, repoPath);
16431640

1644-
if (Git.isStagedUncommitted(ref)) {
1641+
if (Git.isUncommittedStaged(ref)) {
16451642
return {
16461643
current: GitUri.fromFile(fileName, repoPath, ref),
16471644
next: GitUri.fromFile(fileName, repoPath, undefined)
@@ -1656,7 +1653,7 @@ export class GitService implements Disposable {
16561653
if (status.indexStatus !== undefined) {
16571654
return {
16581655
current: GitUri.fromFile(fileName, repoPath, ref),
1659-
next: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha)
1656+
next: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha)
16601657
};
16611658
}
16621659
}
@@ -1682,7 +1679,7 @@ export class GitService implements Disposable {
16821679
// editorLine?: number
16831680
): Promise<GitUri | undefined> {
16841681
// If we have no ref (or staged ref) there is no next commit
1685-
if (ref === undefined || ref.length === 0 || Git.isStagedUncommitted(ref)) return undefined;
1682+
if (ref === undefined || ref.length === 0 || Git.isUncommittedStaged(ref)) return undefined;
16861683

16871684
let filters: GitLogDiffFilter[] | undefined;
16881685
if (ref === GitService.deletedOrMissingSha) {
@@ -1746,18 +1743,18 @@ export class GitService implements Disposable {
17461743
if (skip === 0) {
17471744
return {
17481745
current: GitUri.fromFile(fileName, repoPath, ref),
1749-
previous: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha)
1746+
previous: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha)
17501747
};
17511748
}
17521749

17531750
return {
1754-
current: GitUri.fromFile(fileName, repoPath, GitService.stagedUncommittedSha),
1751+
current: GitUri.fromFile(fileName, repoPath, GitService.uncommittedStagedSha),
17551752
previous: await this.getPreviousUri(repoPath, uri, ref, skip - 1, editorLine)
17561753
};
17571754
}
17581755
}
17591756
}
1760-
else if (GitService.isStagedUncommitted(ref)) {
1757+
else if (GitService.isUncommittedStaged(ref)) {
17611758
const current =
17621759
skip === 0
17631760
? GitUri.fromFile(fileName, repoPath, ref)
@@ -1791,6 +1788,9 @@ export class GitService implements Disposable {
17911788
editorLine?: number
17921789
): Promise<GitUri | undefined> {
17931790
if (ref === GitService.deletedOrMissingSha) return undefined;
1791+
if (ref === GitService.uncommittedSha) {
1792+
ref = undefined;
1793+
}
17941794

17951795
if (ref !== undefined) {
17961796
skip++;
@@ -2130,14 +2130,14 @@ export class GitService implements Disposable {
21302130
): Promise<Uri | undefined> {
21312131
if (ref === GitService.deletedOrMissingSha) return undefined;
21322132

2133-
if (!ref || (Git.isUncommitted(ref) && !Git.isStagedUncommitted(ref))) {
2133+
if (!ref || (Git.isUncommitted(ref) && !Git.isUncommittedStaged(ref))) {
21342134
const data = await Git.ls_files(repoPath!, fileName);
21352135
if (data !== undefined) return GitUri.file(fileName);
21362136

21372137
return undefined;
21382138
}
21392139

2140-
if (Git.isStagedUncommitted(ref)) {
2140+
if (Git.isUncommittedStaged(ref)) {
21412141
return GitUri.git(fileName, repoPath);
21422142
}
21432143

@@ -2435,24 +2435,25 @@ export class GitService implements Disposable {
24352435
return Git.getEncoding(workspace.getConfiguration('files', uri).get<string>('encoding'));
24362436
}
24372437

2438+
static deletedOrMissingSha = Git.deletedOrMissingSha;
24382439
static getGitPath = Git.getGitPath;
24392440
static getGitVersion = Git.getGitVersion;
24402441
static isShaLike = Git.isShaLike;
24412442
static isShaParent = Git.isShaParent;
2442-
static isStagedUncommitted = Git.isStagedUncommitted;
24432443
static isUncommitted = Git.isUncommitted;
2444+
static isUncommittedStaged = Git.isUncommittedStaged;
2445+
static uncommittedSha = Git.uncommittedSha;
2446+
static uncommittedStagedSha = Git.uncommittedStagedSha;
24442447

24452448
static shortenSha(
24462449
ref: string | undefined,
2447-
strings: { deletedOrMissing?: string; stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
2450+
{
2451+
deletedOrMissing = '(deleted)',
2452+
...strings
2453+
}: { deletedOrMissing?: string; stagedUncommitted?: string; uncommitted?: string; working?: string } = {}
24482454
) {
2449-
if (ref === undefined) return undefined;
2450-
2451-
strings = { deletedOrMissing: '(deleted)', working: emptyStr, ...strings };
2452-
2453-
if (ref == null || ref.length === 0) return strings.working;
2454-
if (ref === GitService.deletedOrMissingSha) return strings.deletedOrMissing;
2455+
if (ref === GitService.deletedOrMissingSha) return deletedOrMissing;
24552456

2456-
return Git.isShaLike(ref) || Git.isStagedUncommitted(ref) ? Git.shortenSha(ref, strings) : ref;
2457+
return Git.shortenSha(ref, strings);
24572458
}
24582459
}

0 commit comments

Comments
 (0)