Skip to content

Commit 746f6ce

Browse files
authored
Merge pull request #46 from JohnstonCode/revert-43-support_svn_location
Revert "Added support to configure the path to the svn executable"
2 parents be1ddfb + 9eb66fd commit 746f6ce

File tree

3 files changed

+9
-137
lines changed

3 files changed

+9
-137
lines changed

package.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,6 @@
123123
"type": "boolean",
124124
"description": "Whether svn is enabled",
125125
"default": true
126-
},
127-
"svn.path": {
128-
"type": [
129-
"string",
130-
"null"
131-
],
132-
"description": "Path to the svn executable",
133-
"default": null,
134-
"isExecutable": true
135126
}
136127
}
137128
}

src/extension.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
import { ExtensionContext, Disposable, workspace, window } from "vscode";
2-
import { Svn, findSvn } from "./svn";
1+
import { ExtensionContext, Disposable, window } from "vscode";
2+
import { Svn } from "./svn";
33
import { SvnContentProvider } from "./svnContentProvider";
44
import { SvnCommands } from "./commands";
55
import { Model } from "./model";
66
import { toDisposable } from "./util";
77

8-
async function init(context: ExtensionContext, disposables: Disposable[]): Promise<void> {
8+
function activate(context: ExtensionContext) {
9+
const disposables: Disposable[] = [];
10+
911
const outputChannel = window.createOutputChannel("Svn");
1012
disposables.push(outputChannel);
1113

12-
const config = workspace.getConfiguration('svn');
13-
const enabled = config.get<boolean>('enabled') === true;
14-
const pathHint = workspace.getConfiguration('svn').get<string>('path');
15-
const info = await findSvn(pathHint);
16-
17-
const svn = new Svn({svnPath: info.path, version: info.version});
14+
const svn = new Svn();
1815
const model = new Model(svn);
1916
const contentProvider = new SvnContentProvider(model);
2017
const commands = new SvnCommands(model);
2118
disposables.push(model);
2219

23-
outputChannel.appendLine("Using svn " + info.version + " from " + info.path);
20+
outputChannel.appendLine("svn-scm is now active!");
2421

2522
context.subscriptions.push(
2623
new Disposable(() => Disposable.from(...disposables).dispose())
@@ -32,16 +29,6 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi
3229
toDisposable(() => svn.onOutput.removeListener("log", onOutput))
3330
);
3431
}
35-
36-
function activate(context: ExtensionContext): any {
37-
const disposables: Disposable[] = [];
38-
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
39-
40-
init(context, disposables)
41-
.catch(err => console.error(err));
42-
}
43-
44-
4532
exports.activate = activate;
4633

4734
// this method is called when your extension is deactivated

src/svn.ts

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,21 @@
1-
import { EventEmitter } from "events";
21
import { window } from "vscode";
32
import * as cp from "child_process";
43
import * as iconv from "iconv-lite";
54
import * as jschardet from "jschardet";
6-
import * as path from 'path';
5+
import { EventEmitter } from "events";
76

87
interface CpOptions {
98
cwd?: string;
109
encoding?: string;
1110
log?: boolean;
1211
}
1312

14-
export interface ISvn {
15-
path: string;
16-
version: string;
17-
}
18-
19-
function parseVersion(raw: string): string {
20-
const match = raw.match(/(\d+\.\d+\.\d+ \(r\d+\))/);
21-
22-
if(match && match[0]) {
23-
return match[0];
24-
}
25-
return raw.split(/[\r\n]+/)[0];
26-
}
27-
28-
function findSpecificSvn(path: string): Promise<ISvn> {
29-
return new Promise<ISvn>((c, e) => {
30-
const buffers: Buffer[] = [];
31-
const child = cp.spawn(path, ['--version']);
32-
child.stdout.on('data', (b: Buffer) => buffers.push(b));
33-
// child.on('error', cpErrorHandler(e));
34-
child.on('exit', code => code ? e(new Error('Not found')) : c({ path, version: parseVersion(Buffer.concat(buffers).toString('utf8').trim()) }));
35-
});
36-
}
37-
38-
function findSvnDarwin(): Promise<ISvn> {
39-
return new Promise<ISvn>((c, e) => {
40-
cp.exec('which svn', (err, svnPathBuffer) => {
41-
if (err) {
42-
return e('svn not found');
43-
}
44-
45-
const path = svnPathBuffer.toString().replace(/^\s+|\s+$/g, '');
46-
47-
function getVersion(path: string) {
48-
// make sure svn executes
49-
cp.exec('svn --version', (err, stdout) => {
50-
if (err) {
51-
return e('svn not found');
52-
}
53-
54-
return c({ path, version: parseVersion(stdout.trim()) });
55-
});
56-
}
57-
58-
if (path !== '/usr/bin/svn') {
59-
return getVersion(path);
60-
}
61-
62-
// must check if XCode is installed
63-
cp.exec('xcode-select -p', (err: any) => {
64-
if (err && err.code === 2) {
65-
// svn is not installed, and launching /usr/bin/svn
66-
// will prompt the user to install it
67-
68-
return e('svn not found');
69-
}
70-
71-
getVersion(path);
72-
});
73-
});
74-
});
75-
}
76-
77-
function findSystemSvnWin32(base: string): Promise<ISvn> {
78-
if (!base) {
79-
return Promise.reject<ISvn>('Not found');
80-
}
81-
82-
return findSpecificSvn(path.join(base, 'TortoiseSVN', 'bin', 'svn.exe'));
83-
}
84-
85-
function findSvnWin32(): Promise<ISvn> {
86-
return findSystemSvnWin32(process.env['ProgramW6432'])
87-
.then(void 0, () => findSystemSvnWin32(process.env['ProgramFiles(x86)']))
88-
.then(void 0, () => findSystemSvnWin32(process.env['ProgramFiles']))
89-
.then(void 0, () => findSpecificSvn('svn'));
90-
}
91-
92-
export function findSvn(hint: string | undefined): Promise<ISvn> {
93-
var first = hint ? findSpecificSvn(hint) : Promise.reject<ISvn>(null);
94-
95-
return first
96-
.then(void 0, () => {
97-
switch (process.platform) {
98-
case 'darwin': return findSvnDarwin();
99-
case 'win32': return findSvnWin32();
100-
default: return findSpecificSvn('svn');
101-
}
102-
})
103-
.then(null, () => Promise.reject(new Error('Svn installation not found.')));
104-
}
105-
106-
export interface ISvnOptions {
107-
svnPath: string;
108-
version: string;
109-
}
110-
11113
export class Svn {
112-
private svnPath: string;
113-
private version: string;
114-
11514
private _onOutput = new EventEmitter();
11615
get onOutput(): EventEmitter {
11716
return this._onOutput;
11817
}
11918

120-
constructor(options: ISvnOptions) {
121-
this.svnPath = options.svnPath;
122-
this.version = options.version;
123-
}
124-
12519
private log(output: string): void {
12620
this._onOutput.emit("log", output);
12721
}
@@ -135,7 +29,7 @@ export class Svn {
13529
this.log(`svn ${args.join(" ")}\n`);
13630
}
13731

138-
let process = cp.spawn(this.svnPath, args, options);
32+
let process = cp.spawn("svn", args, options);
13933

14034
let [exitCode, stdout, stderr] = await Promise.all<any>([
14135
new Promise<number>((resolve, reject) => {

0 commit comments

Comments
 (0)