Skip to content

Commit c31eb21

Browse files
authored
fix: history view now uses temp svn fs (#814)
1 parent ad0b561 commit c31eb21

File tree

6 files changed

+76
-102
lines changed

6 files changed

+76
-102
lines changed

src/historyView/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { exists, lstat } from "../fs";
1515
import { configuration } from "../helpers/configuration";
1616
import { IRemoteRepository } from "../remoteRepository";
1717
import { SvnRI } from "../svnRI";
18-
import { createTempSvnRevisionFile } from "../tempFiles";
18+
import { tempSvnFs } from "../temp_svn_fs";
1919

2020
dayjs.extend(relativeTime);
2121

@@ -271,7 +271,7 @@ async function downloadFile(
271271
window.showErrorMessage("Failed to open path");
272272
throw e;
273273
}
274-
return createTempSvnRevisionFile(arg, revision, out);
274+
return tempSvnFs.createTempSvnRevisionFile(arg, revision, out);
275275
}
276276

277277
export async function openDiff(
@@ -302,7 +302,7 @@ export async function openFileRemote(
302302
window.showErrorMessage("Failed to open path");
303303
return;
304304
}
305-
const localUri = await createTempSvnRevisionFile(arg, against, out);
305+
const localUri = await tempSvnFs.createTempSvnRevisionFile(arg, against, out);
306306
const opts: TextDocumentShowOptions = {
307307
preview: true
308308
};

src/historyView/itemLogProvider.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from "vscode";
1414
import { ISvnLogEntry } from "../common/types";
1515
import { SourceControlManager } from "../source_control_manager";
16-
import { tempdir } from "../tempFiles";
1716
import { dispose, unwrap } from "../util";
1817
import {
1918
copyCommitToClipboard,
@@ -131,9 +130,6 @@ export class ItemLogProvider
131130
if (te) {
132131
const uri = te.document.uri;
133132
if (uri.scheme === "file") {
134-
if (uri.path.startsWith(tempdir)) {
135-
return; // do not refresh if diff was called
136-
}
137133
const repo = this.sourceControlManager.getRepository(uri);
138134
if (repo !== null) {
139135
try {

src/tempFiles.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/temp_svn_fs.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
workspace
1313
} from "vscode";
1414
import * as path from "path";
15+
import * as crypto from "crypto";
16+
import { configuration } from "./helpers/configuration";
17+
import { iconv } from "./vscodeModules";
1518

1619
export class File implements FileStat {
1720
type: FileType;
@@ -183,6 +186,34 @@ class TempSvnFs implements FileSystemProvider, Disposable {
183186
);
184187
}
185188

189+
async createTempSvnRevisionFile(
190+
svnUri: Uri,
191+
revision: string,
192+
content: string
193+
) {
194+
const fname = `r${revision}_${path.basename(svnUri.fsPath)}`;
195+
const hash = crypto.createHash("md5");
196+
const filePathHash = hash.update(svnUri.path).digest("hex");
197+
const encoding = configuration.get<string>("default.encoding");
198+
199+
if (encoding) {
200+
content = iconv.encode(content, encoding).toString();
201+
}
202+
203+
if (!this._root.entries.has(filePathHash)) {
204+
this.createDirectory(Uri.parse(`tempsvnfs:/${filePathHash}`));
205+
}
206+
207+
const uri = Uri.parse(`tempsvnfs:/${filePathHash}/${fname}`, true);
208+
209+
this.writeFile(uri, Buffer.from(content), {
210+
create: true,
211+
overwrite: true
212+
});
213+
214+
return uri;
215+
}
216+
186217
dispose(): void {
187218
this._disposables.forEach(disposable => disposable.dispose());
188219
this._disposables = [];

src/test/tempFiles.test.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/test/temp_svn_fs.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as assert from "assert";
2+
import { Uri } from "vscode";
3+
import { tempSvnFs } from "../temp_svn_fs";
4+
import { join } from "path";
5+
6+
suite("Test temp svn fs", () => {
7+
test("Temp files matches expected", async () => {
8+
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");
9+
10+
const revisionUri = await tempSvnFs.createTempSvnRevisionFile(
11+
svnUri,
12+
"30",
13+
"test content"
14+
);
15+
16+
assert.equal(revisionUri.fsPath, join('/', '1181ae15a77d83ac0b077051dfed21ed', 'r30_test.js'));
17+
});
18+
19+
test("Temp file is created", async () => {
20+
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");
21+
22+
const uri = await tempSvnFs.createTempSvnRevisionFile(
23+
svnUri,
24+
"30",
25+
"test content"
26+
);
27+
28+
assert.ok(tempSvnFs.stat(uri));
29+
});
30+
31+
test("Temp contents are correct", async () => {
32+
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");
33+
34+
const revisionUri = await tempSvnFs.createTempSvnRevisionFile(
35+
svnUri,
36+
"30",
37+
"test content"
38+
);
39+
40+
assert.equal(tempSvnFs.readFile(revisionUri), "test content");
41+
});
42+
});

0 commit comments

Comments
 (0)