From f622ac1dd103f645ed5d5485ea180dd99efdb63d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 31 Oct 2021 19:50:00 -0400 Subject: [PATCH] Remove fs need for presence icons Splits path functions into system/paths module --- images/dark/icon-presence-away.svg | 4 --- images/dark/icon-presence-busy.svg | 4 --- images/dark/icon-presence-dnd.svg | 4 --- images/dark/icon-presence-offline.svg | 4 --- images/dark/icon-presence-online.svg | 4 --- src/avatars.ts | 17 ++++++++---- src/git/git.ts | 38 ++++++--------------------- src/git/gitService.ts | 23 ++++++++-------- src/system.ts | 1 + src/system/path.ts | 22 ++++++++++++++++ 10 files changed, 55 insertions(+), 66 deletions(-) delete mode 100644 images/dark/icon-presence-away.svg delete mode 100644 images/dark/icon-presence-busy.svg delete mode 100644 images/dark/icon-presence-dnd.svg delete mode 100644 images/dark/icon-presence-offline.svg delete mode 100644 images/dark/icon-presence-online.svg create mode 100644 src/system/path.ts diff --git a/images/dark/icon-presence-away.svg b/images/dark/icon-presence-away.svg deleted file mode 100644 index 3bc4f4dee99e2..0000000000000 --- a/images/dark/icon-presence-away.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/images/dark/icon-presence-busy.svg b/images/dark/icon-presence-busy.svg deleted file mode 100644 index aee856bc79f01..0000000000000 --- a/images/dark/icon-presence-busy.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/images/dark/icon-presence-dnd.svg b/images/dark/icon-presence-dnd.svg deleted file mode 100644 index aee856bc79f01..0000000000000 --- a/images/dark/icon-presence-dnd.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/images/dark/icon-presence-offline.svg b/images/dark/icon-presence-offline.svg deleted file mode 100644 index 3bc4f4dee99e2..0000000000000 --- a/images/dark/icon-presence-offline.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/images/dark/icon-presence-online.svg b/images/dark/icon-presence-online.svg deleted file mode 100644 index 58b35a4e194eb..0000000000000 --- a/images/dark/icon-presence-online.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/avatars.ts b/src/avatars.ts index bf491045f4bbc..d1ceb1b9268a8 100644 --- a/src/avatars.ts +++ b/src/avatars.ts @@ -1,5 +1,4 @@ 'use strict'; -import * as fs from 'fs'; import { EventEmitter, Uri } from 'vscode'; import { GravatarDefaultStyle } from './config'; import { GlobalState } from './constants'; @@ -221,13 +220,21 @@ async function getAvatarUriFromRemoteProvider( } } +const presenceStatusColorMap = new Map([ + ['online', '#28ca42'], + ['away', '#cecece'], + ['busy', '#ca5628'], + ['dnd', '#ca5628'], + ['offline', '#cecece'], +]); + export function getPresenceDataUri(status: ContactPresenceStatus) { let dataUri = presenceCache.get(status); if (dataUri == null) { - const contents = fs - .readFileSync(Container.context.asAbsolutePath(`images/dark/icon-presence-${status}.svg`)) - .toString('base64'); - + const contents = Strings.base64(` + + +`); dataUri = encodeURI(`data:image/svg+xml;base64,${contents}`); presenceCache.set(status, dataUri); } diff --git a/src/git/git.ts b/src/git/git.ts index de8728231b371..36c19b946140c 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -7,7 +7,7 @@ import { Uri, window, workspace } from 'vscode'; import { GlyphChars } from '../constants'; import { Container } from '../container'; import { Logger } from '../logger'; -import { Strings } from '../system'; +import { Paths, Strings } from '../system'; import { findGitPath, GitLocation } from './locator'; import { GitRevision } from './models/models'; import { GitBranchParser, GitLogParser, GitReflogParser, GitStashParser, GitTagParser } from './parsers/parsers'; @@ -26,7 +26,6 @@ const emptyArray = Object.freeze([]) as unknown as any[]; const emptyObj = Object.freeze({}); const emptyStr = ''; export const maxGitCliLength = 30000; -const slash = '/'; const textDecoder = new TextDecoder('utf8'); @@ -235,27 +234,6 @@ export namespace Git { ); } - export function splitPath( - fileName: string, - repoPath: string | undefined, - extract: boolean = true, - ): [string, string] { - if (repoPath) { - fileName = Strings.normalizePath(fileName); - repoPath = Strings.normalizePath(repoPath); - - const normalizedRepoPath = (repoPath.endsWith(slash) ? repoPath : `${repoPath}/`).toLowerCase(); - if (fileName.toLowerCase().startsWith(normalizedRepoPath)) { - fileName = fileName.substring(normalizedRepoPath.length); - } - } else { - repoPath = Strings.normalizePath(extract ? paths.dirname(fileName) : repoPath!); - fileName = Strings.normalizePath(extract ? paths.basename(fileName) : fileName); - } - - return [fileName, repoPath]; - } - export function validateVersion(major: number, minor: number): boolean { const [gitMajor, gitMinor] = gitInfo.version.split('.'); return parseInt(gitMajor, 10) >= major && parseInt(gitMinor, 10) >= minor; @@ -283,7 +261,7 @@ export namespace Git { ref?: string, options: { args?: string[] | null; ignoreWhitespace?: boolean; startLine?: number; endLine?: number } = {}, ) { - const [file, root] = Git.splitPath(fileName, repoPath); + const [file, root] = Paths.splitPath(fileName, repoPath); const params = ['blame', '--root', '--incremental']; @@ -355,7 +333,7 @@ export namespace Git { endLine?: number; } = {}, ) { - const [file, root] = Git.splitPath(fileName, repoPath); + const [file, root] = Paths.splitPath(fileName, repoPath); const params = ['blame', '--root', '--incremental']; @@ -453,7 +431,7 @@ export namespace Git { params.push(ref, '--'); if (fileName) { - [fileName, repoPath] = Git.splitPath(fileName, repoPath); + [fileName, repoPath] = Paths.splitPath(fileName, repoPath); params.push(fileName); } @@ -856,7 +834,7 @@ export namespace Git { endLine?: number; } = {}, ) { - const [file, root] = Git.splitPath(fileName, repoPath); + const [file, root] = Paths.splitPath(fileName, repoPath); const params = [ 'log', @@ -1350,7 +1328,7 @@ export namespace Git { encoding?: 'binary' | 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'hex' | 'buffer'; } = {}, ): Promise { - const [file, root] = Git.splitPath(fileName, repoPath); + const [file, root] = Paths.splitPath(fileName, repoPath); if (GitRevision.isUncommittedStaged(ref)) { ref = ':'; @@ -1419,7 +1397,7 @@ export namespace Git { } export function stash__apply(repoPath: string, stashName: string, deleteAfter: boolean) { - if (!stashName) return undefined; + if (!stashName) return Promise.resolve(undefined); return git({ cwd: repoPath }, 'stash', deleteAfter ? 'pop' : 'apply', stashName); } @@ -1530,7 +1508,7 @@ export namespace Git { porcelainVersion: number = 1, { similarityThreshold }: { similarityThreshold?: number | null } = {}, ): Promise { - const [file, root] = Git.splitPath(fileName, repoPath); + const [file, root] = Paths.splitPath(fileName, repoPath); const params = ['status', porcelainVersion >= 2 ? `--porcelain=v${porcelainVersion}` : '--porcelain']; if (Git.validateVersion(2, 18)) { diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 14391a656673f..1ecd4dddf0913 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -34,6 +34,7 @@ import { gate, Iterables, log, + Paths, Promises, Strings, TernarySearchTree, @@ -928,7 +929,7 @@ export class GitService implements Disposable { return emptyPromise as Promise; } - const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); + const [file, root] = Paths.splitPath(uri.fsPath, uri.repoPath, false); try { const data = await Git.blame(root, file, uri.sha, { @@ -1011,7 +1012,7 @@ export class GitService implements Disposable { return emptyPromise as Promise; } - const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); + const [file, root] = Paths.splitPath(uri.fsPath, uri.repoPath, false); try { const data = await Git.blame__contents(root, file, contents, { @@ -1740,7 +1741,7 @@ export class GitService implements Disposable { key: string, cc: LogCorrelationContext | undefined, ): Promise { - const [file, root] = Git.splitPath(fileName, repoPath, false); + const [file, root] = Paths.splitPath(fileName, repoPath, false); try { // let data; @@ -1846,7 +1847,7 @@ export class GitService implements Disposable { key: string, cc: LogCorrelationContext | undefined, ): Promise { - const [file, root] = Git.splitPath(fileName, repoPath, false); + const [file, root] = Paths.splitPath(fileName, repoPath, false); try { const data = await Git.diff__contents(root, file, ref, contents, { @@ -2427,7 +2428,7 @@ export class GitService implements Disposable { return emptyPromise as Promise; } - const [file, root] = Git.splitPath(fileName, repoPath, false); + const [file, root] = Paths.splitPath(fileName, repoPath, false); try { if (range != null && range.start.line > range.end.line) { @@ -3973,7 +3974,7 @@ export class GitService implements Disposable { let cacheKey: string; let fileName: string; if (typeof fileNameOrUri === 'string') { - [fileName, repoPath] = Git.splitPath(fileNameOrUri, repoPath); + [fileName, repoPath] = Paths.splitPath(fileNameOrUri, repoPath); cacheKey = GitUri.toKey(fileNameOrUri); } else { if (!this.isTrackable(fileNameOrUri)) return false; @@ -4181,7 +4182,7 @@ export class GitService implements Disposable { stageFile(repoPath: string, fileNameOrUri: string | Uri): Promise { return Git.add( repoPath, - typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0], + typeof fileNameOrUri === 'string' ? fileNameOrUri : Paths.splitPath(fileNameOrUri.fsPath, repoPath)[0], ); } @@ -4191,7 +4192,7 @@ export class GitService implements Disposable { stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise { return Git.add( repoPath, - typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0], + typeof directoryOrUri === 'string' ? directoryOrUri : Paths.splitPath(directoryOrUri.fsPath, repoPath)[0], ); } @@ -4201,7 +4202,7 @@ export class GitService implements Disposable { unStageFile(repoPath: string, fileNameOrUri: string | Uri): Promise { return Git.reset( repoPath, - typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0], + typeof fileNameOrUri === 'string' ? fileNameOrUri : Paths.splitPath(fileNameOrUri.fsPath, repoPath)[0], ); } @@ -4211,7 +4212,7 @@ export class GitService implements Disposable { unStageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise { return Git.reset( repoPath, - typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0], + typeof directoryOrUri === 'string' ? directoryOrUri : Paths.splitPath(directoryOrUri.fsPath, repoPath)[0], ); } @@ -4240,7 +4241,7 @@ export class GitService implements Disposable { ' Please retry by stashing everything or install a more recent version of Git.', ); - const pathspecs = uris.map(u => `./${Git.splitPath(u.fsPath, repoPath)[0]}`); + const pathspecs = uris.map(u => `./${Paths.splitPath(u.fsPath, repoPath)[0]}`); const stdinVersion = '2.30.0'; const stdin = GitService.compareGitVersion(stdinVersion) !== -1; diff --git a/src/system.ts b/src/system.ts index 101c6a437eb36..e32f8ae77c5a2 100644 --- a/src/system.ts +++ b/src/system.ts @@ -27,6 +27,7 @@ export * from './system/decorators/timeout'; export * as Functions from './system/function'; export * as Iterables from './system/iterable'; export * as Objects from './system/object'; +export * as Paths from './system/path'; export * as Promises from './system/promise'; export * from './system/searchTree'; export * from './system/stopwatch'; diff --git a/src/system/path.ts b/src/system/path.ts new file mode 100644 index 0000000000000..664ad8cc67642 --- /dev/null +++ b/src/system/path.ts @@ -0,0 +1,22 @@ +'use strict'; +import * as paths from 'path'; +import { normalizePath } from './string'; + +const slash = '/'; + +export function splitPath(fileName: string, repoPath: string | undefined, extract: boolean = true): [string, string] { + if (repoPath) { + fileName = normalizePath(fileName); + repoPath = normalizePath(repoPath); + + const normalizedRepoPath = (repoPath.endsWith(slash) ? repoPath : `${repoPath}/`).toLowerCase(); + if (fileName.toLowerCase().startsWith(normalizedRepoPath)) { + fileName = fileName.substring(normalizedRepoPath.length); + } + } else { + repoPath = normalizePath(extract ? paths.dirname(fileName) : repoPath!); + fileName = normalizePath(extract ? paths.basename(fileName) : fileName); + } + + return [fileName, repoPath]; +}