Skip to content

Commit 302661c

Browse files
committed
Fixed document title for: file head, log and patch
1 parent 48b1d1e commit 302661c

File tree

5 files changed

+89
-45
lines changed

5 files changed

+89
-45
lines changed

src/commands.ts

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Svn, Status, SvnErrorCodes } from "./svn";
2222
import { Model } from "./model";
2323
import { Repository } from "./repository";
2424
import { Resource } from "./resource";
25-
import { toSvnUri, fromSvnUri } from "./uri";
25+
import { toSvnUri, fromSvnUri, SvnUriAction } from "./uri";
2626
import * as fs from "fs";
2727
import * as path from "path";
2828
import { start } from "repl";
@@ -377,7 +377,7 @@ export class SvnCommands implements IDisposable {
377377

378378
if (arg instanceof Uri) {
379379
if (arg.scheme === "svn") {
380-
uris = [Uri.file(fromSvnUri(arg).path)];
380+
uris = [Uri.file(fromSvnUri(arg).fsPath)];
381381
} else if (arg.scheme === "file") {
382382
uris = [arg];
383383
}
@@ -444,15 +444,23 @@ export class SvnCommands implements IDisposable {
444444

445445
const HEAD = this.getLeftResource(resource, "HEAD");
446446

447+
const basename = path.basename(resource.resourceUri.fsPath);
447448
if (!HEAD) {
448-
const basename = path.basename(resource.resourceUri.fsPath);
449449
window.showWarningMessage(
450450
`"HEAD version of '${basename}' is not available."`
451451
);
452452
return;
453453
}
454454

455-
return await commands.executeCommand<void>("vscode.open", HEAD);
455+
const basedir = path.dirname(resource.resourceUri.fsPath);
456+
457+
const uri = HEAD.with({
458+
path: path.join(basedir, `(HEAD) ${basename}`) // change document title
459+
});
460+
461+
return await commands.executeCommand<void>("vscode.open", uri, {
462+
preview: true
463+
});
456464
}
457465

458466
@command("svn.openChangeBase")
@@ -572,13 +580,17 @@ export class SvnCommands implements IDisposable {
572580
against: string = ""
573581
): Uri | undefined {
574582
if (resource.type === Status.ADDED && resource.renameResourceUri) {
575-
return toSvnUri(resource.renameResourceUri, against);
583+
return toSvnUri(resource.renameResourceUri, SvnUriAction.SHOW, {
584+
ref: against
585+
});
576586
}
577587

578588
switch (resource.type) {
579589
case Status.MODIFIED:
580590
case Status.REPLACED:
581-
return toSvnUri(resource.resourceUri, against);
591+
return toSvnUri(resource.resourceUri, SvnUriAction.SHOW, {
592+
ref: against
593+
});
582594
}
583595
}
584596

@@ -595,7 +607,9 @@ export class SvnCommands implements IDisposable {
595607
return resource.resourceUri;
596608
case Status.DELETED:
597609
case Status.MISSING:
598-
return toSvnUri(resource.resourceUri, against);
610+
return toSvnUri(resource.resourceUri, SvnUriAction.SHOW, {
611+
ref: against
612+
});
599613
}
600614
}
601615

@@ -714,14 +728,17 @@ export class SvnCommands implements IDisposable {
714728
@command("svn.patch", { repository: true })
715729
async patch(repository: Repository) {
716730
try {
717-
const result = await repository.patch();
718-
// send the patch results to a new tab
719-
workspace
720-
.openTextDocument({ language: "diff", content: result })
721-
.then(doc => {
722-
window.showTextDocument(doc);
723-
});
724-
window.showInformationMessage("Files Patched");
731+
const resource = toSvnUri(
732+
Uri.file(repository.workspaceRoot),
733+
SvnUriAction.PATCH
734+
);
735+
const uri = resource.with({
736+
path: path.join(resource.path, "svn.patch") // change document title
737+
});
738+
739+
await commands.executeCommand<void>("vscode.open", uri, {
740+
preview: true
741+
});
725742
} catch (error) {
726743
console.error(error);
727744
window.showErrorMessage("Unable to patch");
@@ -806,15 +823,16 @@ export class SvnCommands implements IDisposable {
806823
@command("svn.log", { repository: true })
807824
async log(repository: Repository) {
808825
try {
809-
const logPromise = repository.log();
810-
window.withProgress(
811-
{ location: ProgressLocation.Window, title: "Fetching logs" },
812-
() => logPromise
826+
const resource = toSvnUri(
827+
Uri.file(repository.workspaceRoot),
828+
SvnUriAction.LOG
813829
);
814-
const result = await logPromise;
815-
// send the log results to a new tab
816-
workspace.openTextDocument({ content: result }).then(doc => {
817-
window.showTextDocument(doc);
830+
const uri = resource.with({
831+
path: path.join(resource.path, "svn.log") // change document title
832+
});
833+
834+
await commands.executeCommand<void>("vscode.open", uri, {
835+
preview: true
818836
});
819837
} catch (error) {
820838
console.error(error);
@@ -833,7 +851,9 @@ export class SvnCommands implements IDisposable {
833851
return;
834852
}
835853

836-
const originalUri = toSvnUri(modifiedUri, "BASE");
854+
const originalUri = toSvnUri(modifiedUri, SvnUriAction.SHOW, {
855+
ref: "BASE"
856+
});
837857
const originalDocument = await workspace.openTextDocument(originalUri);
838858
const basename = path.basename(modifiedUri.fsPath);
839859
const message = `Are you sure you want to revert the selected changes in ${basename}?`;
@@ -934,8 +954,8 @@ export class SvnCommands implements IDisposable {
934954
}
935955

936956
if (uri.scheme === "svn") {
937-
const { path } = fromSvnUri(uri);
938-
uri = Uri.file(path);
957+
const { fsPath } = fromSvnUri(uri);
958+
uri = Uri.file(fsPath);
939959
}
940960

941961
if (uri.scheme === "file") {

src/repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import * as path from "path";
2828
import * as micromatch from "micromatch";
2929
import { setInterval, clearInterval } from "timers";
30-
import { toSvnUri } from "./uri";
30+
import { toSvnUri, SvnUriAction } from "./uri";
3131
import { Status, PropStatus, SvnErrorCodes } from "./svn";
3232
import { IFileStatus } from "./statusParser";
3333

@@ -492,7 +492,7 @@ export class Repository {
492492
return;
493493
}
494494

495-
return toSvnUri(uri, "");
495+
return toSvnUri(uri, SvnUriAction.SHOW);
496496
}
497497

498498
async getBranches() {

src/svnContentProvider.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
window
99
} from "vscode";
1010
import { Model, ModelChangeEvent, OriginalResourceChangeEvent } from "./model";
11-
import { toSvnUri, fromSvnUri } from "./uri";
11+
import { toSvnUri, fromSvnUri, SvnUriAction } from "./uri";
1212
import { throttle, debounce } from "./decorators";
1313
import {
1414
filterEvent,
@@ -100,12 +100,20 @@ export class SvnContentProvider
100100
this.cache[cacheKey] = cacheValue;
101101

102102
try {
103-
const { path, ref } = fromSvnUri(uri);
103+
const { fsPath, action, extra } = fromSvnUri(uri);
104104

105-
return await repository.show(path, ref);
106-
} catch (error) {
107-
return "";
108-
}
105+
if (action === SvnUriAction.SHOW) {
106+
const ref = extra.ref;
107+
return await repository.show(fsPath, ref);
108+
}
109+
if (action === SvnUriAction.LOG) {
110+
return await repository.log();
111+
}
112+
if (action === SvnUriAction.PATCH) {
113+
return await repository.patch();
114+
}
115+
} catch (error) {}
116+
return "";
109117
}
110118

111119
private cleanup(): void {
@@ -114,10 +122,10 @@ export class SvnContentProvider
114122

115123
Object.keys(this.cache).forEach(key => {
116124
const row = this.cache[key];
117-
const { path } = fromSvnUri(row.uri);
125+
const { fsPath } = fromSvnUri(row.uri);
118126
const isOpen = workspace.textDocuments
119127
.filter(d => d.uri.scheme === "file")
120-
.some(d => d.uri.fsPath === path);
128+
.some(d => d.uri.fsPath === fsPath);
121129

122130
if (isOpen || now - row.timestamp < THREE_MINUTES) {
123131
cache[row.uri.toString()] = row;

src/uri.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
import { Uri } from "vscode";
22

3+
export enum SvnUriAction {
4+
LOG = "LOG",
5+
PATCH = "PATCH",
6+
SHOW = "SHOW"
7+
}
8+
9+
export interface SvnUriExtraParams {
10+
ref?: string;
11+
limit?: string;
12+
[key: string]: any;
13+
}
14+
315
export interface SvnUriParams {
4-
path: string;
5-
ref: string;
16+
action: SvnUriAction;
17+
fsPath: string;
18+
extra: SvnUriExtraParams;
619
}
720

821
export function fromSvnUri(uri: Uri): SvnUriParams {
922
return JSON.parse(uri.query);
1023
}
1124

12-
export function toSvnUri(uri: Uri, ref: string): Uri {
25+
export function toSvnUri(uri: Uri, action: SvnUriAction, extra: SvnUriExtraParams = {}): Uri {
26+
const params: SvnUriParams = {
27+
action: action,
28+
fsPath: uri.fsPath,
29+
extra: extra
30+
};
31+
1332
return uri.with({
1433
scheme: "svn",
1534
path: uri.path,
16-
query: JSON.stringify({
17-
path: uri.fsPath,
18-
ref
19-
})
35+
query: JSON.stringify(params)
2036
});
2137
}

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export function isDescendant(parent: string, descendant: string): boolean {
7474

7575
// IF Windows
7676
if (sep === "\\") {
77-
parent = parent.toLowerCase();
78-
descendant = descendant.toLowerCase();
77+
parent = parent.replace(/^\\/, "").toLowerCase();
78+
descendant = descendant.replace(/^\\/, "").toLowerCase();
7979
}
8080

8181
if (parent === descendant) {

0 commit comments

Comments
 (0)