Skip to content

Commit

Permalink
Remove fs need for presence icons
Browse files Browse the repository at this point in the history
Splits path functions into system/paths module
  • Loading branch information
eamodio committed Nov 3, 2021
1 parent 0f27b62 commit f622ac1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 66 deletions.
4 changes: 0 additions & 4 deletions images/dark/icon-presence-away.svg

This file was deleted.

4 changes: 0 additions & 4 deletions images/dark/icon-presence-busy.svg

This file was deleted.

4 changes: 0 additions & 4 deletions images/dark/icon-presence-dnd.svg

This file was deleted.

4 changes: 0 additions & 4 deletions images/dark/icon-presence-offline.svg

This file was deleted.

4 changes: 0 additions & 4 deletions images/dark/icon-presence-online.svg

This file was deleted.

17 changes: 12 additions & 5 deletions 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';
Expand Down Expand Up @@ -221,13 +220,21 @@ async function getAvatarUriFromRemoteProvider(
}
}

const presenceStatusColorMap = new Map<ContactPresenceStatus, string>([
['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(`<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="4" height="16" viewBox="0 0 4 16">
<circle cx="2" cy="14" r="2" fill="${presenceStatusColorMap.get(status)!}"/>
</svg>`);
dataUri = encodeURI(`data:image/svg+xml;base64,${contents}`);
presenceCache.set(status, dataUri);
}
Expand Down
38 changes: 8 additions & 30 deletions src/git/git.ts
Expand Up @@ -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';
Expand All @@ -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');

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -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'];

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -1350,7 +1328,7 @@ export namespace Git {
encoding?: 'binary' | 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'hex' | 'buffer';
} = {},
): Promise<TOut | undefined> {
const [file, root] = Git.splitPath(fileName, repoPath);
const [file, root] = Paths.splitPath(fileName, repoPath);

if (GitRevision.isUncommittedStaged(ref)) {
ref = ':';
Expand Down Expand Up @@ -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<string>({ cwd: repoPath }, 'stash', deleteAfter ? 'pop' : 'apply', stashName);
}

Expand Down Expand Up @@ -1530,7 +1508,7 @@ export namespace Git {
porcelainVersion: number = 1,
{ similarityThreshold }: { similarityThreshold?: number | null } = {},
): Promise<string> {
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)) {
Expand Down
23 changes: 12 additions & 11 deletions src/git/gitService.ts
Expand Up @@ -34,6 +34,7 @@ import {
gate,
Iterables,
log,
Paths,
Promises,
Strings,
TernarySearchTree,
Expand Down Expand Up @@ -928,7 +929,7 @@ export class GitService implements Disposable {
return emptyPromise as Promise<GitBlame>;
}

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, {
Expand Down Expand Up @@ -1011,7 +1012,7 @@ export class GitService implements Disposable {
return emptyPromise as Promise<GitBlame>;
}

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, {
Expand Down Expand Up @@ -1740,7 +1741,7 @@ export class GitService implements Disposable {
key: string,
cc: LogCorrelationContext | undefined,
): Promise<GitDiff | undefined> {
const [file, root] = Git.splitPath(fileName, repoPath, false);
const [file, root] = Paths.splitPath(fileName, repoPath, false);

try {
// let data;
Expand Down Expand Up @@ -1846,7 +1847,7 @@ export class GitService implements Disposable {
key: string,
cc: LogCorrelationContext | undefined,
): Promise<GitDiff | undefined> {
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, {
Expand Down Expand Up @@ -2427,7 +2428,7 @@ export class GitService implements Disposable {
return emptyPromise as Promise<GitLog>;
}

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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4181,7 +4182,7 @@ export class GitService implements Disposable {
stageFile(repoPath: string, fileNameOrUri: string | Uri): Promise<string> {
return Git.add(
repoPath,
typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0],
typeof fileNameOrUri === 'string' ? fileNameOrUri : Paths.splitPath(fileNameOrUri.fsPath, repoPath)[0],
);
}

Expand All @@ -4191,7 +4192,7 @@ export class GitService implements Disposable {
stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<string> {
return Git.add(
repoPath,
typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0],
typeof directoryOrUri === 'string' ? directoryOrUri : Paths.splitPath(directoryOrUri.fsPath, repoPath)[0],
);
}

Expand All @@ -4201,7 +4202,7 @@ export class GitService implements Disposable {
unStageFile(repoPath: string, fileNameOrUri: string | Uri): Promise<string> {
return Git.reset(
repoPath,
typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0],
typeof fileNameOrUri === 'string' ? fileNameOrUri : Paths.splitPath(fileNameOrUri.fsPath, repoPath)[0],
);
}

Expand All @@ -4211,7 +4212,7 @@ export class GitService implements Disposable {
unStageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<string> {
return Git.reset(
repoPath,
typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0],
typeof directoryOrUri === 'string' ? directoryOrUri : Paths.splitPath(directoryOrUri.fsPath, repoPath)[0],
);
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/system.ts
Expand Up @@ -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';
Expand Down
22 changes: 22 additions & 0 deletions 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];
}

0 comments on commit f622ac1

Please sign in to comment.