Skip to content

Commit

Permalink
fix: history view now uses temp svn fs (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnstonCode authored Feb 17, 2020
1 parent ad0b561 commit c31eb21
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 102 deletions.
6 changes: 3 additions & 3 deletions src/historyView/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { exists, lstat } from "../fs";
import { configuration } from "../helpers/configuration";
import { IRemoteRepository } from "../remoteRepository";
import { SvnRI } from "../svnRI";
import { createTempSvnRevisionFile } from "../tempFiles";
import { tempSvnFs } from "../temp_svn_fs";

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -271,7 +271,7 @@ async function downloadFile(
window.showErrorMessage("Failed to open path");
throw e;
}
return createTempSvnRevisionFile(arg, revision, out);
return tempSvnFs.createTempSvnRevisionFile(arg, revision, out);
}

export async function openDiff(
Expand Down Expand Up @@ -302,7 +302,7 @@ export async function openFileRemote(
window.showErrorMessage("Failed to open path");
return;
}
const localUri = await createTempSvnRevisionFile(arg, against, out);
const localUri = await tempSvnFs.createTempSvnRevisionFile(arg, against, out);
const opts: TextDocumentShowOptions = {
preview: true
};
Expand Down
4 changes: 0 additions & 4 deletions src/historyView/itemLogProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from "vscode";
import { ISvnLogEntry } from "../common/types";
import { SourceControlManager } from "../source_control_manager";
import { tempdir } from "../tempFiles";
import { dispose, unwrap } from "../util";
import {
copyCommitToClipboard,
Expand Down Expand Up @@ -131,9 +130,6 @@ export class ItemLogProvider
if (te) {
const uri = te.document.uri;
if (uri.scheme === "file") {
if (uri.path.startsWith(tempdir)) {
return; // do not refresh if diff was called
}
const repo = this.sourceControlManager.getRepository(uri);
if (repo !== null) {
try {
Expand Down
41 changes: 0 additions & 41 deletions src/tempFiles.ts

This file was deleted.

31 changes: 31 additions & 0 deletions src/temp_svn_fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
workspace
} from "vscode";
import * as path from "path";
import * as crypto from "crypto";
import { configuration } from "./helpers/configuration";
import { iconv } from "./vscodeModules";

export class File implements FileStat {
type: FileType;
Expand Down Expand Up @@ -183,6 +186,34 @@ class TempSvnFs implements FileSystemProvider, Disposable {
);
}

async createTempSvnRevisionFile(
svnUri: Uri,
revision: string,
content: string
) {
const fname = `r${revision}_${path.basename(svnUri.fsPath)}`;
const hash = crypto.createHash("md5");
const filePathHash = hash.update(svnUri.path).digest("hex");
const encoding = configuration.get<string>("default.encoding");

if (encoding) {
content = iconv.encode(content, encoding).toString();
}

if (!this._root.entries.has(filePathHash)) {
this.createDirectory(Uri.parse(`tempsvnfs:/${filePathHash}`));
}

const uri = Uri.parse(`tempsvnfs:/${filePathHash}/${fname}`, true);

this.writeFile(uri, Buffer.from(content), {
create: true,
overwrite: true
});

return uri;
}

dispose(): void {
this._disposables.forEach(disposable => disposable.dispose());
this._disposables = [];
Expand Down
54 changes: 0 additions & 54 deletions src/test/tempFiles.test.ts

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/temp_svn_fs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as assert from "assert";
import { Uri } from "vscode";
import { tempSvnFs } from "../temp_svn_fs";
import { join } from "path";

suite("Test temp svn fs", () => {
test("Temp files matches expected", async () => {
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");

const revisionUri = await tempSvnFs.createTempSvnRevisionFile(
svnUri,
"30",
"test content"
);

assert.equal(revisionUri.fsPath, join('/', '1181ae15a77d83ac0b077051dfed21ed', 'r30_test.js'));
});

test("Temp file is created", async () => {
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");

const uri = await tempSvnFs.createTempSvnRevisionFile(
svnUri,
"30",
"test content"
);

assert.ok(tempSvnFs.stat(uri));
});

test("Temp contents are correct", async () => {
const svnUri = Uri.parse("http://example.com/svn/test/trunk/test.js");

const revisionUri = await tempSvnFs.createTempSvnRevisionFile(
svnUri,
"30",
"test content"
);

assert.equal(tempSvnFs.readFile(revisionUri), "test content");
});
});

0 comments on commit c31eb21

Please sign in to comment.