mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Added support for encodings for Git.
Fixes #21146 **Bug** Git always uses utf8 encoding for retrieving file contents. **Fix** Pass the 'files.encoding' configuration property to the git-extension and use this encoding to decode git output.
This commit is contained in:
@@ -9,6 +9,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as cp from 'child_process';
|
||||
import iconv = require('iconv-lite');
|
||||
import { assign, uniqBy, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp } from './util';
|
||||
import { EventEmitter, Event } from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
@@ -159,7 +160,7 @@ export interface IExecutionResult {
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
export async function exec(child: cp.ChildProcess): Promise<IExecutionResult> {
|
||||
export async function exec(child: cp.ChildProcess, encoding: string = 'utf8'): Promise<IExecutionResult> {
|
||||
const disposables: IDisposable[] = [];
|
||||
|
||||
const once = (ee: NodeJS.EventEmitter, name: string, fn: Function) => {
|
||||
@@ -178,14 +179,14 @@ export async function exec(child: cp.ChildProcess): Promise<IExecutionResult> {
|
||||
once(child, 'exit', c);
|
||||
}),
|
||||
new Promise<string>(c => {
|
||||
const buffers: string[] = [];
|
||||
const buffers: Buffer[] = [];
|
||||
on(child.stdout, 'data', b => buffers.push(b));
|
||||
once(child.stdout, 'close', () => c(buffers.join('')));
|
||||
once(child.stdout, 'close', () => c(decode(Buffer.concat(buffers), encoding)));
|
||||
}),
|
||||
new Promise<string>(c => {
|
||||
const buffers: string[] = [];
|
||||
const buffers: Buffer[] = [];
|
||||
on(child.stderr, 'data', b => buffers.push(b));
|
||||
once(child.stderr, 'close', () => c(buffers.join('')));
|
||||
once(child.stderr, 'close', () => c(decode(Buffer.concat(buffers), encoding)));
|
||||
})
|
||||
]);
|
||||
|
||||
@@ -194,6 +195,10 @@ export async function exec(child: cp.ChildProcess): Promise<IExecutionResult> {
|
||||
return { exitCode, stdout, stderr };
|
||||
}
|
||||
|
||||
function decode(buffer: NodeBuffer, encoding: string): string {
|
||||
return iconv.decode(buffer, encoding);
|
||||
}
|
||||
|
||||
export interface IGitErrorData {
|
||||
error?: Error;
|
||||
message?: string;
|
||||
@@ -329,7 +334,7 @@ export class Git {
|
||||
child.stdin.end(options.input, 'utf8');
|
||||
}
|
||||
|
||||
const result = await exec(child);
|
||||
const result = await exec(child, options.encoding);
|
||||
|
||||
if (result.exitCode) {
|
||||
let gitErrorCode: string | undefined = void 0;
|
||||
|
||||
Reference in New Issue
Block a user