浏览代码

Avoids * imports for node libs

main
Eric Amodio 2 年前
父节点
当前提交
e0915eb66d
共有 31 个文件被更改,包括 122 次插入124 次删除
  1. +2
    -2
      src/annotations/fileAnnotationController.ts
  2. +2
    -2
      src/commands/browseRepoAtRevision.ts
  3. +2
    -2
      src/commands/common.ts
  4. +3
    -3
      src/commands/diffWith.ts
  5. +5
    -5
      src/commands/diffWithRevisionFrom.ts
  6. +2
    -2
      src/commands/openFileAtRevisionFrom.ts
  7. +6
    -10
      src/env/node/git/git.ts
  8. +17
    -17
      src/env/node/git/localGitProvider.ts
  9. +2
    -2
      src/env/node/git/locator.ts
  10. +16
    -16
      src/env/node/git/shell.ts
  11. +2
    -2
      src/git/formatters/statusFormatter.ts
  12. +2
    -2
      src/git/fsProvider.ts
  13. +9
    -11
      src/git/gitUri.ts
  14. +4
    -4
      src/git/models/repository.ts
  15. +2
    -2
      src/git/parsers/blameParser.ts
  16. +2
    -2
      src/git/parsers/logParser.ts
  17. +2
    -2
      src/quickpicks/commitQuickPickItems.ts
  18. +7
    -3
      src/system/path.ts
  19. +2
    -2
      src/views/nodes/branchTrackingStatusFilesNode.ts
  20. +4
    -4
      src/views/nodes/commitFileNode.ts
  21. +2
    -2
      src/views/nodes/commitNode.ts
  22. +3
    -3
      src/views/nodes/fileHistoryNode.ts
  23. +3
    -3
      src/views/nodes/fileRevisionAsCommitNode.ts
  24. +2
    -2
      src/views/nodes/mergeConflictFileNode.ts
  25. +2
    -2
      src/views/nodes/mergeStatusNode.ts
  26. +3
    -3
      src/views/nodes/rebaseStatusNode.ts
  27. +4
    -4
      src/views/nodes/resultsFileNode.ts
  28. +2
    -2
      src/views/nodes/resultsFilesNode.ts
  29. +2
    -2
      src/views/nodes/stashNode.ts
  30. +4
    -4
      src/views/nodes/statusFileNode.ts
  31. +2
    -2
      src/views/nodes/statusFilesNode.ts

+ 2
- 2
src/annotations/fileAnnotationController.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename } from 'path';
import {
ConfigurationChangeEvent,
DecorationRangeBehavior,
@ -534,7 +534,7 @@ export class FileAnnotationController implements Disposable {
}
progress.report({
message: `Computing ${annotationsLabel} for ${paths.basename(editor.document.fileName)}`,
message: `Computing ${annotationsLabel} for ${basename(editor.document.fileName)}`,
});
}

+ 2
- 2
src/commands/browseRepoAtRevision.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename } from 'path';
import { commands, TextEditor, Uri } from 'vscode';
import { BuiltInCommands } from '../constants';
import { Container } from '../container';
@ -73,7 +73,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
openWorkspace(uri, {
location: args.openInNewWindow ? OpenWorkspaceLocation.NewWindow : OpenWorkspaceLocation.AddToWorkspace,
name: `${paths.basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`,
name: `${basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`,
});
if (!args.openInNewWindow) {

+ 2
- 2
src/commands/common.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { extname } from 'path';
import {
commands,
Disposable,
@ -715,7 +715,7 @@ export async function openEditor(
uri = uri.documentUri();
}
if (uri.scheme === DocumentSchemes.GitLens && ImageMimetypes[paths.extname(uri.fsPath)]) {
if (uri.scheme === DocumentSchemes.GitLens && ImageMimetypes[extname(uri.fsPath)]) {
await commands.executeCommand(BuiltInCommands.Open, uri);
return undefined;

+ 3
- 3
src/commands/diffWith.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename } from 'path';
import { commands, Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode';
import { BuiltInCommands, GlyphChars } from '../constants';
import { Container } from '../container';
@ -147,10 +147,10 @@ export class DiffWithCommand extends Command {
}
if (args.lhs.title == null && (lhs != null || lhsSuffix.length !== 0)) {
args.lhs.title = `${paths.basename(args.lhs.uri.fsPath)}${lhsSuffix ? ` (${lhsSuffix})` : ''}`;
args.lhs.title = `${basename(args.lhs.uri.fsPath)}${lhsSuffix ? ` (${lhsSuffix})` : ''}`;
}
if (args.rhs.title == null) {
args.rhs.title = `${paths.basename(args.rhs.uri.fsPath)}${rhsSuffix ? ` (${rhsSuffix})` : ''}`;
args.rhs.title = `${basename(args.rhs.uri.fsPath)}${rhsSuffix ? ` (${rhsSuffix})` : ''}`;
}
const title =

+ 5
- 5
src/commands/diffWithRevisionFrom.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename, relative } from 'path';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
@ -42,7 +42,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
let ref;
let sha;
if (args?.stash) {
const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath));
const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath));
const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await StashPicker.show(
@ -83,11 +83,11 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
// Check to see if this file has been renamed
const files = await Container.instance.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] });
if (files != null) {
const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath));
const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath));
const rename = files.find(s => s.fileName === fileName);
if (rename?.originalFileName != null) {
renamedUri = GitUri.resolveToUri(rename.originalFileName, gitUri.repoPath);
renamedTitle = `${paths.basename(rename.originalFileName)} (${GitRevision.shorten(ref)})`;
renamedTitle = `${basename(rename.originalFileName)} (${GitRevision.shorten(ref)})`;
}
}
@ -96,7 +96,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
lhs: {
sha: sha,
uri: renamedUri ?? gitUri,
title: renamedTitle ?? `${paths.basename(gitUri.fsPath)} (${GitRevision.shorten(ref)})`,
title: renamedTitle ?? `${basename(gitUri.fsPath)} (${GitRevision.shorten(ref)})`,
},
rhs: {
sha: '',

+ 2
- 2
src/commands/openFileAtRevisionFrom.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { relative } from 'path';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
@ -44,7 +44,7 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand {
if (args.reference == null) {
if (args?.stash) {
const fileName = Strings.normalizePath(paths.relative(gitUri.repoPath, gitUri.fsPath));
const fileName = Strings.normalizePath(relative(gitUri.repoPath, gitUri.fsPath));
const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await StashPicker.show(

+ 6
- 10
src/env/node/git/git.ts 查看文件

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
'use strict';
import * as paths from 'path';
import { dirname, isAbsolute, join as joinPaths } from 'path';
import { Uri, window, workspace } from 'vscode';
import { hrtime } from '@env/hrtime';
import { GlyphChars } from '../../../constants';
@ -250,8 +250,8 @@ export namespace Git {
let supported = await Git.isAtLeastVersion('2.23');
if (supported) {
let ignoreRevsFile = params[index + 1];
if (!paths.isAbsolute(ignoreRevsFile)) {
ignoreRevsFile = paths.join(repoPath ?? emptyStr, ignoreRevsFile);
if (!isAbsolute(ignoreRevsFile)) {
ignoreRevsFile = joinPaths(repoPath ?? emptyStr, ignoreRevsFile);
}
const exists = ignoreRevsFileMap.get(ignoreRevsFile);
@ -852,7 +852,7 @@ export namespace Git {
if (format !== 'refs') {
if (startLine == null) {
// If this is the log of a folder, use `--name-status` to match non-file logs (for parsing)
if (format === 'simple' || isFolderGlob(file)) {
if (format === 'simple' || Paths.isFolderGlob(file)) {
params.push('--name-status');
} else {
params.push('--numstat', '--summary');
@ -1258,7 +1258,7 @@ export namespace Git {
let exists = inDotGit ? false : await fsExists(cwd);
if (!exists) {
do {
const parent = paths.dirname(cwd);
const parent = dirname(cwd);
if (parent === cwd || parent.length === 0) return undefined;
cwd = parent;
@ -1521,7 +1521,7 @@ export namespace Git {
options?: { numeric?: boolean; throw?: boolean; trim?: boolean },
): Promise<string | number | undefined> {
try {
const bytes = await workspace.fs.readFile(Uri.file(paths.join(...[repoPath, '.git', ...pathParts])));
const bytes = await workspace.fs.readFile(Uri.file(joinPaths(...[repoPath, '.git', ...pathParts])));
let contents = textDecoder.decode(bytes);
contents = options?.trim ?? true ? contents.trim() : contents;
@ -1538,7 +1538,3 @@ export namespace Git {
}
}
}
export function isFolderGlob(path: string) {
return paths.basename(path) === '*';
}

+ 17
- 17
src/env/node/git/localGitProvider.ts 查看文件

@ -1,7 +1,7 @@
'use strict';
import * as fs from 'fs';
import * as os from 'os';
import * as paths from 'path';
import { readdir, realpath, stat, Stats } from 'fs';
import { hostname, userInfo } from 'os';
import { dirname, relative, resolve as resolvePath } from 'path';
import {
Disposable,
env,
@ -100,7 +100,7 @@ import {
GitDocumentState,
TrackedDocument,
} from '../../../trackers/gitDocumentTracker';
import { Git, GitErrors, isFolderGlob, maxGitCliLength } from './git';
import { Git, GitErrors, maxGitCliLength } from './git';
import { findGitPath, GitLocation, InvalidGitConfigError, UnableToFindGitError } from './locator';
import { fsExists, RunError } from './shell';
@ -393,7 +393,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
for (let p of repoPaths) {
p = paths.dirname(p);
p = dirname(p);
// If we are the same as the root, skip it
if (Strings.normalizePath(p) === rootPath) continue;
@ -420,7 +420,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const cc = Logger.getCorrelationContext();
return new Promise<string[]>((resolve, reject) => {
fs.readdir(root, { withFileTypes: true }, async (err, files) => {
readdir(root, { withFileTypes: true }, async (err, files) => {
if (err != null) {
reject(err);
return;
@ -438,10 +438,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (!f.isDirectory()) continue;
if (f.name === '.git') {
repositories.push(paths.resolve(root, f.name));
repositories.push(resolvePath(root, f.name));
} else if (depth >= 0 && excludes[f.name] !== true) {
try {
await this.repositorySearchCore(paths.resolve(root, f.name), depth, excludes, repositories);
await this.repositorySearchCore(resolvePath(root, f.name), depth, excludes, repositories);
} catch (ex) {
Logger.error(ex, cc, 'FAILED');
}
@ -1299,7 +1299,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
} while (true);
} else {
user.name =
process.env.GIT_AUTHOR_NAME || process.env.GIT_COMMITTER_NAME || os.userInfo()?.username || undefined;
process.env.GIT_AUTHOR_NAME || process.env.GIT_COMMITTER_NAME || userInfo()?.username || undefined;
if (!user.name) {
// If we found no user data, mark it so we won't bother trying again
this._userMapCache.set(repoPath, null);
@ -1310,7 +1310,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
process.env.GIT_AUTHOR_EMAIL ||
process.env.GIT_COMMITTER_EMAIL ||
process.env.EMAIL ||
`${user.name}@${os.hostname()}`;
`${user.name}@${hostname()}`;
}
const author = `${user.name} <${user.email}>`;
@ -2130,7 +2130,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const log = GitLogParser.parse(
data,
// If this is the log of a folder, parse it as a normal log rather than a file log
isFolderGlob(file) ? GitCommitType.Log : GitCommitType.LogFile,
Paths.isFolderGlob(file) ? GitCommitType.Log : GitCommitType.LogFile,
root,
file,
ref,
@ -3056,10 +3056,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (isDirectory) {
path = filePath;
} else {
const stat = await new Promise<fs.Stats | undefined>(resolve =>
fs.stat(filePath, (err, stat) => resolve(err == null ? stat : undefined)),
const stats = await new Promise<Stats | undefined>(resolve =>
stat(filePath, (err, stats) => resolve(err == null ? stats : undefined)),
);
path = stat?.isDirectory() ? filePath : paths.dirname(filePath);
path = stats?.isDirectory() ? filePath : dirname(filePath);
}
repoPath = await Git.rev_parse__show_toplevel(path);
@ -3078,7 +3078,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
try {
const networkPath = await new Promise<string | undefined>(resolve =>
fs.realpath.native(`${letter}:\\`, { encoding: 'utf8' }, (err, resolvedPath) =>
realpath.native(`${letter}:\\`, { encoding: 'utf8' }, (err, resolvedPath) =>
resolve(err != null ? undefined : resolvedPath),
),
);
@ -3103,7 +3103,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
// If we are not on Windows (symlinks don't seem to have the same issue on Windows), check if we are a symlink and if so, use the symlink path (not its resolved path)
// This is because VS Code will provide document Uris using the symlinked path
repoPath = await new Promise<string | undefined>(resolve => {
fs.realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => {
realpath(path, { encoding: 'utf8' }, (err, resolvedPath) => {
if (err != null) {
Logger.debug(cc, `fs.realpath failed; repoPath=${repoPath}`);
resolve(repoPath);
@ -3616,7 +3616,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const fileName =
typeof fileNameOrUri === 'string'
? fileNameOrUri
: Strings.normalizePath(paths.relative(repoPath, fileNameOrUri.fsPath));
: Strings.normalizePath(relative(repoPath, fileNameOrUri.fsPath));
const blob = await Git.rev_parse__verify(repoPath, ref, fileName);
if (blob == null) return GitRevision.deletedOrMissing;

+ 2
- 2
src/env/node/git/locator.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { GlyphChars } from '../../../constants';
import { LogLevel } from '../../../logger';
import { Stopwatch } from '../../../system';
@ -93,7 +93,7 @@ async function findGitDarwin(): Promise {
function findSystemGitWin32(basePath: string | null | undefined): Promise<GitLocation> {
if (basePath == null || basePath.length === 0) return Promise.reject(new UnableToFindGitError());
return findSpecificGit(paths.join(basePath, 'Git', 'cmd', 'git.exe'));
return findSpecificGit(joinPaths(basePath, 'Git', 'cmd', 'git.exe'));
}
function findGitWin32(): Promise<GitLocation> {

+ 16
- 16
src/env/node/git/shell.ts 查看文件

@ -1,8 +1,8 @@
'use strict';
import { ExecException, execFile } from 'child_process';
import * as fs from 'fs';
import * as paths from 'path';
import * as iconv from 'iconv-lite';
import { exists, existsSync, Stats, statSync } from 'fs';
import { join as joinPaths } from 'path';
import { decode } from 'iconv-lite';
import { Logger } from '../../../logger';
export const isWindows = process.platform === 'win32';
@ -28,9 +28,9 @@ function runDownPath(exe: string): string {
// Files with any directory path don't get this applied
if (slashesRegex.test(exe)) return exe;
const target = paths.join('.', exe);
const target = joinPaths('.', exe);
try {
const stats = fs.statSync(target);
const stats = statSync(target);
if (stats?.isFile() && isExecutable(stats)) return target;
} catch {}
@ -39,9 +39,9 @@ function runDownPath(exe: string): string {
const haystack = path.split(isWindows ? ';' : ':');
let stats;
for (const p of haystack) {
const needle = paths.join(p, exe);
const needle = joinPaths(p, exe);
try {
stats = fs.statSync(needle);
stats = statSync(needle);
if (stats?.isFile() && isExecutable(stats)) return needle;
} catch {}
}
@ -50,7 +50,7 @@ function runDownPath(exe: string): string {
return exe;
}
function isExecutable(stats: fs.Stats) {
function isExecutable(stats: Stats) {
if (isWindows) return true;
const isGroup = stats.gid ? process.getgid != null && stats.gid === process.getgid() : true;
@ -72,7 +72,7 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args
// POSIX can just execute scripts directly, no need for silly goosery
if (!isWindows) return { cmd: runDownPath(exe), args: args };
if (!fs.existsSync(exe)) {
if (!existsSync(exe)) {
// NB: When you write something like `surf-client ... -- surf-build` on Windows,
// a shell would normally convert that to surf-build.cmd, but since it's passed
// in as an argument, it doesn't happen
@ -80,12 +80,12 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args
for (const ext of possibleExts) {
const possibleFullPath = runDownPath(`${exe}${ext}`);
if (fs.existsSync(possibleFullPath)) return findExecutable(possibleFullPath, args);
if (existsSync(possibleFullPath)) return findExecutable(possibleFullPath, args);
}
}
if (ps1Regex.test(exe)) {
const cmd = paths.join(
const cmd = joinPaths(
process.env.SYSTEMROOT ?? 'C:\\WINDOWS',
'System32',
'WindowsPowerShell',
@ -98,7 +98,7 @@ export function findExecutable(exe: string, args: string[]): { cmd: string; args
}
if (batOrCmdRegex.test(exe)) {
const cmd = paths.join(process.env.SYSTEMROOT ?? 'C:\\WINDOWS', 'System32', 'cmd.exe');
const cmd = joinPaths(process.env.SYSTEMROOT ?? 'C:\\WINDOWS', 'System32', 'cmd.exe');
const cmdArgs = ['/C', exe, ...args];
return { cmd: cmd, args: cmdArgs };
@ -191,10 +191,10 @@ export function run(
error,
encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer'
? stdout
: iconv.decode(Buffer.from(stdout, 'binary'), encoding),
: decode(Buffer.from(stdout, 'binary'), encoding),
encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer'
? stderr
: iconv.decode(Buffer.from(stderr, 'binary'), encoding),
: decode(Buffer.from(stderr, 'binary'), encoding),
),
);
@ -208,7 +208,7 @@ export function run(
resolve(
encoding === 'utf8' || encoding === 'binary' || encoding === 'buffer'
? (stdout as TOut)
: (iconv.decode(Buffer.from(stdout, 'binary'), encoding) as TOut),
: (decode(Buffer.from(stdout, 'binary'), encoding) as TOut),
);
});
@ -219,5 +219,5 @@ export function run(
}
export function fsExists(path: string) {
return new Promise<boolean>(resolve => fs.exists(path, exists => resolve(exists)));
return new Promise<boolean>(resolve => exists(path, exists => resolve(exists)));
}

+ 2
- 2
src/git/formatters/statusFormatter.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename } from 'path';
import { GlyphChars } from '../../constants';
import { Strings } from '../../system';
import { GitFile, GitFileWithCommit } from '../models/file';
@ -26,7 +26,7 @@ export class StatusFileFormatter extends Formatter
}
get file() {
const file = paths.basename(this._item.fileName);
const file = basename(this._item.fileName);
return this._padOrTruncate(file, this._options.tokenOptions.file);
}

+ 2
- 2
src/git/fsProvider.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { relative } from 'path';
import {
Disposable,
Event,
@ -70,7 +70,7 @@ export class GitFileSystemProvider implements FileSystemProvider, Disposable {
const items = [
...Iterables.map<GitTree, [string, FileType]>(tree, t => [
path != null && path.length !== 0 ? Strings.normalizePath(paths.relative(path, t.path)) : t.path,
path != null && path.length !== 0 ? Strings.normalizePath(relative(path, t.path)) : t.path,
typeToFileType(t.type),
]),
];

+ 9
- 11
src/git/gitUri.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename, dirname, isAbsolute, join as joinPaths, relative } from 'path';
import { Uri } from 'vscode';
import { UriComparer } from '../comparers';
import { DocumentSchemes } from '../constants';
@ -140,7 +140,7 @@ export class GitUri extends (Uri as any as UriEx) {
@memoize()
get fileName(): string {
return paths.basename(this.relativeFsPath);
return basename(this.relativeFsPath);
}
@memoize()
@ -155,9 +155,7 @@ export class GitUri extends (Uri as any as UriEx) {
@memoize()
private get relativeFsPath() {
return this.repoPath == null || this.repoPath.length === 0
? this.fsPath
: paths.relative(this.repoPath, this.fsPath);
return this.repoPath == null || this.repoPath.length === 0 ? this.fsPath : relative(this.repoPath, this.fsPath);
}
@memoize()
@ -325,7 +323,7 @@ export class GitUri extends (Uri as any as UriEx) {
}
static getDirectory(fileName: string, relativeTo?: string): string {
let directory: string | undefined = paths.dirname(fileName);
let directory: string | undefined = dirname(fileName);
directory = relativeTo != null ? GitUri.relativeTo(directory, relativeTo) : Strings.normalizePath(directory);
return directory == null || directory.length === 0 || directory === '.' ? emptyStr : directory;
}
@ -346,7 +344,7 @@ export class GitUri extends (Uri as any as UriEx) {
fileName = fileNameOrUri;
}
let file = paths.basename(fileName);
let file = basename(fileName);
if (truncateTo != null && file.length >= truncateTo) {
return Strings.truncateMiddle(file, truncateTo);
}
@ -379,7 +377,7 @@ export class GitUri extends (Uri as any as UriEx) {
fileName = fileNameOrUri;
}
let file = paths.basename(fileName);
let file = basename(fileName);
if (truncateTo != null && file.length >= truncateTo) {
return Strings.truncateMiddle(file, truncateTo);
}
@ -407,9 +405,9 @@ export class GitUri extends (Uri as any as UriEx) {
static relativeTo(fileNameOrUri: string | Uri, relativeTo: string | undefined): string {
const fileName = fileNameOrUri instanceof Uri ? fileNameOrUri.fsPath : fileNameOrUri;
const relativePath =
relativeTo == null || relativeTo.length === 0 || !paths.isAbsolute(fileName)
relativeTo == null || relativeTo.length === 0 || !isAbsolute(fileName)
? fileName
: paths.relative(relativeTo, fileName);
: relative(relativeTo, fileName);
return Strings.normalizePath(relativePath);
}
@ -436,7 +434,7 @@ export class GitUri extends (Uri as any as UriEx) {
if (normalizedFileName.startsWith(normalizedRepoPath)) return normalizedFileName;
return Strings.normalizePath(paths.join(normalizedRepoPath, normalizedFileName));
return Strings.normalizePath(joinPaths(normalizedRepoPath, normalizedFileName));
}
static resolveToUri(fileName: string, repoPath?: string) {

+ 4
- 4
src/git/models/repository.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename, join as joinPaths, relative } from 'path';
import {
commands,
ConfigurationChangeEvent,
@ -217,14 +217,14 @@ export class Repository implements Disposable {
suspended: boolean,
closed: boolean = false,
) {
const relativePath = paths.relative(folder.uri.fsPath, path);
const relativePath = relative(folder.uri.fsPath, path);
if (root) {
// Check if the repository is not contained by a workspace folder
const repoFolder = workspace.getWorkspaceFolder(GitUri.fromRepoPath(path));
if (repoFolder == null) {
// If it isn't within a workspace folder we can't get change events, see: https://github.com/Microsoft/vscode/issues/3025
this._supportsChangeEvents = false;
this.formattedName = this.name = paths.basename(path);
this.formattedName = this.name = basename(path);
} else {
this.formattedName = this.name = folder.name;
}
@ -582,7 +582,7 @@ export class Repository implements Disposable {
}
try {
const stat = await workspace.fs.stat(Uri.file(paths.join(this.path, '.git/FETCH_HEAD')));
const stat = await workspace.fs.stat(Uri.file(joinPaths(this.path, '.git/FETCH_HEAD')));
// If the file is empty, assume the fetch failed, and don't update the timestamp
if (stat.size > 0) {
this._lastFetched = stat.mtime;

+ 2
- 2
src/git/parsers/blameParser.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { relative } from 'path';
import { debug, Strings } from '../../system';
import { GitAuthor, GitBlame, GitBlameCommit, GitCommitLine, GitRevision, GitUser } from '../models';
@ -131,7 +131,7 @@ export class GitBlameParser {
emptyStr,
),
);
relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName));
relativeFileName = Strings.normalizePath(relative(repoPath, fileName));
} else {
relativeFileName = entry.fileName;
}

+ 2
- 2
src/git/parsers/logParser.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { relative } from 'path';
import { Range } from 'vscode';
import { Arrays, debug, Strings } from '../../system';
import {
@ -346,7 +346,7 @@ export class GitLogParser {
emptyStr,
),
);
relativeFileName = Strings.normalizePath(paths.relative(repoPath, fileName));
relativeFileName = Strings.normalizePath(relative(repoPath, fileName));
} else {
relativeFileName = entry.fileName!;
}

+ 2
- 2
src/quickpicks/commitQuickPickItems.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename } from 'path';
import { QuickPickItem, window } from 'vscode';
import { Commands, GitActions, OpenChangedFilesCommandArgs } from '../commands';
import { GlyphChars } from '../constants';
@ -37,7 +37,7 @@ export class CommitFilesQuickPickItem extends CommandQuickPickItem {
export class CommitFileQuickPickItem extends CommandQuickPickItem {
constructor(readonly commit: GitLogCommit, readonly file: GitFile, picked?: boolean) {
super({
label: `${Strings.pad(GitFile.getStatusCodicon(file.status), 0, 2)}${paths.basename(file.fileName)}`,
label: `${Strings.pad(GitFile.getStatusCodicon(file.status), 0, 2)}${basename(file.fileName)}`,
description: GitFile.getFormattedDirectory(file, true),
picked: picked,
});

+ 7
- 3
src/system/path.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename, dirname } from 'path';
import { Uri } from 'vscode';
import { Strings } from '../system';
import { normalizePath } from './string';
@ -74,6 +74,10 @@ export function isDescendent(uriOrPath: Uri | string, baseUriOrPath: Uri | strin
);
}
export function isFolderGlob(path: string) {
return basename(path) === '*';
}
export function splitPath(filePath: string, repoPath: string | undefined, extract: boolean = true): [string, string] {
if (repoPath) {
filePath = normalizePath(filePath);
@ -84,8 +88,8 @@ export function splitPath(filePath: string, repoPath: string | undefined, extrac
filePath = filePath.substring(normalizedRepoPath.length);
}
} else {
repoPath = normalizePath(extract ? paths.dirname(filePath) : repoPath!);
filePath = normalizePath(extract ? paths.basename(filePath) : filePath);
repoPath = normalizePath(extract ? dirname(filePath) : repoPath!);
filePath = normalizePath(extract ? basename(filePath) : filePath);
}
return [filePath, repoPath];

+ 2
- 2
src/views/nodes/branchTrackingStatusFilesNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri';
@ -84,7 +84,7 @@ export class BranchTrackingStatusFilesNode extends ViewNode {
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 4
- 4
src/views/nodes/commitFileNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { dirname, join as joinPaths } from 'path';
import { Command, Selection, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { StatusFileFormatter } from '../../git/formatters';
@ -69,8 +69,8 @@ export class CommitFileNode
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', icon)),
dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', icon)),
};
item.command = this.getCommand();
@ -100,7 +100,7 @@ export class CommitFileNode
private _folderName: string | undefined;
get folderName() {
if (this._folderName === undefined) {
this._folderName = paths.dirname(this.uri.relativePath);
this._folderName = dirname(this.uri.relativePath);
}
return this._folderName;
}

+ 2
- 2
src/views/nodes/commitNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { Command, MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { ViewFilesLayout } from '../../configuration';
@ -57,7 +57,7 @@ export class CommitNode extends ViewRefNode
const hierarchy = Arrays.makeHierarchical(
children as FileNode[],
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 3
- 3
src/views/nodes/fileHistoryNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { basename, join as joinPaths } from 'path';
import { Disposable, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { configuration } from '../../configuration';
import { GitUri } from '../../git/gitUri';
@ -151,7 +151,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl
get label() {
// Check if this is a base folder
if (this.folder && this.uri.fileName === '') {
return `${paths.basename(this.uri.fsPath)}${
return `${basename(this.uri.fsPath)}${
this.uri.sha
? ` ${this.uri.sha === GitRevision.deletedOrMissing ? this.uri.shortSha : `(${this.uri.shortSha})`}`
: ''
@ -242,7 +242,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl
@memoize()
private getPathOrGlob() {
return this.folder ? paths.join(this.uri.fsPath, '*') : this.uri.fsPath;
return this.folder ? joinPaths(this.uri.fsPath, '*') : this.uri.fsPath;
}
get hasMore() {

+ 3
- 3
src/views/nodes/fileRevisionAsCommitNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import {
Command,
MarkdownString,
@ -120,8 +120,8 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
if (item.iconPath == null) {
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', icon)),
dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', icon)),
};
}

+ 2
- 2
src/views/nodes/mergeConflictFileNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { dirname } from 'path';
import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { BuiltInCommands } from '../../constants';
import { StatusFileFormatter } from '../../git/formatters';
@ -81,7 +81,7 @@ export class MergeConflictFileNode extends ViewNode implements
private _folderName: string | undefined;
get folderName() {
if (this._folderName == null) {
this._folderName = paths.dirname(this.uri.relativePath);
this._folderName = dirname(this.uri.relativePath);
}
return this._folderName;
}

+ 2
- 2
src/views/nodes/mergeStatusNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri';
@ -48,7 +48,7 @@ export class MergeStatusNode extends ViewNode {
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 3
- 3
src/views/nodes/rebaseStatusNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import {
Command,
commands,
@ -65,7 +65,7 @@ export class RebaseStatusNode extends ViewNode {
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);
@ -182,7 +182,7 @@ export class RebaseCommitNode extends ViewRefNode
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 4
- 4
src/views/nodes/resultsFileNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { dirname, join as joinPaths } from 'path';
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithCommandArgs } from '../../commands';
import { StatusFileFormatter } from '../../git/formatters';
@ -49,8 +49,8 @@ export class ResultsFileNode extends ViewRefFileNode implements FileNode {
const statusIcon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', statusIcon)),
light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', statusIcon)),
dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', statusIcon)),
light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', statusIcon)),
};
item.command = this.getCommand();
@ -74,7 +74,7 @@ export class ResultsFileNode extends ViewRefFileNode implements FileNode {
private _folderName: string | undefined;
get folderName() {
if (this._folderName === undefined) {
this._folderName = paths.dirname(this.uri.relativePath);
this._folderName = dirname(this.uri.relativePath);
}
return this._folderName;
}

+ 2
- 2
src/views/nodes/resultsFilesNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri';
@ -78,7 +78,7 @@ export class ResultsFilesNode extends ViewNode {
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 2
- 2
src/views/nodes/stashNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../config';
import { CommitFormatter } from '../../git/formatters';
@ -43,7 +43,7 @@ export class StashNode extends ViewRefNode
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

+ 4
- 4
src/views/nodes/statusFileNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { dirname, join as joinPaths } from 'path';
import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithCommandArgs, DiffWithPreviousCommandArgs } from '../../commands';
import { StatusFileFormatter } from '../../git/formatters/statusFormatter';
@ -111,8 +111,8 @@ export class StatusFileNode extends ViewNode implements FileNo
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: this.view.container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(paths.join('images', 'light', icon)),
dark: this.view.container.context.asAbsolutePath(joinPaths('images', 'dark', icon)),
light: this.view.container.context.asAbsolutePath(joinPaths('images', 'light', icon)),
};
}
@ -151,7 +151,7 @@ export class StatusFileNode extends ViewNode implements FileNo
private _folderName: string | undefined;
get folderName() {
if (this._folderName == null) {
this._folderName = paths.dirname(this.uri.relativePath);
this._folderName = dirname(this.uri.relativePath);
}
return this._folderName;
}

+ 2
- 2
src/views/nodes/statusFilesNode.ts 查看文件

@ -1,5 +1,5 @@
'use strict';
import * as paths from 'path';
import { join as joinPaths } from 'path';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri';
@ -111,7 +111,7 @@ export class StatusFilesNode extends ViewNode {
const hierarchy = Arrays.makeHierarchical(
children,
n => n.uri.relativePath.split('/'),
(...parts: string[]) => Strings.normalizePath(paths.join(...parts)),
(...parts: string[]) => Strings.normalizePath(joinPaths(...parts)),
this.view.config.files.compact,
);

正在加载...
取消
保存