Skip to content

Commit ef09685

Browse files
committed
Closes #4726 adds is:tip filter support to Graph
1 parent 4fca052 commit ef09685

File tree

8 files changed

+52
-19
lines changed

8 files changed

+52
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111
- Adds a new _Safe Hard Reset_ (`--keep`) option to Git _reset_ command
1212
- Adds support for reference or range commit searches on the _Commit Graph_, _Search & Compare_ view, and in the _Search Commits_ command ([#4723](https://github.com/gitkraken/vscode-gitlens/issues/4723))
1313
- Adds natural language support to allow for more powerful queries
14+
- Adds ability to filter/search to branch & tag tips on the _Commit Graph_ ([#4726](https://github.com/gitkraken/vscode-gitlens/issues/4726))
1415
- Adds a navigable search history to the search box on the _Commit Graph_ ([#4724](https://github.com/gitkraken/vscode-gitlens/issues/4724))
1516
- Adds ability to show file or folder histories on the _Commit Graph_ ([#4725](https://github.com/gitkraken/vscode-gitlens/issues/4725))
1617
- Adds _Open File History in Commit Graph_ command to files in views

src/commands/git/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class SearchGitCommand extends QuickCommand<State> {
337337
items.push(
338338
{
339339
label: searchOperatorToTitleMap.get('type:')!,
340-
description: 'type:stash or is:stash',
340+
description: 'type:stash or is:stash; type:tip or is:tip',
341341
alwaysShow: true,
342342
item: { type: 'add', operator: 'type:' },
343343
},

src/env/node/git/sub-providers/commits.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,8 @@ async function parseCommits(
12671267
let countStashChildCommits = 0;
12681268
const commits = new Map<string, GitCommit>();
12691269

1270+
const tipsOnly = searchFilters?.type === 'tip';
1271+
12701272
if (resultOrStream instanceof Promise) {
12711273
const result = await resultOrStream;
12721274

@@ -1276,8 +1278,10 @@ async function parseCommits(
12761278
if (stashes?.size) {
12771279
const allowFilteredFiles = searchFilters?.files ?? false;
12781280
const stashesOnly = searchFilters?.type === 'stash';
1281+
12791282
for (const c of parser.parse(result.stdout)) {
12801283
if (stashesOnly && !stashes?.has(c.sha)) continue;
1284+
if (tipsOnly && !c.tips) continue;
12811285

12821286
count++;
12831287
if (limit && count > limit) break;
@@ -1307,6 +1311,8 @@ async function parseCommits(
13071311
}
13081312
} else {
13091313
for (const c of parser.parse(result.stdout)) {
1314+
if (tipsOnly && !c.tips) continue;
1315+
13101316
count++;
13111317
if (limit && count > limit) break;
13121318

@@ -1322,8 +1328,10 @@ async function parseCommits(
13221328
if (stashes?.size) {
13231329
const allowFilteredFiles = searchFilters?.files ?? false;
13241330
const stashesOnly = searchFilters?.type === 'stash';
1331+
13251332
for await (const c of parser.parseAsync(resultOrStream)) {
13261333
if (stashesOnly && !stashes?.has(c.sha)) continue;
1334+
if (tipsOnly && !c.tips) continue;
13271335

13281336
count++;
13291337
if (limit && count > limit) break;
@@ -1353,6 +1361,8 @@ async function parseCommits(
13531361
}
13541362
} else {
13551363
for await (const c of parser.parseAsync(resultOrStream)) {
1364+
if (tipsOnly && !c.tips) continue;
1365+
13561366
count++;
13571367
if (limit && count > limit) break;
13581368

src/env/node/git/sub-providers/graph.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,23 +637,23 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
637637

638638
const comparisonKey = getSearchQueryComparisonKey(search);
639639
try {
640-
const parser = getShaAndDatesLogParser();
640+
const currentUser = search.query.includes('@me')
641+
? await this.provider.config.getCurrentUser(repoPath)
642+
: undefined;
643+
644+
const { args: searchArgs, files, shas, filters } = parseSearchQueryCommand(search, currentUser);
645+
646+
const tipsOnly = filters.type === 'tip';
647+
const parser = getShaAndDatesLogParser(tipsOnly);
641648

642649
const similarityThreshold = configuration.get('advanced.similarityThreshold');
643650
const args = [
644651
'log',
645-
646652
...parser.arguments,
647653
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
648654
'--use-mailmap',
649655
];
650656

651-
const currentUser = search.query.includes('@me')
652-
? await this.provider.config.getCurrentUser(repoPath)
653-
: undefined;
654-
655-
const { args: searchArgs, files, shas, filters } = parseSearchQueryCommand(search, currentUser);
656-
657657
let stashes: Map<string, GitStashCommit> | undefined;
658658
let stdin: string | undefined;
659659
let remappedIds: Map<string, string>;
@@ -736,7 +736,7 @@ export class GraphGitSubProvider implements GitGraphSubProvider {
736736

737737
count++;
738738
sha = remappedIds.get(r.sha) ?? r.sha;
739-
if (results.has(sha) || (stashesOnly && !stashes?.has(sha))) {
739+
if (results.has(sha) || (stashesOnly && !stashes?.has(sha)) || (tipsOnly && !r.tips)) {
740740
continue;
741741
}
742742

src/git/parsers/logParser.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,19 @@ export function getShaLogParser(): ShaLogParser {
9999
}
100100

101101
const shaAndDateMapping = { sha: '%H', authorDate: '%at', committerDate: '%ct' };
102+
const shaAndDateAndTipsMapping = { sha: '%H', authorDate: '%at', committerDate: '%ct', tips: '%D' };
102103

103-
type ShaAndDatesLogParser = LogParser<typeof shaAndDateMapping>;
104+
type ShaAndDatesLogParser = LogParser<typeof shaAndDateMapping & { tips?: string }>;
104105
let _shaAndDatesParser: ShaAndDatesLogParser | undefined;
106+
type ShaAndDatesAndTipsLogParser = LogParser<typeof shaAndDateAndTipsMapping>;
107+
let _shaAndDatesAndTipsParser: ShaAndDatesAndTipsLogParser | undefined;
108+
109+
export function getShaAndDatesLogParser(includeTips?: boolean): ShaAndDatesLogParser | ShaAndDatesAndTipsLogParser {
110+
if (includeTips) {
111+
_shaAndDatesAndTipsParser ??= createLogParser(shaAndDateAndTipsMapping);
112+
return _shaAndDatesAndTipsParser;
113+
}
105114

106-
export function getShaAndDatesLogParser(): ShaAndDatesLogParser {
107115
_shaAndDatesParser ??= createLogParser(shaAndDateMapping);
108116
return _shaAndDatesParser;
109117
}

src/git/search.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ export function parseSearchQuery(search: SearchQuery, validate: boolean = false)
197197
export interface SearchQueryFilters {
198198
/** Specifies whether the search results will be filtered to specific files */
199199
files: boolean;
200-
/** Specifies whether the search results will be filtered to a specific type, only `stash` is supported */
201-
type?: 'stash';
200+
/** Specifies whether the search results will be filtered to a specific type, only `stash` and `tip` are supported */
201+
type?: 'stash' | 'tip';
202202
/** Specifies whether the search results will be filtered to a specific ref or ref range */
203203
refs: boolean;
204204
}
@@ -306,6 +306,8 @@ export function parseSearchQueryCommand(search: SearchQuery, currentUser: GitUse
306306
if (value === 'stash') {
307307
filters.type = 'stash';
308308
searchArgs.add('--no-walk');
309+
} else if (value === 'tip') {
310+
filters.type = 'tip';
309311
}
310312
}
311313

src/plus/ai/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Available search operators:
350350
- 'commit:' - Search by a specific commit SHA (e.g. 'commit:4ce3a')
351351
- 'file:' - Search by file path (e.g. 'file:"package.json"', 'file:"*.ts"'); maps to \`git log -- <value>\`
352352
- 'change:' - Search by specific code changes using regular expressions (e.g. 'change:"function.*auth"', 'change:"import.*react"'); maps to \`git log -G<value>\`
353-
- 'type:' - Search by type -- only stash is currently supported (e.g. 'type:stash')
353+
- 'type:' - Search by type -- supports stash and tip (e.g. 'type:stash', 'type:tip')
354354
- 'ref:' - Search for commits reachable by a reference (branch, tag, commit) or reference range. Supports single refs (e.g. 'ref:main', 'ref:v1.0'), two-dot ranges (e.g. 'ref:main..feature' for commits in feature but not in main), three-dot ranges (e.g. 'ref:main...feature' for symmetric difference), and relative refs (e.g. 'ref:HEAD~5..HEAD'); maps to \`git log <ref>\`
355355
- 'after:' - Search for commits after a certain date or range (e.g. 'after:2023-01-01', 'after:"6 months ago"', 'after:"last Tuesday"', 'after:"noon"', 'after:"1 month 2 days ago"'); maps to \`git log --since=<value>\`
356356
- 'before:' - Search for commits before a certain date or range (e.g. 'before:2023-01-01', 'before:"6 months ago"', 'before:"yesterday"', 'before:"3PM GMT"'); maps to \`git log --until=<value>\`

src/webviews/apps/shared/components/search/search-input.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class GlSearchInput extends GlElement {
225225
}
226226
227227
.menu-button {
228-
display: block;
228+
display: flex;
229229
width: 100%;
230230
padding: 0.1rem 0.6rem 0 0.6rem;
231231
line-height: 2.2rem;
@@ -234,6 +234,12 @@ export class GlSearchInput extends GlElement {
234234
border-radius: 3px;
235235
}
236236
237+
.menu-button small {
238+
margin-left: auto;
239+
padding-left: 1.5rem;
240+
opacity: 0.8;
241+
}
242+
237243
.menu-button:hover {
238244
color: var(--vscode-menu-selectionForeground);
239245
background-color: var(--vscode-menu-selectionBackground);
@@ -834,7 +840,7 @@ export class GlSearchInput extends GlElement {
834840
>`;
835841
case 'type:':
836842
return html`<span
837-
>Type: use <code>stash</code> to search only stashes, e.g. <code>type:stash</code></span
843+
>Type: use <code>is:stash</code> for stashes or <code>is:tip</code> for branch & tag tips</span
838844
>`;
839845
case 'file:':
840846
return html`<span
@@ -907,9 +913,15 @@ export class GlSearchInput extends GlElement {
907913
Ref <small>ref: or ^:</small>
908914
</button>
909915
</menu-item>
916+
<menu-divider></menu-divider>
917+
<menu-item role="none">
918+
<button class="menu-button" type="button" @click="${() => this.handleInsertToken('is:stash')}">
919+
Stashes <small>is:stash or type:stash</small>
920+
</button>
921+
</menu-item>
910922
<menu-item role="none">
911-
<button class="menu-button" type="button" @click="${() => this.handleInsertToken('type:stash')}">
912-
Type <small>type:stash or is:stash</small>
923+
<button class="menu-button" type="button" @click="${() => this.handleInsertToken('is:tip')}">
924+
Branch & Tag Tips <small>is:tip or type:tip</small>
913925
</button>
914926
</menu-item>
915927
<menu-divider></menu-divider>

0 commit comments

Comments
 (0)