Skip to content

feat: log filter #1643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@
"title": "Add repo-like path",
"icon": "$(add)"
},
{
"command": "svn.repolog.filterAuthor",
"category": "SVN",
"title": "Set filter by author",
"icon": "$(account)"
},
{
"command": "svn.repolog.filterMsg",
"category": "SVN",
"title": "Set filter by message",
"icon": "$(filter)"
},
{
"command": "svn.repolog.copymsg",
"category": "SVN",
Expand Down Expand Up @@ -569,6 +581,14 @@
"command": "svn.renameExplorer",
"when": "false"
},
{
"command": "svn.repolog.filterAuthor",
"when": "false"
},
{
"command": "svn.repolog.filterMsg",
"when": "false"
},
{
"command": "svn.repolog.addrepolike",
"when": "false"
Expand Down Expand Up @@ -661,6 +681,16 @@
"when": "view == repolog",
"group": "navigation"
},
{
"command": "svn.repolog.filterAuthor",
"when": "view == repolog",
"group": "navigation"
},
{
"command": "svn.repolog.filterMsg",
"when": "view == repolog",
"group": "navigation"
},
{
"command": "svn.repolog.addrepolike",
"when": "view == repolog",
Expand Down
46 changes: 44 additions & 2 deletions src/historyView/repoLogProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class RepoLogProvider
._onDidChangeTreeData.event;
// TODO on-disk cache?
private readonly logCache: Map<string, ICachedLog> = new Map();
private filterAuthor: string = "";
private filterMsg: string = "";
private _dispose: Disposable[] = [];

private getCached(maybeItem?: ILogTreeItem): ICachedLog {
Expand Down Expand Up @@ -118,14 +120,44 @@ export class RepoLogProvider
return this.refresh();
// TODO refresh only required repo, need to pass element === getChildren()
}
)
),
commands.registerCommand(
"svn.repolog.filterAuthor",
this.filterAuthorGui,
this
),
commands.registerCommand("svn.repolog.filterMsg", this.filterMsgGui, this)
);
}

public dispose() {
dispose(this._dispose);
}

public filterAuthorGui() {
const box = window.createInputBox();
box.prompt = "Set filter for commit authors, empty to reset";
box.value = this.filterAuthor;
box.onDidAccept(async () => {
this.filterAuthor = box.value;
box.dispose();
this._onDidChangeTreeData.fire(undefined);
});
box.show();
}

public filterMsgGui() {
const box = window.createInputBox();
box.prompt = "Set filter for commit message, empty to reset";
box.value = this.filterMsg;
box.onDidAccept(async () => {
this.filterMsg = box.value;
box.dispose();
this._onDidChangeTreeData.fire(undefined);
});
box.show();
}

public removeRepo(element: ILogTreeItem) {
this.logCache.delete((element.data as SvnPath).toString());
this.refresh();
Expand Down Expand Up @@ -391,7 +423,17 @@ export class RepoLogProvider
if (logentries.length === 0) {
await fetchMore(cached);
}
const result = transform(logentries, LogTreeItemKind.Commit, element);
// filter
const logFiltered = logentries.filter(
({ author, msg }) =>
(this.filterAuthor === "" || author.includes(this.filterAuthor)) &&
(this.filterMsg === "" || msg.includes(this.filterMsg))
);

window.showInformationMessage(
`Filtered ${logFiltered.length} of ${logentries.length} entries`
);
const result = transform(logFiltered, LogTreeItemKind.Commit, element);
insertBaseMarker(cached, logentries, result);
if (!cached.isComplete) {
const ti = new TreeItem(`Load another ${limit} revisions`);
Expand Down