Browse Source

Adds sorting/filtering to branch/tag methods

Consolidates more reusable logic into GitService
main
Eric Amodio 5 years ago
parent
commit
2892a465d8
20 changed files with 241 additions and 206 deletions
  1. +1
    -1
      src/annotations/annotations.ts
  2. +1
    -3
      src/commands/openBranchInRemote.ts
  3. +1
    -3
      src/commands/openFileInRemote.ts
  4. +0
    -6
      src/git/formatters/commitFormatter.ts
  5. +166
    -41
      src/git/gitService.ts
  6. +6
    -5
      src/git/models/repository.ts
  7. +1
    -1
      src/quickpicks/branchHistoryQuickPick.ts
  8. +1
    -1
      src/quickpicks/commitFileQuickPick.ts
  9. +1
    -1
      src/quickpicks/commitQuickPick.ts
  10. +1
    -1
      src/quickpicks/fileHistoryQuickPick.ts
  11. +33
    -71
      src/quickpicks/referencesQuickPick.ts
  12. +5
    -2
      src/views/nodes/branchNode.ts
  13. +8
    -17
      src/views/nodes/branchesNode.ts
  14. +2
    -2
      src/views/nodes/contributorNode.ts
  15. +0
    -21
      src/views/nodes/helpers.ts
  16. +7
    -16
      src/views/nodes/remoteNode.ts
  17. +2
    -8
      src/views/nodes/remotesNode.ts
  18. +2
    -2
      src/views/nodes/resultsCommitsNode.ts
  19. +2
    -2
      src/views/nodes/tagNode.ts
  20. +1
    -2
      src/views/nodes/tagsNode.ts

+ 1
- 1
src/annotations/annotations.ts View File

@ -195,7 +195,7 @@ export class Annotations {
const [presence, previousLineDiffUris, remotes] = await Promise.all([
Container.vsls.getContactPresence(commit.email),
commit.isUncommitted ? commit.getPreviousLineDiffUris(uri, editorLine, uri.sha) : undefined,
Container.git.getRemotes(commit.repoPath)
Container.git.getRemotes(commit.repoPath, { sort: true })
]);
const markdown = new MarkdownString(

+ 1
- 3
src/commands/openBranchInRemote.ts View File

@ -58,9 +58,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
{
autoPick: true,
checkmarks: false,
filters: {
branches: b => b.tracking !== undefined
},
filterBranches: b => b.tracking !== undefined,
include: 'branches'
}
);

+ 1
- 3
src/commands/openFileInRemote.ts View File

@ -87,9 +87,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
{
autoPick: true,
checkmarks: false,
filters: {
branches: b => b.tracking !== undefined
},
filterBranches: b => b.tracking !== undefined,
include: 'branches'
}
);

+ 0
- 6
src/git/formatters/commitFormatter.ts View File

@ -306,12 +306,6 @@ export class CommitFormatter extends Formatter {
}
if (this._options.remotes !== undefined) {
this._options.remotes.sort(
(a, b) =>
(a.default ? -1 : 1) - (b.default ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
for (const r of this._options.remotes) {
if (r.provider === undefined) continue;

+ 166
- 41
src/git/gitService.ts View File

@ -25,7 +25,7 @@ import { CommandContext, DocumentSchemes, setCommandContext } from '../constants
import { Container } from '../container';
import { LogCorrelationContext, Logger } from '../logger';
import { Messages } from '../messages';
import { gate, Iterables, log, Objects, Strings, TernarySearchTree, Versions } from '../system';
import { Arrays, gate, Iterables, log, Objects, Strings, TernarySearchTree, Versions } from '../system';
import { CachedBlame, CachedDiff, CachedLog, GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker';
import { vslsUriPrefixRegex } from '../vsls/vsls';
import {
@ -972,32 +972,118 @@ export class GitService implements Disposable {
}
@log()
async getBranches(repoPath: string | undefined): Promise<GitBranch[]> {
async getBranches(
repoPath: string | undefined,
options: { filter?: (b: GitBranch) => boolean; sort?: boolean } = {}
): Promise<GitBranch[]> {
if (repoPath === undefined) return [];
let branches;
if (this.useCaching) {
branches = this._branchesCache.get(repoPath);
if (branches !== undefined) return branches;
let branches: GitBranch[] | undefined;
try {
if (this.useCaching) {
branches = this._branchesCache.get(repoPath);
if (branches !== undefined) return branches;
}
const data = await Git.for_each_ref__branch(repoPath, { all: true });
// If we don't get any data, assume the repo doesn't have any commits yet so check if we have a current branch
if (data == null || data.length === 0) {
const current = await this.getBranch(repoPath);
branches = current !== undefined ? [current] : [];
}
else {
branches = GitBranchParser.parse(data, repoPath);
}
if (this.useCaching) {
const repo = await this.getRepository(repoPath);
if (repo !== undefined && repo.supportsChangeEvents) {
this._branchesCache.set(repoPath, branches);
}
}
return branches;
}
finally {
if (options.filter !== undefined) {
branches = branches!.filter(options.filter);
}
const data = await Git.for_each_ref__branch(repoPath, { all: true });
// If we don't get any data, assume the repo doesn't have any commits yet so check if we have a current branch
if (data == null || data.length === 0) {
const current = await this.getBranch(repoPath);
branches = current !== undefined ? [current] : [];
if (options.sort) {
branches!.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) ||
(b.remote ? -1 : 1) - (a.remote ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
}
if (options.filter !== undefined) {
// eslint-disable-next-line no-unsafe-finally
return branches!;
}
}
else {
branches = GitBranchParser.parse(data, repoPath);
}
@log()
async getBranchesAndOrTags(
repoPath: string | undefined,
{
filterBranches,
filterTags,
include,
...options
}: {
filterBranches?: (b: GitBranch) => boolean;
filterTags?: (t: GitTag) => boolean;
include?: 'all' | 'branches' | 'tags';
sort?: boolean;
} = {}
) {
const [branches, tags] = await Promise.all<GitBranch[] | undefined, GitTag[] | undefined>([
include === 'all' || include === 'branches'
? Container.git.getBranches(repoPath, {
...options,
filter: filterBranches && filterBranches
})
: undefined,
include === 'all' || include === 'tags'
? Container.git.getTags(repoPath, {
...options,
filter: filterTags && filterTags
})
: undefined
]);
if (branches !== undefined && tags !== undefined) {
return [...branches.filter(b => !b.remote), ...tags, ...branches.filter(b => b.remote)];
}
if (this.useCaching) {
const repo = await this.getRepository(repoPath);
if (repo !== undefined && repo.supportsChangeEvents) {
this._branchesCache.set(repoPath, branches);
}
if (branches !== undefined) {
return branches;
}
return branches;
return tags;
}
@log()
async getBranchesAndTagsTipsFn(repoPath: string | undefined, currentName?: string) {
const [branches, tags] = await Promise.all([
Container.git.getBranches(repoPath),
Container.git.getTags(repoPath, { includeRefs: true })
]);
const branchesAndTagsBySha = Arrays.groupByFilterMap(
(branches as { name: string; sha: string }[]).concat(tags as { name: string; sha: string }[]),
bt => bt.sha!,
bt => (bt.name === currentName ? undefined : bt.name)
);
return (sha: string) => {
const branchesAndTags = branchesAndTagsBySha.get(sha);
if (branchesAndTags === undefined || branchesAndTags.length === 0) return undefined;
return branchesAndTags.join(', ');
};
}
@log()
@ -1981,18 +2067,27 @@ export class GitService implements Disposable {
}
@log()
async getRemotes(repoPath: string | undefined, options: { includeAll?: boolean } = {}): Promise<GitRemote[]> {
async getRemotes(
repoPath: string | undefined,
options: { includeAll?: boolean; sort?: boolean } = {}
): Promise<GitRemote[]> {
if (repoPath === undefined) return [];
const repository = await this.getRepository(repoPath);
const remotes = repository !== undefined ? repository.getRemotes() : this.getRemotesCore(repoPath);
const remotes = await (repository !== undefined
? repository.getRemotes({ sort: options.sort })
: this.getRemotesCore(repoPath, undefined, { sort: options.sort }));
if (options.includeAll) return remotes;
return (await remotes).filter(r => r.provider !== undefined);
return remotes.filter(r => r.provider !== undefined);
}
async getRemotesCore(repoPath: string | undefined, providers?: RemoteProviders): Promise<GitRemote[]> {
async getRemotesCore(
repoPath: string | undefined,
providers?: RemoteProviders,
options: { sort?: boolean } = {}
): Promise<GitRemote[]> {
if (repoPath === undefined) return [];
providers =
@ -2003,7 +2098,18 @@ export class GitService implements Disposable {
try {
const data = await Git.remote(repoPath);
return GitRemoteParser.parse(data, repoPath, RemoteProviderFactory.factory(providers)) || [];
const remotes = GitRemoteParser.parse(data, repoPath, RemoteProviderFactory.factory(providers));
if (remotes === undefined) return [];
if (options.sort) {
remotes.sort(
(a, b) =>
(a.default ? -1 : 1) - (b.default ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
}
return remotes;
}
catch (ex) {
Logger.error(ex);
@ -2236,37 +2342,56 @@ export class GitService implements Disposable {
}
@log()
async getTags(repoPath: string | undefined, options: { includeRefs?: boolean } = {}): Promise<GitTag[]> {
async getTags(
repoPath: string | undefined,
options: { filter?: (t: GitTag) => boolean; includeRefs?: boolean; sort?: boolean } = {}
): Promise<GitTag[]> {
if (repoPath === undefined) return [];
let tags;
if (options.includeRefs) {
tags = this._tagsWithRefsCache.get(repoPath);
let tags: GitTag[] | undefined;
try {
if (options.includeRefs) {
tags = this._tagsWithRefsCache.get(repoPath);
if (tags !== undefined) return tags;
const data = await Git.show_ref__tags(repoPath);
tags = GitTagParser.parseWithRef(data, repoPath) || [];
const repo = await this.getRepository(repoPath);
if (repo !== undefined && repo.supportsChangeEvents) {
this._tagsWithRefsCache.set(repoPath, tags);
}
return tags;
}
tags = this._tagsCache.get(repoPath);
if (tags !== undefined) return tags;
const data = await Git.show_ref__tags(repoPath);
tags = GitTagParser.parseWithRef(data, repoPath) || [];
const data = await Git.tag(repoPath);
tags = GitTagParser.parse(data, repoPath) || [];
const repo = await this.getRepository(repoPath);
if (repo !== undefined && repo.supportsChangeEvents) {
this._tagsWithRefsCache.set(repoPath, tags);
this._tagsCache.set(repoPath, tags);
}
return tags;
}
finally {
if (options.filter !== undefined) {
tags = tags!.filter(options.filter);
}
tags = this._tagsCache.get(repoPath);
if (tags !== undefined) return tags;
const data = await Git.tag(repoPath);
tags = GitTagParser.parse(data, repoPath) || [];
if (options.sort) {
tags!.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
}
const repo = await this.getRepository(repoPath);
if (repo !== undefined && repo.supportsChangeEvents) {
this._tagsCache.set(repoPath, tags);
if (options.filter !== undefined) {
// eslint-disable-next-line no-unsafe-finally
return tags!;
}
}
return tags;
}
@log()

+ 6
- 5
src/git/models/repository.ts View File

@ -263,8 +263,8 @@ export class Repository implements Disposable {
return this._branch;
}
getBranches(): Promise<GitBranch[]> {
return Container.git.getBranches(this.path);
getBranches(options: { filter?: (b: GitBranch) => boolean; sort?: boolean } = {}): Promise<GitBranch[]> {
return Container.git.getBranches(this.path, options);
}
getChangedFilesCount(sha?: string): Promise<GitDiffShortStat | undefined> {
@ -284,7 +284,7 @@ export class Repository implements Disposable {
);
}
getRemotes(): Promise<GitRemote[]> {
getRemotes(options: { sort?: boolean } = {}): Promise<GitRemote[]> {
if (this._remotes === undefined || !this.supportsChangeEvents) {
if (this._providers === undefined) {
const remotesCfg = configuration.get<RemotesConfig[] | null | undefined>(
@ -294,7 +294,8 @@ export class Repository implements Disposable {
this._providers = RemoteProviderFactory.loadProviders(remotesCfg);
}
this._remotes = Container.git.getRemotesCore(this.path, this._providers);
// Since we are caching the results, always sort
this._remotes = Container.git.getRemotesCore(this.path, this._providers, { sort: true });
}
return this._remotes;
@ -308,7 +309,7 @@ export class Repository implements Disposable {
return Container.git.getStatusForRepo(this.path);
}
getTags(options?: { includeRefs?: boolean }): Promise<GitTag[]> {
getTags(options?: { filter?: (t: GitTag) => boolean; includeRefs?: boolean; sort?: boolean }): Promise<GitTag[]> {
return Container.git.getTags(this.path, options);
}

+ 1
- 1
src/quickpicks/branchHistoryQuickPick.ts View File

@ -55,7 +55,7 @@ export class BranchHistoryQuickPick {
[uri, currentCommandArgs]
);
const remotes = await Container.git.getRemotes((uri && uri.repoPath) || log.repoPath);
const remotes = await Container.git.getRemotes((uri && uri.repoPath) || log.repoPath, { sort: true });
if (remotes.length) {
items.splice(
0,

+ 1
- 1
src/quickpicks/commitFileQuickPick.ts View File

@ -191,7 +191,7 @@ export class CommitFileQuickPick {
}
items.push(new OpenCommitFileRevisionCommandQuickPickItem(commit));
const remotes = await Container.git.getRemotes(commit.repoPath);
const remotes = await Container.git.getRemotes(commit.repoPath, { sort: true });
if (remotes.length) {
if (workingUri && commit.status !== 'D') {
const branch = await Container.git.getBranch(commit.repoPath);

+ 1
- 1
src/quickpicks/commitQuickPick.ts View File

@ -293,7 +293,7 @@ export class CommitQuickPick {
else {
items.splice(index++, 0, new ShowCommitInViewQuickPickItem(commit));
remotes = await Container.git.getRemotes(commit.repoPath);
remotes = await Container.git.getRemotes(commit.repoPath, { sort: true });
if (remotes.length) {
items.splice(
index++,

+ 1
- 1
src/quickpicks/fileHistoryQuickPick.ts View File

@ -159,7 +159,7 @@ export class FileHistoryQuickPick {
);
}
const remotes = await Container.git.getRemotes(uri.repoPath!);
const remotes = await Container.git.getRemotes(uri.repoPath!, { sort: true });
if (remotes.length) {
const resource: RemoteResource =
uri.sha !== undefined

+ 33
- 71
src/quickpicks/referencesQuickPick.ts View File

@ -37,7 +37,7 @@ export class BranchQuickPickItem implements QuickPickItem {
description: string;
detail: string | undefined;
constructor(public readonly branch: GitBranch, showCheckmarks: boolean, checked: boolean | undefined) {
constructor(public readonly branch: GitBranch, showCheckmarks: boolean, checked?: boolean) {
checked = showCheckmarks && (checked || (checked === undefined && branch.current));
this.label = `${
checked ? `$(check)${GlyphChars.Space.repeat(2)}` : showCheckmarks ? GlyphChars.Space.repeat(6) : ''
@ -71,7 +71,7 @@ export class TagQuickPickItem implements QuickPickItem {
description: string;
detail: string | undefined;
constructor(public readonly tag: GitTag, showCheckmarks: boolean, checked: boolean) {
constructor(public readonly tag: GitTag, showCheckmarks: boolean, checked?: boolean) {
checked = showCheckmarks && checked;
this.label = `${
checked ? `$(check)${GlyphChars.Space.repeat(2)}` : showCheckmarks ? GlyphChars.Space.repeat(6) : ''
@ -103,10 +103,8 @@ export interface ReferencesQuickPickOptions {
autoPick?: boolean;
checked?: string;
checkmarks: boolean;
filters?: {
branches?(branch: GitBranch): boolean;
tags?(tag: GitTag): boolean;
};
filterBranches?(branch: GitBranch): boolean;
filterTags?(tag: GitTag): boolean;
goBack?: CommandQuickPickItem;
include?: 'branches' | 'tags' | 'all';
}
@ -216,75 +214,39 @@ export class ReferencesQuickPick {
}
}
private async getItems(options: ReferencesQuickPickOptions, token: CancellationToken) {
const { checked, checkmarks, filters, goBack, include } = { include: 'all', ...options };
let branches;
let tags;
switch (include) {
case 'branches': {
const result = await Functions.cancellable(Container.git.getBranches(this.repoPath), token);
if (result === undefined || token.isCancellationRequested) return [];
branches = result;
break;
}
case 'tags': {
const result = await Functions.cancellable(Container.git.getTags(this.repoPath), token);
if (result === undefined || token.isCancellationRequested) return [];
tags = result;
break;
}
default: {
const result = await Functions.cancellable(
Promise.all([Container.git.getBranches(this.repoPath), Container.git.getTags(this.repoPath)]),
token
);
if (result === undefined || token.isCancellationRequested) return [];
[branches, tags] = result;
break;
}
}
private async getItems(
{ checked, checkmarks, goBack, ...options }: ReferencesQuickPickOptions,
token: CancellationToken
) {
const branchesAndOrTags = await Functions.cancellable(
Container.git.getBranchesAndOrTags(this.repoPath, {
include: options.include || 'all',
filterBranches: options.filterBranches,
filterTags: options.filterTags,
sort: true
}),
token
);
if (branchesAndOrTags === undefined || token.isCancellationRequested) return [];
const items: (BranchQuickPickItem | TagQuickPickItem | CommandQuickPickItem)[] = [];
if (branches !== undefined) {
const filter =
filters !== undefined && typeof filters.branches === 'function' ? filters.branches : undefined;
branches.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) ||
(b.remote ? -1 : 1) - (a.remote ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
for (const b of branches) {
if (filter !== undefined && !filter(b)) continue;
if (checkmarks && checked !== undefined && b.name === checked) {
items.splice(0, 0, new BranchQuickPickItem(b, checkmarks, true));
}
else {
items.push(new BranchQuickPickItem(b, checkmarks, checked === undefined ? undefined : false));
}
for (const bt of branchesAndOrTags) {
if (checkmarks && checked === bt.name) {
items.splice(
0,
0,
new (GitBranch.is(bt) ? BranchQuickPickItem : TagQuickPickItem)(bt as any, checkmarks, true)
);
}
}
if (tags !== undefined) {
const filter = filters !== undefined && typeof filters.tags === 'function' ? filters.tags : undefined;
tags.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
for (const t of tags) {
if (filter !== undefined && !filter(t)) continue;
if (checkmarks && checked !== undefined && t.name === checked) {
items.splice(0, 0, new TagQuickPickItem(t, checkmarks, true));
}
else {
items.push(new TagQuickPickItem(t, checkmarks, false));
}
else {
items.push(
new (GitBranch.is(bt) ? BranchQuickPickItem : TagQuickPickItem)(
bt as any,
checkmarks,
checked === undefined ? undefined : false
)
);
}
}

+ 5
- 2
src/views/nodes/branchNode.ts View File

@ -9,7 +9,7 @@ import { RepositoriesView } from '../repositoriesView';
import { BranchTrackingStatusNode } from './branchTrackingStatusNode';
import { CommitNode } from './commitNode';
import { MessageNode, ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode, ViewRefNode } from './viewNode';
export class BranchNode extends ViewRefNode<RepositoriesView> implements PageableViewNode {
@ -83,7 +83,10 @@ export class BranchNode extends ViewRefNode implements Pageabl
});
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];
const getBranchAndTagTips = await getBranchesAndTagTipsFn(this.uri.repoPath, this.branch.name);
const getBranchAndTagTips = await Container.git.getBranchesAndTagsTipsFn(
this.uri.repoPath,
this.branch.name
);
children.push(
...insertDateMarkers(
Iterables.map(

+ 8
- 17
src/views/nodes/branchesNode.ts View File

@ -3,7 +3,7 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewBranchesLayout } from '../../configuration';
import { Container } from '../../container';
import { GitUri, Repository } from '../../git/gitService';
import { Arrays, debug, gate, Iterables } from '../../system';
import { Arrays, debug, gate } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
@ -22,21 +22,14 @@ export class BranchesNode extends ViewNode {
async getChildren(): Promise<ViewNode[]> {
if (this._children === undefined) {
const branches = await this.repo.getBranches();
const branches = await this.repo.getBranches({
// only show local branches
filter: b => !b.remote,
sort: true
});
if (branches === undefined) return [];
branches.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
// filter local branches
const branchNodes = [
...Iterables.filterMap(branches, b =>
b.remote ? undefined : new BranchNode(this.uri, this.view, this, b)
)
];
const branchNodes = branches.map(b => new BranchNode(this.uri, this.view, this, b));
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;
const hierarchy = Arrays.makeHierarchical(
@ -62,11 +55,9 @@ export class BranchesNode extends ViewNode {
}
async getTreeItem(): Promise<TreeItem> {
const remotes = await this.repo.getRemotes();
const item = new TreeItem('Branches', TreeItemCollapsibleState.Collapsed);
item.contextValue = ResourceType.Branches;
if (remotes !== undefined && remotes.length > 0) {
if (await this.repo.hasRemotes()) {
item.contextValue += '+remotes';
}
item.iconPath = {

+ 2
- 2
src/views/nodes/contributorNode.ts View File

@ -6,7 +6,7 @@ import { RepositoriesView } from '../repositoriesView';
import { PageableViewNode, ResourceType, ViewNode } from './viewNode';
import { Container } from '../../container';
import { MessageNode, ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { insertDateMarkers } from './helpers';
import { CommitNode } from './commitNode';
import { GlyphChars } from '../../constants';
@ -30,7 +30,7 @@ export class ContributorNode extends ViewNode implements Pagea
});
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];
const getBranchAndTagTips = await getBranchesAndTagTipsFn(this.uri.repoPath);
const getBranchAndTagTips = await Container.git.getBranchesAndTagsTipsFn(this.uri.repoPath);
const children = [
...insertDateMarkers(
Iterables.map(

+ 0
- 21
src/views/nodes/helpers.ts View File

@ -1,29 +1,8 @@
'use strict';
import { Container } from '../../container';
import { GitLogCommit } from '../../git/gitService';
import { Arrays } from '../../system';
import { MessageNode } from './common';
import { ViewNode } from './viewNode';
export async function getBranchesAndTagTipsFn(repoPath: string | undefined, currentName?: string) {
const [branches, tags] = await Promise.all([
Container.git.getBranches(repoPath),
Container.git.getTags(repoPath, { includeRefs: true })
]);
const branchesAndTagsBySha = Arrays.groupByFilterMap(
(branches as { name: string; sha: string }[]).concat(tags as { name: string; sha: string }[]),
bt => bt.sha!,
bt => (bt.name === currentName ? undefined : bt.name)
);
return (sha: string) => {
const branchesAndTags = branchesAndTagsBySha.get(sha);
if (branchesAndTags === undefined || branchesAndTags.length === 0) return undefined;
return branchesAndTags.join(', ');
};
}
const markers: [number, string][] = [
[0, 'Less than a week ago'],
[7, 'Over a week ago'],

+ 7
- 16
src/views/nodes/remoteNode.ts View File

@ -4,7 +4,7 @@ import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitRemote, GitRemoteType, GitUri, Repository } from '../../git/gitService';
import { Arrays, Iterables, log } from '../../system';
import { Arrays, log } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
@ -26,23 +26,14 @@ export class RemoteNode extends ViewNode {
}
async getChildren(): Promise<ViewNode[]> {
const branches = await this.repo.getBranches();
const branches = await this.repo.getBranches({
// only show remote branchs for this remote
filter: b => b.remote && b.name.startsWith(this.remote.name),
sort: true
});
if (branches === undefined) return [];
branches.sort(
(a, b) =>
(a.starred ? -1 : 1) - (b.starred ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
// filter remote branches
const branchNodes = [
...Iterables.filterMap(branches, b =>
!b.remote || !b.name.startsWith(this.remote.name)
? undefined
: new BranchNode(this.uri, this.view, this, b)
)
];
const branchNodes = branches.map(b => new BranchNode(this.uri, this.view, this, b));
if (this.view.config.branches.layout === ViewBranchesLayout.List) return branchNodes;
const hierarchy = Arrays.makeHierarchical(

+ 2
- 8
src/views/nodes/remotesNode.ts View File

@ -2,7 +2,6 @@
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Container } from '../../container';
import { GitUri, Repository } from '../../git/gitService';
import { Iterables } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { MessageNode } from './common';
import { RemoteNode } from './remoteNode';
@ -18,17 +17,12 @@ export class RemotesNode extends ViewNode {
}
async getChildren(): Promise<ViewNode[]> {
const remotes = await this.repo.getRemotes();
const remotes = await this.repo.getRemotes({ sort: true });
if (remotes === undefined || remotes.length === 0) {
return [new MessageNode(this.view, this, 'No remotes could be found')];
}
remotes.sort(
(a, b) =>
(a.default ? -1 : 1) - (b.default ? -1 : 1) ||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
);
return [...Iterables.map(remotes, r => new RemoteNode(this.uri, this.view, this, r, this.repo))];
return remotes.map(r => new RemoteNode(this.uri, this.view, this, r, this.repo));
}
getTreeItem(): TreeItem {

+ 2
- 2
src/views/nodes/resultsCommitsNode.ts View File

@ -6,7 +6,7 @@ import { debug, gate, Iterables } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { CommitNode } from './commitNode';
import { ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode } from './viewNode';
export interface CommitsQueryResults {
@ -44,7 +44,7 @@ export class ResultsCommitsNode extends ViewNode implements Pagea
const { log } = await this.getCommitsQueryResults();
if (log === undefined) return [];
const getBranchAndTagTips = await getBranchesAndTagTipsFn(this.uri.repoPath);
const getBranchAndTagTips = await Container.git.getBranchesAndTagsTipsFn(this.uri.repoPath);
const children = [
...insertDateMarkers(
Iterables.map(

+ 2
- 2
src/views/nodes/tagNode.ts View File

@ -7,7 +7,7 @@ import { Iterables } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { CommitNode } from './commitNode';
import { MessageNode, ShowMoreNode } from './common';
import { getBranchesAndTagTipsFn, insertDateMarkers } from './helpers';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, ViewNode, ViewRefNode } from './viewNode';
import { emojify } from '../../emojis';
@ -39,7 +39,7 @@ export class TagNode extends ViewRefNode implements PageableVi
});
if (log === undefined) return [new MessageNode(this.view, this, 'No commits could be found.')];
const getBranchAndTagTips = await getBranchesAndTagTipsFn(this.uri.repoPath, this.tag.name);
const getBranchAndTagTips = await Container.git.getBranchesAndTagsTipsFn(this.uri.repoPath, this.tag.name);
const children = [
...insertDateMarkers(
Iterables.map(

+ 1
- 2
src/views/nodes/tagsNode.ts View File

@ -20,10 +20,9 @@ export class TagsNode extends ViewNode {
}
async getChildren(): Promise<ViewNode[]> {
const tags = await this.repo.getTags();
const tags = await this.repo.getTags({ sort: true });
if (tags.length === 0) return [new MessageNode(this.view, this, 'No tags could be found.')];
tags.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
const tagNodes = tags.map(t => new TagNode(this.uri, this.view, this, t));
if (this.view.config.branches.layout === ViewBranchesLayout.List) return tagNodes;

Loading…
Cancel
Save