Skip to content

Commit

Permalink
feat: Added log search commands (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnstonCode committed Jan 27, 2020
1 parent d8bbe4c commit 6fc635f
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 1 deletion.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@
"light": "icons/light/icon-history.svg",
"dark": "icons/dark/icon-history.svg"
}
},
{
"command": "svn.searchLogByRevision",
"title": "Search log by revision",
"category": "SVN"
},
{
"command": "svn.searchLogByText",
"title": "Search log",
"category": "SVN"
}
],
"menus": {
Expand Down Expand Up @@ -650,6 +660,14 @@
{
"command": "svn.pickCommitMessage",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
},
{
"command": "svn.searchLogByRevision",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
},
{
"command": "svn.searchLogByText",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0 && isSvn18orGreater"
}
],
"view/title": [
Expand Down
4 changes: 4 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { SwitchBranch } from "./commands/switchBranch";
import { Update } from "./commands/update";
import { Upgrade } from "./commands/upgrade";
import { SourceControlManager } from "./source_control_manager";
import { SearchLogByRevision } from "./commands/search_log_by_revision";
import { SearchLogByText } from "./commands/search_log_by_text";

export function registerCommands(
sourceControlManager: SourceControlManager,
Expand Down Expand Up @@ -91,4 +93,6 @@ export function registerCommands(
disposables.push(new RevertAll());
disposables.push(new PickCommitMessage());
disposables.push(new RevertExplorer());
disposables.push(new SearchLogByRevision());
disposables.push(new SearchLogByText());
}
41 changes: 41 additions & 0 deletions src/commands/search_log_by_revision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as path from "path";
import { Command } from "./command";
import { window, Uri, commands } from "vscode";
import { Repository } from "../repository";
import { toSvnUri } from "../uri";
import { SvnUriAction } from "../common/types";

export class SearchLogByRevision extends Command {
constructor() {
super("svn.searchLogByRevision", { repository: true });
}

public async execute(repository: Repository) {
const input = await window.showInputBox({ prompt: "Revision?" });
if (!input) {
return;
}

const revision = parseInt(input, 10);
if (!revision || !/^\+?(0|[1-9]\d*)$/.test(input)) {
window.showErrorMessage("Invalid revision");
return;
}

try {
const resource = toSvnUri(
Uri.file(repository.workspaceRoot),
SvnUriAction.LOG_REVISION,
{ revision }
);
const uri = resource.with({
path: path.join(resource.path, "svn.log")
});

await commands.executeCommand<void>("vscode.open", uri);
} catch (error) {
console.error(error);
window.showErrorMessage("Unable to log");
}
}
}
35 changes: 35 additions & 0 deletions src/commands/search_log_by_text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as path from "path";
import { Command } from "./command";
import { window, Uri, commands } from "vscode";
import { Repository } from "../repository";
import { toSvnUri } from "../uri";
import { SvnUriAction } from "../common/types";

export class SearchLogByText extends Command {
constructor() {
super("svn.searchLogByText", { repository: true });
}

public async execute(repository: Repository) {
const input = await window.showInputBox({ prompt: "Search query" });
if (!input) {
return;
}

try {
const resource = toSvnUri(
Uri.file(repository.workspaceRoot),
SvnUriAction.LOG_SEARCH,
{ search: input }
);
const uri = resource.with({
path: path.join(resource.path, "svn.log")
});

await commands.executeCommand<void>("vscode.open", uri);
} catch (error) {
console.error(error);
window.showErrorMessage("Unable to log");
}
}
}
6 changes: 5 additions & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,17 @@ export interface ISvn {
export enum SvnUriAction {
LOG = "LOG",
PATCH = "PATCH",
SHOW = "SHOW"
SHOW = "SHOW",
LOG_REVISION = "LOG_REVISION",
LOG_SEARCH = "LOG_SEARCH"
}

export interface ISvnUriExtraParams {
ref?: string;
limit?: string;
[key: string]: any;
revision?: number;
search?: string;
}

export interface ISvnUriParams {
Expand Down
14 changes: 14 additions & 0 deletions src/contexts/isSvn18orGreater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Disposable } from "vscode";
import * as semver from "semver";
import { setVscodeContext } from "../util";

export class IsSvn18orGreater implements Disposable {
constructor(svnVersion: string) {
const is18orGreater = semver.satisfies(svnVersion, ">= 1.8");

setVscodeContext("isSvn18orGreater", is18orGreater);
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
dispose() {}
}
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SvnProvider from "./treeView/dataProviders/svnProvider";
import { toDisposable } from "./util";
import { BranchChangesProvider } from "./historyView/branchChangesProvider";
import { IsSvn19orGreater } from "./contexts/isSvn19orGreater";
import { IsSvn18orGreater } from "./contexts/isSvn18orGreater";

async function init(
_context: ExtensionContext,
Expand Down Expand Up @@ -62,6 +63,7 @@ async function init(

disposables.push(new CheckActiveEditor(sourceControlManager));
disposables.push(new OpenRepositoryCount(sourceControlManager));
disposables.push(new IsSvn18orGreater(info.version));
disposables.push(new IsSvn19orGreater(info.version));

outputChannel.appendLine(`Using svn "${info.version}" from "${info.path}"`);
Expand Down
12 changes: 12 additions & 0 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,18 @@ export class Repository implements IRemoteRepository {
return this.run(Operation.Log, () => this.repository.plainLog());
}

public async plainLogByRevision(revision: number) {
return this.run(Operation.Log, () =>
this.repository.plainLogByRevision(revision)
);
}

public async plainLogByText(search: string) {
return this.run(Operation.Log, () =>
this.repository.plainLogByText(search)
);
}

public async log(
rfrom: string,
rto: string,
Expand Down
6 changes: 6 additions & 0 deletions src/svnContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export class SvnContentProvider
if (action === SvnUriAction.LOG) {
return await repository.plainLog();
}
if (action === SvnUriAction.LOG_REVISION && extra.revision) {
return await repository.plainLogByRevision(extra.revision);
}
if (action === SvnUriAction.LOG_SEARCH && extra.search) {
return await repository.plainLogByText(extra.search);
}
if (action === SvnUriAction.PATCH) {
return await repository.patch([fsPath]);
}
Expand Down
12 changes: 12 additions & 0 deletions src/svnRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,18 @@ export class Repository {
return result.stdout;
}

public async plainLogByRevision(revision: number) {
const result = await this.exec(["log", "-r", revision.toString()]);

return result.stdout;
}

public async plainLogByText(search: string) {
const result = await this.exec(["log", "--search", search]);

return result.stdout;
}

public async log(
rfrom: string,
rto: string,
Expand Down

0 comments on commit 6fc635f

Please sign in to comment.