Skip to content

Commit 3e1d02a

Browse files
TheoHegemannedgardmessias
authored andcommitted
Added configuration parameter svn.default.encoding (#227)
* Added configuration parameter svn.default.encoding Added configuration parameter svn.default.encoding: Encoding of svn output if the output is not utf-8. When this parameter is null, the encoding is automatically detected. Example: 'svn.default.encoding: windows-1252'.
1 parent 7be495f commit 3e1d02a

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dependencies": {
4242
"@types/xml2js": "^0.4.2",
4343
"iconv-lite": "^0.4.19",
44+
"is-utf8": "^0.2.1",
4445
"jschardet": "^1.6.0",
4546
"micromatch": "^3.1.5",
4647
"xml2js": "^0.4.19"
@@ -601,6 +602,14 @@
601602
"type": "boolean",
602603
"description": "Set to ignore externals definitions on update (add --ignore-externals)",
603604
"default": true
605+
},
606+
"svn.default.encoding": {
607+
"type": [
608+
"string",
609+
"null"
610+
],
611+
"description": "Encoding of svn output if the output is not utf-8. When this parameter is null, the encoding is automatically detected. Example: 'windows-1252'.",
612+
"default": null
604613
}
605614
}
606615
}

src/svn.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Repository } from "./svnRepository";
88
import { parseInfoXml } from "./infoParser";
99
import { SpawnOptions } from "child_process";
1010
import { IDisposable, toDisposable, dispose } from "./util";
11+
import { configuration } from "./helpers/configuration";
12+
13+
const isUtf8 = require("is-utf8");
1114

1215
// List: https://github.com/apache/subversion/blob/1.6.x/subversion/svn/schema/status.rnc#L33
1316
export enum Status {
@@ -241,15 +244,27 @@ export class Svn {
241244

242245
// SVN with '--xml' always return 'UTF-8', and jschardet detects this encoding: 'TIS-620'
243246
if (!args.includes("--xml")) {
244-
jschardet.MacCyrillicModel.mTypicalPositiveRatio += 0.001;
245247

246-
const encodingGuess = jschardet.detect(stdout);
248+
const default_encoding = configuration.get<string>("default.encoding");
249+
if (default_encoding) {
250+
if (!iconv.encodingExists(default_encoding)) {
251+
this.logOutput("svn.default.encoding: Invalid Parameter: '" + default_encoding + "'.\n")
252+
} else if (!isUtf8(stdout)) {
253+
encoding = default_encoding;
254+
}
255+
256+
} else {
257+
258+
jschardet.MacCyrillicModel.mTypicalPositiveRatio += 0.001;
259+
260+
const encodingGuess = jschardet.detect(stdout);
247261

248-
if (
249-
encodingGuess.confidence > 0.8 &&
250-
iconv.encodingExists(encodingGuess.encoding)
251-
) {
252-
encoding = encodingGuess.encoding;
262+
if (
263+
encodingGuess.confidence > 0.8 &&
264+
iconv.encodingExists(encodingGuess.encoding)
265+
) {
266+
encoding = encodingGuess.encoding;
267+
}
253268
}
254269
}
255270

0 commit comments

Comments
 (0)