Skip to content

Commit

Permalink
Removes statics for better tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Aug 8, 2022
1 parent 97f6487 commit 9229adf
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 91 deletions.
8 changes: 4 additions & 4 deletions src/commands/base.ts
Expand Up @@ -11,8 +11,8 @@ import type { ActionContext } from '../api/gitlens';
import type { Commands } from '../constants';
import type { GitBranch } from '../git/models/branch';
import { isBranch } from '../git/models/branch';
import type { GitStashCommit } from '../git/models/commit';
import { GitCommit } from '../git/models/commit';
import type { GitCommit, GitStashCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import { GitContributor } from '../git/models/contributor';
import type { GitFile } from '../git/models/file';
import type { GitReference } from '../git/models/reference';
Expand Down Expand Up @@ -99,7 +99,7 @@ export function isCommandContextViewNodeHasCommit<T extends GitCommit | GitStash
): context is CommandViewNodeContext & { node: ViewNode & { commit: T } } {
if (context.type !== 'viewItem') return false;

return GitCommit.is((context.node as ViewNode & { commit: GitCommit | GitStashCommit }).commit);
return isCommit((context.node as ViewNode & { commit: GitCommit | GitStashCommit }).commit);
}

export function isCommandContextViewNodeHasContributor(
Expand All @@ -125,7 +125,7 @@ export function isCommandContextViewNodeHasFileCommit(
if (context.type !== 'viewItem') return false;

const node = context.node as ViewNode & { commit: GitCommit; file: GitFile; repoPath: string };
return node.file != null && GitCommit.is(node.commit) && (node.file.repoPath != null || node.repoPath != null);
return node.file != null && isCommit(node.commit) && (node.file.repoPath != null || node.repoPath != null);
}

export function isCommandContextViewNodeHasFileRefs(context: CommandContext): context is CommandViewNodeContext & {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/diffWith.ts
Expand Up @@ -2,7 +2,8 @@ import type { TextDocumentShowOptions, Uri } from 'vscode';
import { Range, ViewColumn } from 'vscode';
import { Commands, CoreCommands, GlyphChars } from '../constants';
import type { Container } from '../container';
import { GitCommit } from '../git/models/commit';
import type { GitCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import { GitRevision } from '../git/models/reference';
import { Logger } from '../logger';
import { showGenericErrorMessage } from '../messages';
Expand Down Expand Up @@ -31,7 +32,7 @@ export class DiffWithCommand extends Command {
static getMarkdownCommandArgs(commit: GitCommit, line?: number): string;
static getMarkdownCommandArgs(argsOrCommit: DiffWithCommandArgs | GitCommit, line?: number): string {
let args: DiffWithCommandArgs | GitCommit;
if (GitCommit.is(argsOrCommit)) {
if (isCommit(argsOrCommit)) {
const commit = argsOrCommit;
if (commit.file == null || commit.unresolvedPreviousSha == null) {
debugger;
Expand Down
10 changes: 5 additions & 5 deletions src/commands/git/show.ts
@@ -1,6 +1,6 @@
import type { Container } from '../../container';
import type { GitStashCommit } from '../../git/models/commit';
import { GitCommit } from '../../git/models/commit';
import type { GitCommit, GitStashCommit } from '../../git/models/commit';
import { isCommit } from '../../git/models/commit';
import type { GitRevisionReference } from '../../git/models/reference';
import { Repository } from '../../git/models/repository';
import { CommitFilesQuickPickItem } from '../../quickpicks/items/commits';
Expand Down Expand Up @@ -48,7 +48,7 @@ function assertStateStepRepository(state: PartialStepState<State>): asserts stat

type CommitStepState = SomeNonNullable<RepositoryStepState<State<GitCommit | GitStashCommit>>, 'reference'>;
function assertsStateStepCommit(state: RepositoryStepState): asserts state is CommitStepState {
if (GitCommit.is(state.reference)) return;
if (isCommit(state.reference)) return;

debugger;
throw new Error('Missing reference');
Expand Down Expand Up @@ -138,10 +138,10 @@ export class ShowGitCommand extends QuickCommand<State> {
if (
state.counter < 2 ||
state.reference == null ||
!GitCommit.is(state.reference) ||
!isCommit(state.reference) ||
state.reference.file != null
) {
if (state.reference != null && !GitCommit.is(state.reference)) {
if (state.reference != null && !isCommit(state.reference)) {
state.reference = await this.container.git.getCommit(state.reference.repoPath, state.reference.ref);
}

Expand Down
53 changes: 27 additions & 26 deletions src/commands/gitCommands.actions.ts
Expand Up @@ -11,7 +11,8 @@ import type { FileAnnotationType } from '../configuration';
import { Commands, CoreCommands } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitCommit } from '../git/models/commit';
import type { GitCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import type { GitContributor } from '../git/models/contributor';
import type { GitFile } from '../git/models/file';
import type {
Expand Down Expand Up @@ -170,30 +171,30 @@ export namespace GitActions {
ref2?: GitRevisionReference,
) {
// Open the working file to ensure undo will work
(await GitActions.Commit.openFile(file, ref1, { preserveFocus: true, preview: false }));
await GitActions.Commit.openFile(file, ref1, { preserveFocus: true, preview: false });

let ref = ref1.ref;
// If the file is `?` (untracked), then this must be a stash, so get the ^3 commit to access the untracked file
if (typeof file !== 'string' && file.status === '?') {
ref = `${ref}^3`;
}

(await Container.instance.git.applyChangesToWorkingFile(
await Container.instance.git.applyChangesToWorkingFile(
GitUri.fromFile(file, ref1.repoPath, ref),
ref,
ref2?.ref,
));
);
}

export async function copyIdToClipboard(ref: { repoPath: string; ref: string } | GitCommit) {
(await env.clipboard.writeText(ref.ref));
await env.clipboard.writeText(ref.ref);
}

export async function copyMessageToClipboard(
ref: { repoPath: string; ref: string } | GitCommit,
): Promise<void> {
let commit;
if (GitCommit.is(ref)) {
if (isCommit(ref)) {
commit = ref;
if (commit.message == null) {
await commit.ensureFullDetails();
Expand All @@ -204,7 +205,7 @@ export namespace GitActions {
}

const message = commit.message ?? commit.summary;
(await env.clipboard.writeText(message));
await env.clipboard.writeText(message);
}

export async function openAllChanges(commit: GitCommit, options?: TextDocumentShowOptions): Promise<void>;
Expand All @@ -220,7 +221,7 @@ export namespace GitActions {
) {
let files;
let refs;
if (GitCommit.is(commitOrFiles)) {
if (isCommit(commitOrFiles)) {
if (commitOrFiles.files == null) {
await commitOrFiles.ensureFullDetails();
}
Expand Down Expand Up @@ -265,7 +266,7 @@ export namespace GitActions {
ref?: { repoPath: string; ref: string },
) {
let files;
if (GitCommit.is(commitOrFiles)) {
if (isCommit(commitOrFiles)) {
if (commitOrFiles.files == null) {
await commitOrFiles.ensureFullDetails();
}
Expand Down Expand Up @@ -309,7 +310,7 @@ export namespace GitActions {
) {
let files;
let ref;
if (GitCommit.is(commitOrFiles)) {
if (isCommit(commitOrFiles)) {
if (commitOrFiles.files == null) {
await commitOrFiles.ensureFullDetails();
}
Expand Down Expand Up @@ -338,7 +339,7 @@ export namespace GitActions {
options = { preserveFocus: true, preview: false, ...options };

for (const file of files) {
(await openChangesWithWorking(file, ref, options));
await openChangesWithWorking(file, ref, options);
}
}

Expand All @@ -358,7 +359,7 @@ export namespace GitActions {
options?: TextDocumentShowOptions,
) {
if (typeof file === 'string') {
if (!GitCommit.is(commitOrRefs)) throw new Error('Invalid arguments');
if (!isCommit(commitOrRefs)) throw new Error('Invalid arguments');

const f = await commitOrRefs.findFile(file);
if (f == null) throw new Error('Invalid arguments');
Expand All @@ -368,7 +369,7 @@ export namespace GitActions {

if (file.status === 'A') return;

const refs = GitCommit.is(commitOrRefs)
const refs = isCommit(commitOrRefs)
? {
repoPath: commitOrRefs.repoPath,
// Don't need to worry about verifying the previous sha, as the DiffWith command will
Expand Down Expand Up @@ -409,7 +410,7 @@ export namespace GitActions {
tool?: string,
) {
if (typeof file === 'string') {
if (!GitCommit.is(commitOrRef)) throw new Error('Invalid arguments');
if (!isCommit(commitOrRef)) throw new Error('Invalid arguments');

const f = await commitOrRef.findFile(file);
if (f == null) throw new Error('Invalid arguments');
Expand Down Expand Up @@ -445,7 +446,7 @@ export namespace GitActions {
options?: TextDocumentShowOptions,
) {
if (typeof file === 'string') {
if (!GitCommit.is(commitOrRef)) throw new Error('Invalid arguments');
if (!isCommit(commitOrRef)) throw new Error('Invalid arguments');

const f = await commitOrRef.findFile(file);
if (f == null) throw new Error('Invalid arguments');
Expand All @@ -456,7 +457,7 @@ export namespace GitActions {
if (file.status === 'D') return;

let ref;
if (GitCommit.is(commitOrRef)) {
if (isCommit(commitOrRef)) {
ref = {
repoPath: commitOrRef.repoPath,
ref: commitOrRef.sha,
Expand Down Expand Up @@ -541,12 +542,12 @@ export namespace GitActions {
): Promise<void> {
let uri;
if (fileOrRevisionUri instanceof Uri) {
if (GitCommit.is(commitOrOptions)) throw new Error('Invalid arguments');
if (isCommit(commitOrOptions)) throw new Error('Invalid arguments');

uri = fileOrRevisionUri;
options = commitOrOptions;
} else {
if (!GitCommit.is(commitOrOptions)) throw new Error('Invalid arguments');
if (!isCommit(commitOrOptions)) throw new Error('Invalid arguments');

const commit = commitOrOptions;

Expand Down Expand Up @@ -586,7 +587,7 @@ export namespace GitActions {
}

export async function openDetails(commit: GitCommit): Promise<void> {
(await Container.instance.commitDetailsView.show({ commit: commit }));
await Container.instance.commitDetailsView.show({ commit: commit });
}

export async function openFiles(commit: GitCommit): Promise<void>;
Expand All @@ -597,7 +598,7 @@ export namespace GitActions {
ref?: string,
): Promise<void> {
let files;
if (GitCommit.is(commitOrFiles)) {
if (isCommit(commitOrFiles)) {
if (commitOrFiles.files == null) {
await commitOrFiles.ensureFullDetails();
}
Expand Down Expand Up @@ -642,7 +643,7 @@ export namespace GitActions {
ref2?: string,
): Promise<void> {
let files;
if (GitCommit.is(commitOrFiles)) {
if (isCommit(commitOrFiles)) {
if (commitOrFiles.files == null) {
await commitOrFiles.ensureFullDetails();
}
Expand Down Expand Up @@ -683,7 +684,7 @@ export namespace GitActions {
file.status === `?` ? `${revision.ref}^3` : file.status === 'D' ? `${revision.ref}^` : revision.ref;
}

(await Container.instance.git.checkout(revision.repoPath, ref, { path: path }));
await Container.instance.git.checkout(revision.repoPath, ref, { path: path });
}

export async function reveal(
Expand Down Expand Up @@ -766,8 +767,8 @@ export namespace GitActions {
if (url == null || url.length === 0) return undefined;

repo = ensureRepo(repo);
(await Container.instance.git.addRemote(repo.path, name, url));
(await repo.fetch({ remote: name }));
await Container.instance.git.addRemote(repo.path, name, url);
await repo.fetch({ remote: name });

return name;
}
Expand All @@ -780,11 +781,11 @@ export namespace GitActions {
repo = r;
}

(await repo.fetch({ remote: remote }));
await repo.fetch({ remote: remote });
}

export async function prune(repo: string | Repository, remote: string) {
(await Container.instance.git.pruneRemote(typeof repo === 'string' ? repo : repo.path, remote));
await Container.instance.git.pruneRemote(typeof repo === 'string' ? repo : repo.path, remote);
}

export async function reveal(
Expand Down
12 changes: 6 additions & 6 deletions src/commands/quickCommand.steps.ts
Expand Up @@ -6,8 +6,8 @@ import type { PlusFeatures } from '../features';
import type { PagedResult } from '../git/gitProvider';
import type { BranchSortOptions, GitBranch } from '../git/models/branch';
import { sortBranches } from '../git/models/branch';
import type { GitStashCommit } from '../git/models/commit';
import { GitCommit } from '../git/models/commit';
import type { GitCommit, GitStashCommit } from '../git/models/commit';
import { isCommit, isStash } from '../git/models/commit';
import type { GitContributor } from '../git/models/contributor';
import type { GitLog } from '../git/models/log';
import type { GitBranchReference, GitRevisionReference, GitTagReference } from '../git/models/reference';
Expand Down Expand Up @@ -1626,7 +1626,7 @@ async function getShowCommitOrStashStepItems<

let unpublished: boolean | undefined;

if (GitCommit.isStash(state.reference)) {
if (isStash(state.reference)) {
items.push(
QuickPickSeparator.create('Actions'),
new GitCommandQuickPickItem('Apply Stash...', {
Expand Down Expand Up @@ -1672,7 +1672,7 @@ async function getShowCommitOrStashStepItems<
branch != null
? Container.instance.git.getCommitBranches(state.repo.path, state.reference.ref, {
branch: branch.name,
commitDate: GitCommit.is(state.reference) ? state.reference.committer.date : undefined,
commitDate: isCommit(state.reference) ? state.reference.committer.date : undefined,
})
: undefined,
!branch?.remote && branch?.upstream != null ? state.reference.isPushed() : undefined,
Expand Down Expand Up @@ -1852,7 +1852,7 @@ export function* showCommitOrStashFilesStep<
items: [
new CommitFilesQuickPickItem(state.reference, {
picked: state.fileName == null,
hint: `Click to see ${GitCommit.isStash(state.reference) ? 'stash' : 'commit'} actions`,
hint: `Click to see ${isStash(state.reference) ? 'stash' : 'commit'} actions`,
}),
QuickPickSeparator.create('Files'),
...(state.reference.files?.map(
Expand Down Expand Up @@ -1990,7 +1990,7 @@ async function getShowCommitOrStashFileStepItems<

const items: (CommandQuickPickItem | QuickPickSeparator)[] = [];

if (GitCommit.isStash(state.reference)) {
if (isStash(state.reference)) {
items.push(
QuickPickSeparator.create(),
new CommitCopyMessageQuickPickItem(state.reference),
Expand Down
6 changes: 3 additions & 3 deletions src/commands/showQuickCommitFile.ts
Expand Up @@ -3,8 +3,8 @@ import { Uri, window } from 'vscode';
import { Commands } from '../constants';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import type { GitStashCommit } from '../git/models/commit';
import { GitCommit } from '../git/models/commit';
import type { GitCommit, GitStashCommit } from '../git/models/commit';
import { isCommit } from '../git/models/commit';
import type { GitLog } from '../git/models/log';
import { Logger } from '../logger';
import {
Expand Down Expand Up @@ -136,7 +136,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
}

const path = args.commit?.file?.path ?? gitUri.fsPath;
if (GitCommit.is(args.commit)) {
if (isCommit(args.commit)) {
if (args.commit.files == null) {
await args.commit.ensureFullDetails();
}
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Expand Up @@ -10,7 +10,7 @@ import { Container } from './container';
import { setContext } from './context';
import { isGitUri } from './git/gitUri';
import { getBranchNameWithoutRemote } from './git/models/branch';
import { GitCommit } from './git/models/commit';
import { isCommit } from './git/models/commit';
import { Logger, LogLevel } from './logger';
import { showDebugLoggingWarningMessage, showInsidersErrorMessage, showWhatsNewMessage } from './messages';
import { registerPartnerActionRunners } from './partners';
Expand All @@ -34,7 +34,7 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |
})`;
}

if (GitCommit.is(o)) {
if (isCommit(o)) {
return `GitCommit(${o.sha ? ` sha=${o.sha}` : ''}${o.repoPath ? ` repoPath=${o.repoPath}` : ''})`;
}

Expand Down

0 comments on commit 9229adf

Please sign in to comment.