Browse Source

Adds repo picker to commit search

Adds repo name to results if there is more than 1
main
Eric Amodio 7 years ago
parent
commit
b58c023b66
8 changed files with 57 additions and 14 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +9
    -4
      src/commands/showCommitSearch.ts
  3. +5
    -0
      src/gitService.ts
  4. +14
    -0
      src/system/iterable.ts
  5. +6
    -0
      src/system/searchTree.ts
  6. +2
    -2
      src/views/commitsResultsNode.ts
  7. +7
    -3
      src/views/comparisionResultsNode.ts
  8. +11
    -5
      src/views/resultsExplorer.ts

+ 3
- 0
CHANGELOG.md View File

@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Adds a repository quick pick menu to the *Show Commit Search* command (`gitlens.showCommitSearch`) when there is no active repository
### Fixed
- Fixes [#257](https://github.com/eamodio/vscode-gitlens/issues/257) - Some branches fail to show history
- Fixes [#259](https://github.com/eamodio/vscode-gitlens/issues/259) - File history lists unrelated merge commits

+ 9
- 4
src/commands/showCommitSearch.ts View File

@ -6,8 +6,7 @@ import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRepoSearchBy, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { CommandQuickPickItem, CommitsQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickPicks';
import { CommandQuickPickItem, CommitsQuickPick, RepositoriesQuickPick, ShowCommitsSearchInResultsQuickPickItem } from '../quickPicks';
import { ShowQuickCommitDetailsCommandArgs } from './showQuickCommitDetails';
const searchByRegex = /^([@~=:#])/;
@ -38,8 +37,14 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
const gitUri = uri === undefined ? undefined : await GitUri.fromUri(uri);
const repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to show commit search`);
let repoPath = gitUri === undefined ? Container.git.getHighlanderRepoPath() : gitUri.repoPath;
if (!repoPath) {
const pick = await RepositoriesQuickPick.show(`Search for commits in which repository${GlyphChars.Ellipsis}`, args.goBackCommand);
if (pick instanceof CommandQuickPickItem) return pick.execute();
if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
repoPath = pick.repoPath;
}
args = { ...args };
const originalArgs = { ...args };

+ 5
- 0
src/gitService.ts View File

@ -1186,6 +1186,11 @@ export class GitService extends Disposable {
return repo;
}
async getRepositoryCount(): Promise<number> {
const repositoryTree = await this.getRepositoryTree();
return repositoryTree.count();
}
async getStashList(repoPath: string | undefined): Promise<GitStash | undefined> {
if (repoPath === undefined) return undefined;

+ 14
- 0
src/system/iterable.ts View File

@ -1,6 +1,20 @@
'use strict';
export namespace Iterables {
export function count<T>(source: Iterable<T> | IterableIterator<T>): number {
let count = 0;
let next: IteratorResult<T>;
while (true) {
next = (source as IterableIterator<T>).next();
if (next.done) break;
count++;
}
return count;
}
export function every<T>(source: Iterable<T> | IterableIterator<T>, predicate: (item: T) => boolean): boolean {
for (const item of source) {
if (!predicate(item)) return false;

+ 6
- 0
src/system/searchTree.ts View File

@ -339,6 +339,12 @@ export class TernarySearchTree {
return this._root !== undefined && !this._root.isEmpty();
}
count(): number {
if (this._root === undefined || this._root.isEmpty()) return 0;
return Iterables.count(this.entries());
}
entries(): Iterable<[E, string]> {
return this._iterator(this._root!, []);
}

+ 2
- 2
src/views/commitsResultsNode.ts View File

@ -13,7 +13,7 @@ export class CommitsResultsNode extends ExplorerNode {
constructor(
readonly repoPath: string,
private readonly labelFn: (log: GitLog | undefined) => string,
private readonly labelFn: (log: GitLog | undefined) => Promise<string>,
private readonly logFn: (maxCount: number | undefined) => Promise<GitLog | undefined>,
private readonly explorer: Explorer,
private readonly contextValue: ResourceType = ResourceType.Results
@ -49,7 +49,7 @@ export class CommitsResultsNode extends ExplorerNode {
const log = await this.logFn(this.maxCount);
this._cache = {
label: this.labelFn(log),
label: await this.labelFn(log),
log: log
};
}

+ 7
- 3
src/views/comparisionResultsNode.ts View File

@ -23,7 +23,7 @@ export class ComparisionResultsNode extends ExplorerNode {
this.resetChildren();
const commitsQueryFn = (maxCount: number | undefined) => Container.git.getLog(this.uri.repoPath!, { maxCount: maxCount, ref: `${this.ref1}...${this.ref2 || 'HEAD'}` });
const commitsLabelFn = (log: GitLog | undefined) => {
const commitsLabelFn = async (log: GitLog | undefined) => {
const count = log !== undefined ? log.count : 0;
const truncated = log !== undefined ? log.truncated : false;
@ -48,9 +48,13 @@ export class ComparisionResultsNode extends ExplorerNode {
}
async getTreeItem(): Promise<TreeItem> {
const repo = await Container.git.getRepository(this.uri.repoPath!);
let repository = '';
if (await Container.git.getRepositoryCount() > 1) {
const repo = await Container.git.getRepository(this.uri.repoPath!);
repository = ` ${Strings.pad(GlyphChars.Dash, 1, 1)} ${(repo && repo.formattedName) || this.uri.repoPath}`;
}
const item = new TreeItem(`Comparing ${GitService.shortenSha(this.ref1)} to ${this.ref2 !== '' ? GitService.shortenSha(this.ref2) : 'Working Tree'} ${Strings.pad(GlyphChars.Dash, 1, 1)} ${(repo && repo.formattedName) || this.uri.repoPath}`, TreeItemCollapsibleState.Expanded);
const item = new TreeItem(`Comparing ${GitService.shortenSha(this.ref1)} to ${this.ref2 !== '' ? GitService.shortenSha(this.ref2) : 'Working Tree'}${repository}`, TreeItemCollapsibleState.Expanded);
item.contextValue = ResourceType.ComparisonResults;
return item;
}

+ 11
- 5
src/views/resultsExplorer.ts View File

@ -1,8 +1,8 @@
'use strict';
import { Functions } from '../system';
import { Functions, Strings } from '../system';
import { commands, ConfigurationChangeEvent, ConfigurationTarget, Disposable, Event, EventEmitter, TreeDataProvider, TreeItem, window } from 'vscode';
import { configuration, ExplorerFilesLayout, IExplorerConfig } from '../configuration';
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants';
import { Container } from '../container';
import { RefreshNodeCommandArgs } from './explorerCommands';
import { CommitResultsNode, CommitsResultsNode, ComparisionResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes';
@ -138,7 +138,7 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider
? (maxCount: number | undefined) => Promise.resolve(results)
: results.query;
const labelFn = (log: GitLog | undefined) => {
const labelFn = async (log: GitLog | undefined) => {
if (typeof resultsLabel === 'string') return resultsLabel;
const count = log !== undefined ? log.count : 0;
@ -148,8 +148,14 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider
? { singular: 'result', plural: 'results' }
: resultsLabel.resultsType;
if (count === 1) return `1 ${resultsType.singular} for ${resultsLabel.label}`;
return `${count === 0 ? 'No' : `${count}${truncated ? '+' : ''}`} ${resultsType.plural} for ${resultsLabel.label}`;
let repository = '';
if (await Container.git.getRepositoryCount() > 1) {
const repo = await Container.git.getRepository(results.repoPath);
repository = ` ${Strings.pad(GlyphChars.Dash, 1, 1)} ${(repo && repo.formattedName) || results.repoPath}`;
}
if (count === 1) return `1 ${resultsType.singular} for ${resultsLabel.label}${repository}`;
return `${count === 0 ? 'No' : `${count}${truncated ? '+' : ''}`} ${resultsType.plural} for ${resultsLabel.label}${repository}`;
};
this.addResults(new CommitsResultsNode(results.repoPath, labelFn, Functions.seeded(query, results), this, ResourceType.SearchResults));

Loading…
Cancel
Save