Skip to content

Commit

Permalink
Adds avatar context menu on the graph
Browse files Browse the repository at this point in the history
Adds graph context menus for virtual GitHub repos
Adds comparison commands to the graph
Fixes `when` clause contitions for some commands
  • Loading branch information
eamodio committed Oct 6, 2022
1 parent 5f123e3 commit a9c0288
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 37 deletions.
108 changes: 98 additions & 10 deletions package.json
Expand Up @@ -6442,6 +6442,40 @@
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.compareAncestryWithWorking",
"title": "Compare Ancestry with Working Tree",
"category": "GitLens"
},
{
"command": "gitlens.graph.compareWithHead",
"title": "Compare with HEAD",
"category": "GitLens",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.graph.compareWithUpstream",
"title": "Compare with Upstream",
"category": "GitLens"
},
{
"command": "gitlens.graph.compareWithWorking",
"title": "Compare with Working Tree",
"category": "GitLens",
"icon": "$(gitlens-compare-ref-working)"
},
{
"command": "gitlens.graph.addAuthor",
"title": "Add as Co-author",
"category": "GitLens",
"icon": "$(person-add)"
},
{
"command": "gitlens.graph.copy",
"title": "Copy",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.graph.columnAuthorOn",
"title": "Show Author",
Expand Down Expand Up @@ -7120,7 +7154,7 @@
},
{
"command": "gitlens.addAuthors",
"when": "gitlens:enabled"
"when": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders"
},
{
"command": "gitlens.connectRemoteProvider",
Expand Down Expand Up @@ -8394,6 +8428,30 @@
"command": "gitlens.graph.copyRemotePullRequestUrl",
"when": "false"
},
{
"command": "gitlens.graph.compareAncestryWithWorking",
"when": "false"
},
{
"command": "gitlens.graph.compareWithHead",
"when": "false"
},
{
"command": "gitlens.graph.compareWithUpstream",
"when": "false"
},
{
"command": "gitlens.graph.compareWithWorking",
"when": "false"
},
{
"command": "gitlens.graph.addAuthor",
"when": "false"
},
{
"command": "gitlens.graph.copy",
"when": "false"
},
{
"command": "gitlens.graph.columnAuthorOn",
"when": "false"
Expand Down Expand Up @@ -9027,7 +9085,7 @@
},
{
"command": "gitlens.views.addAuthors",
"when": "view =~ /^gitlens\\.views\\.contributors/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view =~ /^gitlens\\.views\\.contributors/",
"group": "navigation@10"
},
{
Expand Down Expand Up @@ -9739,7 +9797,7 @@
},
{
"command": "gitlens.views.createWorktree",
"when": "!gitlens:readonly && viewItem =~ /gitlens:branch\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b/",
"group": "1_gitlens_actions_@9"
},
{
Expand Down Expand Up @@ -9810,12 +9868,12 @@
},
{
"command": "gitlens.views.addAuthors",
"when": "viewItem =~ /gitlens:contributors\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:contributors\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.addAuthors",
"when": "viewItem =~ /gitlens:contributors\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:contributors\\b/",
"group": "1_gitlens_actions@1"
},
{
Expand All @@ -9825,7 +9883,7 @@
},
{
"command": "gitlens.views.addAuthor",
"when": "viewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",
"group": "inline@2"
},
{
Expand All @@ -9840,7 +9898,7 @@
},
{
"command": "gitlens.views.addAuthor",
"when": "viewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",
"group": "1_gitlens_actions@2"
},
{
Expand Down Expand Up @@ -10748,12 +10806,12 @@
},
{
"command": "gitlens.views.createWorktree",
"when": "!gitlens:readonly && viewItem =~ /gitlens:worktrees\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:worktrees\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.createWorktree",
"when": "!gitlens:readonly && viewItem =~ /gitlens:worktrees\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:worktrees\\b/",
"group": "1_gitlens_actions@1"
},
{
Expand Down Expand Up @@ -10907,7 +10965,7 @@
},
{
"command": "gitlens.graph.createWorktree",
"when": "!gitlens:readonly && webviewItem =~ /gitlens:branch\\b/",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b/",
"group": "1_gitlens_actions_@9"
},
{
Expand Down Expand Up @@ -11017,6 +11075,36 @@
"when": "webviewItem =~ /gitlens:graph:pullrequest\\b/",
"group": "7_gitlens_cutcopypaste@1"
},
{
"command": "gitlens.graph.compareWithUpstream",
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)/",
"group": "4_gitlens_compare@1"
},
{
"command": "gitlens.graph.compareWithHead",
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:(branch\\b(?!.*?\\b\\+current\\b)|commit\\b|stash\\b|tag\\b)/",
"group": "4_gitlens_compare@2"
},
{
"command": "gitlens.graph.compareWithWorking",
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/",
"group": "4_gitlens_compare@3"
},
{
"command": "gitlens.graph.compareAncestryWithWorking",
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/",
"group": "4_gitlens_compare@4"
},
{
"command": "gitlens.graph.addAuthor",
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:contributor\\b(?!.*?\\b\\+current\\b)/",
"group": "1_gitlens_actions@2"
},
{
"command": "gitlens.graph.copy",
"when": "webviewItem =~ /gitlens:contributor\\b/",
"group": "7_gitlens_cutcopypaste@1"
},
{
"command": "gitlens.graph.columnAuthorOn",
"when": "webviewItem =~ /gitlens:graph:columns\\b/ && webviewItemValue =~ /\\bauthor\\b/",
Expand Down
34 changes: 21 additions & 13 deletions src/env/node/git/localGitProvider.ts
Expand Up @@ -1634,16 +1634,19 @@ export class LocalGitProvider implements GitProvider, Disposable {
const defaultPageLimit = configuration.get('graph.pageItemLimit') ?? 1000;
const ordering = configuration.get('graph.commitOrdering', undefined, 'date');

const [refResult, stashResult, branchesResult, remotesResult] = await Promise.allSettled([
const [refResult, stashResult, branchesResult, remotesResult, currentUserResult] = await Promise.allSettled([
this.git.log2(repoPath, undefined, ...refParser.arguments, '-n1', options?.ref ?? 'HEAD'),
this.getStash(repoPath),
this.getBranches(repoPath),
this.getRemotes(repoPath),
this.getCurrentUser(repoPath),
]);

const branches = getSettledValue(branchesResult)?.values;
const branchMap = branches != null ? new Map(branches.map(r => [r.name, r])) : new Map<string, GitBranch>();

const currentUser = getSettledValue(currentUserResult);

const remotes = getSettledValue(remotesResult);
const remoteMap =
remotes != null
Expand Down Expand Up @@ -1747,8 +1750,8 @@ export class LocalGitProvider implements GitProvider, Disposable {

let branch: GitBranch | undefined;
let branchName: string;
let current = false;
let headCommit = false;
let head = false;
let isCurrentUser = false;
let refHeads: GitGraphRowHead[];
let refRemoteHeads: GitGraphRowRemoteHead[];
let refTags: GitGraphRowTag[];
Expand Down Expand Up @@ -1776,7 +1779,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
refRemoteHeads = [];
refTags = [];
contexts = undefined;
headCommit = false;
head = false;

if (commit.tips) {
for (let tip of commit.tips.split(', ')) {
Expand All @@ -1803,9 +1806,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
continue;
}

current = tip.startsWith('HEAD');
if (current) {
headCommit = true;
head = tip.startsWith('HEAD');
if (head) {
reachableFromHEAD.add(commit.sha);

if (tip !== 'HEAD') {
Expand Down Expand Up @@ -1854,9 +1856,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
refHeads.push({
id: branchId,
name: tip,
isCurrentHead: current,
isCurrentHead: head,
context: serializeWebviewItemContext<GraphItemRefContext>({
webviewItem: `gitlens:branch${current ? '+current' : ''}${
webviewItem: `gitlens:branch${head ? '+current' : ''}${
branch?.upstream != null ? '+tracking' : ''
}`,
webviewItemValue: {
Expand Down Expand Up @@ -1898,6 +1900,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}

isCurrentUser = isUserMatch(currentUser, commit.author, commit.authorEmail);

contexts = {};
if (stashCommit != null) {
contexts.row = serializeWebviewItemContext<GraphItemRefContext>({
Expand All @@ -1913,7 +1917,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
});
} else {
contexts.row = serializeWebviewItemContext<GraphItemRefContext>({
webviewItem: `gitlens:commit${headCommit ? '+HEAD' : ''}${
webviewItem: `gitlens:commit${head ? '+HEAD' : ''}${
reachableFromHEAD.has(commit.sha) ? '+current' : ''
}`,
webviewItemValue: {
Expand All @@ -1924,19 +1928,23 @@ export class LocalGitProvider implements GitProvider, Disposable {
}),
},
});

contexts.avatar = serializeWebviewItemContext<GraphItemContext>({
webviewItem: 'gitlens:avatar',
webviewItem: `gitlens:contributor${isCurrentUser ? '+current' : ''}`,
webviewItemValue: {
type: 'avatar',
type: 'contributor',
repoPath: repoPath,
name: commit.author,
email: commit.authorEmail,
current: isCurrentUser,
},
});
}

rows.push({
sha: commit.sha,
parents: parents,
author: commit.author,
author: isCurrentUser ? 'You' : commit.author,
email: commit.authorEmail,
date: Number(ordering === 'author-date' ? commit.authorDate : commit.committerDate) * 1000,
message: emojify(commit.message.trim()),
Expand Down

0 comments on commit a9c0288

Please sign in to comment.