Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git - adopt log output channel api #163695

Merged
merged 5 commits into from Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 2 additions & 34 deletions extensions/git/package.json
Expand Up @@ -19,7 +19,8 @@
"scmValidation",
"tabInputTextMerge",
"timeline",
"contribMergeEditorMenus"
"contribMergeEditorMenus",
"extensionLog"
],
"categories": [
"Other"
Expand Down Expand Up @@ -49,11 +50,6 @@
},
"contributes": {
"commands": [
{
"command": "git.setLogLevel",
"title": "%command.setLogLevel%",
"category": "Git"
},
{
"command": "git.clone",
"title": "%command.clone%",
Expand Down Expand Up @@ -651,10 +647,6 @@
],
"menus": {
"commandPalette": [
{
"command": "git.setLogLevel",
"when": "config.git.enabled && !git.missing"
},
{
"command": "git.clone",
"when": "config.git.enabled && !git.missing"
Expand Down Expand Up @@ -2546,30 +2538,6 @@
"default": [],
"markdownDescription": "%config.commandsToLog%"
},
"git.logLevel": {
"type": "string",
"default": "Info",
"enum": [
"Trace",
"Debug",
"Info",
"Warning",
"Error",
"Critical",
"Off"
],
"enumDescriptions": [
"%config.logLevel.trace%",
"%config.logLevel.debug%",
"%config.logLevel.info%",
"%config.logLevel.warn%",
"%config.logLevel.error%",
"%config.logLevel.critical%",
"%config.logLevel.off%"
],
"markdownDescription": "%config.logLevel%",
"scope": "window"
},
"git.mergeEditor": {
"type": "boolean",
"default": false,
Expand Down
16 changes: 0 additions & 16 deletions extensions/git/package.nls.json
@@ -1,7 +1,6 @@
{
"displayName": "Git",
"description": "Git SCM Integration",
"command.setLogLevel": "Set Log Level...",
"command.clone": "Clone",
"command.cloneRecursive": "Clone (Recursive)",
"command.init": "Initialize Repository",
Expand Down Expand Up @@ -236,21 +235,6 @@
"config.repositoryScanIgnoredFolders": "List of folders that are ignored while scanning for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`.",
"config.repositoryScanMaxDepth": "Controls the depth used when scanning workspace folders for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`. Can be set to `-1` for no limit.",
"config.useIntegratedAskPass": "Controls whether GIT_ASKPASS should be overwritten to use the integrated version.",
"config.logLevel": {
"message": "Specifies how much information (if any) to log to the [git output](command:git.showOutput).",
"comment": [
"{Locked='](command:git.showOutput'}",
"Do not translate the 'command:*' part inside of the '(..)'. It is an internal command syntax for VS Code",
"Please make sure there is no space between the right bracket and left parenthesis: ]( this is an internal syntax for links"
]
},
"config.logLevel.trace": "Log all information",
"config.logLevel.debug": "Log only debug, information, warning, error, and critical information",
"config.logLevel.info": "Log only information, warning, error, and critical information",
"config.logLevel.warn": "Log only warning, error, and critical information",
"config.logLevel.error": "Log only error, and critical information",
"config.logLevel.critical": "Log only critical information",
"config.logLevel.off": "Log nothing",
"config.mergeEditor": "Open the merge editor for files that are currently under conflict.",
"submenu.explorer": "Git",
"submenu.commit": "Commit",
Expand Down
63 changes: 12 additions & 51 deletions extensions/git/src/commands.ts
Expand Up @@ -5,7 +5,7 @@

import * as os from 'os';
import * as path from 'path';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind } from 'vscode';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind, LogOutputChannel } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import * as nls from 'vscode-nls';
import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator';
Expand All @@ -16,7 +16,6 @@ import { Repository, Resource, ResourceGroupType } from './repository';
import { applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging';
import { fromGitUri, toGitUri, isGitUri, toMergeUris } from './uri';
import { grep, isDescendant, pathEquals, relativePath } from './util';
import { LogLevel, OutputChannelLogger } from './log';
import { GitTimelineItem } from './timelineProvider';
import { ApiRepository } from './api/api1';
import { pickRemoteSource } from './remoteSource';
Expand Down Expand Up @@ -350,7 +349,7 @@ export class CommandCenter {
constructor(
private git: Git,
private model: Model,
private outputChannelLogger: OutputChannelLogger,
private logger: LogOutputChannel,
private telemetryReporter: TelemetryReporter
) {
this.disposables = Commands.map(({ commandId, key, method, options }) => {
Expand All @@ -366,47 +365,9 @@ export class CommandCenter {
this.disposables.push(workspace.registerTextDocumentContentProvider('git-output', this.commandErrors));
}

@command('git.setLogLevel')
async setLogLevel(): Promise<void> {
const createItem = (logLevel: LogLevel) => {
let description: string | undefined;
const defaultDescription = localize('default', "Default");
const currentDescription = localize('current', "Current");

if (logLevel === this.outputChannelLogger.defaultLogLevel && logLevel === this.outputChannelLogger.currentLogLevel) {
description = `${defaultDescription} & ${currentDescription} `;
} else if (logLevel === this.outputChannelLogger.defaultLogLevel) {
description = defaultDescription;
} else if (logLevel === this.outputChannelLogger.currentLogLevel) {
description = currentDescription;
}

return {
label: LogLevel[logLevel],
logLevel,
description
};
};

const items = [
createItem(LogLevel.Trace),
createItem(LogLevel.Debug),
createItem(LogLevel.Info),
createItem(LogLevel.Warning),
createItem(LogLevel.Error),
createItem(LogLevel.Critical),
createItem(LogLevel.Off)
];

const choice = await window.showQuickPick(items, {
placeHolder: localize('select log level', "Select log level")
});

if (!choice) {
return;
}

this.outputChannelLogger.currentLogLevel = choice.logLevel;
@command('git.showOutput')
showOutput(): void {
this.logger.show();
}

@command('git.refresh', { repository: true })
Expand Down Expand Up @@ -947,14 +908,14 @@ export class CommandCenter {

@command('git.stage')
async stage(...resourceStates: SourceControlResourceState[]): Promise<void> {
this.outputChannelLogger.logDebug(`git.stage ${resourceStates.length} `);
this.logger.debug(`git.stage ${resourceStates.length} `);

resourceStates = resourceStates.filter(s => !!s);

if (resourceStates.length === 0 || (resourceStates[0] && !(resourceStates[0].resourceUri instanceof Uri))) {
const resource = this.getSCMResource();

this.outputChannelLogger.logDebug(`git.stage.getSCMResource ${resource ? resource.resourceUri.toString() : null} `);
this.logger.debug(`git.stage.getSCMResource ${resource ? resource.resourceUri.toString() : null} `);

if (!resource) {
return;
Expand Down Expand Up @@ -997,7 +958,7 @@ export class CommandCenter {
const untracked = selection.filter(s => s.resourceGroupType === ResourceGroupType.Untracked);
const scmResources = [...workingTree, ...untracked, ...resolved, ...unresolved];

this.outputChannelLogger.logDebug(`git.stage.scmResources ${scmResources.length} `);
this.logger.debug(`git.stage.scmResources ${scmResources.length} `);
if (!scmResources.length) {
return;
}
Expand Down Expand Up @@ -3231,8 +3192,8 @@ export class CommandCenter {

const choices = new Map<string, () => void>();
const openOutputChannelChoice = localize('open git log', "Open Git Log");
const outputChannelLogger = this.outputChannelLogger;
choices.set(openOutputChannelChoice, () => outputChannelLogger.showOutputChannel());
const outputChannelLogger = this.logger;
choices.set(openOutputChannelChoice, () => outputChannelLogger.show());

const showCommandOutputChoice = localize('show command output', "Show Command Output");
if (err.stderr) {
Expand Down Expand Up @@ -3349,10 +3310,10 @@ export class CommandCenter {
private getSCMResource(uri?: Uri): Resource | undefined {
uri = uri ? uri : (window.activeTextEditor && window.activeTextEditor.document.uri);

this.outputChannelLogger.logDebug(`git.getSCMResource.uri ${uri && uri.toString()}`);
this.logger.debug(`git.getSCMResource.uri ${uri && uri.toString()}`);

for (const r of this.model.repositories.map(r => r.root)) {
this.outputChannelLogger.logDebug(`repo root ${r}`);
this.logger.debug(`repo root ${r}`);
}

if (!uri) {
Expand Down
11 changes: 5 additions & 6 deletions extensions/git/src/git.ts
Expand Up @@ -13,12 +13,11 @@ import { EventEmitter } from 'events';
import * as iconv from '@vscode/iconv-lite-umd';
import * as filetype from 'file-type';
import { assign, groupBy, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent, splitInChunks, Limiter, Versions, isWindows } from './util';
import { CancellationToken, ConfigurationChangeEvent, Progress, Uri, workspace } from 'vscode';
import { CancellationToken, ConfigurationChangeEvent, LogOutputChannel, Progress, Uri, workspace } from 'vscode';
import { detectEncoding } from './encoding';
import { Ref, RefType, Branch, Remote, ForcePushMode, GitErrorCodes, LogOptions, Change, Status, CommitOptions, BranchQuery } from './api/git';
import * as byline from 'byline';
import { StringDecoder } from 'string_decoder';
import { OutputChannelLogger } from './log';
import TelemetryReporter from '@vscode/extension-telemetry';

// https://github.com/microsoft/vscode/issues/65693
Expand Down Expand Up @@ -401,8 +400,8 @@ export class Git {
return Versions.compare(Versions.fromString(this.version), Versions.fromString(version));
}

open(repository: string, dotGit: { path: string; commonPath?: string }, outputChannelLogger: OutputChannelLogger): Repository {
return new Repository(this, repository, dotGit, outputChannelLogger);
open(repository: string, dotGit: { path: string; commonPath?: string }, logger: LogOutputChannel): Repository {
return new Repository(this, repository, dotGit, logger);
}

async init(repository: string): Promise<void> {
Expand Down Expand Up @@ -915,7 +914,7 @@ export class Repository {
private _git: Git,
private repositoryRoot: string,
readonly dotGit: { path: string; commonPath?: string },
private outputChannelLogger: OutputChannelLogger
private logger: LogOutputChannel
) { }

get git(): Git {
Expand Down Expand Up @@ -2003,7 +2002,7 @@ export class Repository {
return result;
}
catch (err) {
this.outputChannelLogger.logWarning(err.message);
this.logger.warn(err.message);
}

try {
Expand Down
115 changes: 0 additions & 115 deletions extensions/git/src/log.ts

This file was deleted.