Parcourir la source

Adds compact mode for showing branch/tag tips

main
Eric Amodio il y a 4 ans
Parent
révision
f4f2931a69
2 fichiers modifiés avec 25 ajouts et 7 suppressions
  1. +23
    -5
      src/git/gitService.ts
  2. +2
    -2
      src/views/nodes/commitNode.ts

+ 23
- 5
src/git/gitService.ts Voir le fichier

@ -20,7 +20,7 @@ import {
} from 'vscode';
import { API as BuiltInGitApi, Repository as BuiltInGitRepository, GitExtension } from '../@types/git';
import { BranchSorting, configuration, TagSorting } from '../configuration';
import { CommandContext, DocumentSchemes, setCommandContext } from '../constants';
import { CommandContext, DocumentSchemes, GlyphChars, setCommandContext } from '../constants';
import { Container } from '../container';
import { LogCorrelationContext, Logger } from '../logger';
import { Messages } from '../messages';
@ -1204,15 +1204,33 @@ export class GitService implements Disposable {
const [branches, tags] = await Promise.all([this.getBranches(repoPath), this.getTags(repoPath)]);
const branchesAndTagsBySha = Arrays.groupByFilterMap(
(branches as { name: string; sha: string }[]).concat(tags as { name: string; sha: string }[]),
(branches as (GitBranch | GitTag)[]).concat(tags as (GitBranch | GitTag)[]),
bt => bt.sha,
bt => (bt.name === currentName ? undefined : bt.name),
bt => {
if (currentName) {
if (bt.name === currentName) return undefined;
if (bt.refType === 'branch' && bt.getNameWithoutRemote() === currentName) {
return { name: bt.name, compactName: bt.getRemoteName() };
}
}
return { name: bt.name };
},
);
return (sha: string) => {
return (sha: string, compact?: boolean): string | undefined => {
const branchesAndTags = branchesAndTagsBySha.get(sha);
if (branchesAndTags == null || branchesAndTags.length === 0) return undefined;
return branchesAndTags.join(', ');
if (!compact) return branchesAndTags.map(bt => bt.name).join(', ');
if (branchesAndTags.length > 1) {
return [branchesAndTags[0], { name: GlyphChars.Ellipsis }]
.map(bt => bt.compactName ?? bt.name)
.join(', ');
}
return branchesAndTags.map(bt => bt.compactName ?? bt.name).join(', ');
};
}

+ 2
- 2
src/views/nodes/commitNode.ts Voir le fichier

@ -22,7 +22,7 @@ export class CommitNode extends ViewRefNode
public readonly commit: GitLogCommit,
private readonly unpublished?: boolean,
public readonly branch?: GitBranch,
private readonly getBranchAndTagTips?: (sha: string) => string | undefined,
private readonly getBranchAndTagTips?: (sha: string, compact?: boolean) => string | undefined,
private readonly _options: { expand?: boolean } = {},
) {
super(commit.toGitUri(), view, parent);
@ -95,7 +95,7 @@ export class CommitNode extends ViewRefNode
getTreeItem(): TreeItem {
const label = CommitFormatter.fromTemplate(this.view.config.commitFormat, this.commit, {
dateFormat: Container.config.defaultDateFormat,
getBranchAndTagTips: this.getBranchAndTagTips,
getBranchAndTagTips: (sha: string) => this.getBranchAndTagTips?.(sha, true),
messageTruncateAtNewLine: true,
});

Chargement…
Annuler
Enregistrer