Skip to content

Commit

Permalink
Merge branch 'main' into fix-json-schema-parse-uri
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored Jan 7, 2025
2 parents 4cafefb + 971869e commit a3671f2
Show file tree
Hide file tree
Showing 97 changed files with 2,168 additions and 705 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/monaco-editor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
path: ${{ steps.npmCacheDirPath.outputs.dir }}
key: ${{ runner.os }}-npmCacheDir-${{ steps.nodeModulesCacheKey.outputs.value }}
restore-keys: ${{ runner.os }}-npmCacheDir-
- name: Install libkrb5-dev
- name: Install system dependencies
if: ${{ steps.cacheNodeModules.outputs.cache-hit != 'true' }}
run: |
sudo apt update
sudo apt install -y libkrb5-dev
sudo apt install -y libxkbfile-dev pkg-config libkrb5-dev libxss1
- name: Execute npm
if: ${{ steps.cacheNodeModules.outputs.cache-hit != 'true' }}
env:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/notebooks/api.github-issues
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"kind": 2,
"language": "github-issues",
"value": "$REPO=repo:microsoft/vscode\n$MILESTONE=milestone:\"November 2024\""
"value": "$REPO=repo:microsoft/vscode\n$MILESTONE=milestone:\"January 2025\""
},
{
"kind": 1,
Expand Down
19 changes: 8 additions & 11 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,6 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.viewAllChanges",
"title": "%command.viewAllChanges%",
"icon": "$(diff-multiple)",
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.copyCommitId",
"title": "%command.timelineCopyCommitId%",
Expand Down Expand Up @@ -1444,10 +1437,6 @@
"command": "git.viewCommit",
"when": "false"
},
{
"command": "git.viewAllChanges",
"when": "false"
},
{
"command": "git.stageFile",
"when": "false"
Expand Down Expand Up @@ -3229,6 +3218,14 @@
"type": "string",
"default": "${authorName} (${authorDateAgo})",
"markdownDescription": "%config.blameStatusBarItem.template%"
},
"git.commitShortHashLength": {
"type": "number",
"default": 7,
"minimum": 7,
"maximum": 40,
"markdownDescription": "%config.commitShortHashLength%",
"scope": "resource"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"command.viewChanges": "View Changes",
"command.viewStagedChanges": "View Staged Changes",
"command.viewUntrackedChanges": "View Untracked Changes",
"command.viewAllChanges": "View All Changes",
"command.viewCommit": "View Commit",
"command.api.getRepositories": "Get Repositories",
"command.api.getRepositoryState": "Get Repository State",
Expand Down Expand Up @@ -278,9 +277,10 @@
"config.publishBeforeContinueOn.prompt": "Prompt to publish unpublished Git state when using Continue Working On from a Git repository",
"config.similarityThreshold": "Controls the threshold of the similarity index (the amount of additions/deletions compared to the file's size) for changes in a pair of added/deleted files to be considered a rename. **Note:** Requires Git version `2.18.0` or later.",
"config.blameEditorDecoration.enabled": "Controls whether to show blame information in the editor using editor decorations.",
"config.blameEditorDecoration.template": "Template for the blame information editor decoration. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First 8 characters of the commit hash\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.blameEditorDecoration.template": "Template for the blame information editor decoration. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First N characters of the commit hash according to `#git.commitShortHashLength#`\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.blameStatusBarItem.enabled": "Controls whether to show blame information in the status bar.",
"config.blameStatusBarItem.template": "Template for the blame information status bar item. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First 8 characters of the commit hash\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.blameStatusBarItem.template": "Template for the blame information status bar item. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First N characters of the commit hash according to `#git.commitShortHashLength#`\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.commitShortHashLength": "Controls the length of the commit short hash.",
"submenu.explorer": "Git",
"submenu.commit": "Commit",
"submenu.commit.amend": "Amend",
Expand Down
30 changes: 19 additions & 11 deletions extensions/git/src/blame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { DecorationOptions, l10n, Position, Range, TextEditor, TextEditorChange, TextEditorDecorationType, TextEditorChangeKind, ThemeColor, Uri, window, workspace, EventEmitter, ConfigurationChangeEvent, StatusBarItem, StatusBarAlignment, Command, MarkdownString, languages, HoverProvider, CancellationToken, Hover, TextDocument } from 'vscode';
import { Model } from './model';
import { dispose, fromNow, IDisposable } from './util';
import { dispose, fromNow, getCommitShortHash, IDisposable } from './util';
import { Repository } from './repository';
import { throttle } from './decorators';
import { BlameInformation, Commit } from './git';
Expand Down Expand Up @@ -186,14 +186,14 @@ export class GitBlameController {
this._onDidChangeConfiguration();
}

formatBlameInformationMessage(template: string, blameInformation: BlameInformation): string {
formatBlameInformationMessage(documentUri: Uri, template: string, blameInformation: BlameInformation): string {
const subject = blameInformation.subject && blameInformation.subject.length > this._subjectMaxLength
? `${blameInformation.subject.substring(0, this._subjectMaxLength)}\u2026`
: blameInformation.subject;

const templateTokens = {
hash: blameInformation.hash,
hashShort: blameInformation.hash.substring(0, 8),
hashShort: getCommitShortHash(documentUri, blameInformation.hash),
subject: emojify(subject ?? ''),
authorName: blameInformation.authorName ?? '',
authorEmail: blameInformation.authorEmail ?? '',
Expand Down Expand Up @@ -227,7 +227,12 @@ export class GitBlameController {
markdownString.supportThemeIcons = true;

if (blameInformationOrCommit.authorName) {
markdownString.appendMarkdown(`$(account) **${blameInformationOrCommit.authorName}**`);
if (blameInformationOrCommit.authorEmail) {
const emailTitle = l10n.t('Email');
markdownString.appendMarkdown(`$(account) [**${blameInformationOrCommit.authorName}**](mailto:${blameInformationOrCommit.authorEmail} "${emailTitle} ${blameInformationOrCommit.authorName}")`);
} else {
markdownString.appendMarkdown(`$(account) **${blameInformationOrCommit.authorName}**`);
}

if (blameInformationOrCommit.authorDate) {
const dateString = new Date(blameInformationOrCommit.authorDate).toLocaleString(undefined, { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' });
Expand Down Expand Up @@ -260,9 +265,9 @@ export class GitBlameController {
markdownString.appendMarkdown(`\n\n---\n\n`);
}

markdownString.appendMarkdown(`[\`$(git-commit) ${blameInformationOrCommit.hash.substring(0, 8)} \`](command:git.blameStatusBarItem.viewCommit?${encodeURIComponent(JSON.stringify([documentUri, blameInformationOrCommit.hash]))} "${l10n.t('View Commit')}")`);
markdownString.appendMarkdown(`[\`$(git-commit) ${getCommitShortHash(documentUri, blameInformationOrCommit.hash)} \`](command:git.viewCommit?${encodeURIComponent(JSON.stringify([documentUri, blameInformationOrCommit.hash]))} "${l10n.t('View Commit')}")`);
markdownString.appendMarkdown(' ');
markdownString.appendMarkdown(`[$(copy)](command:git.blameStatusBarItem.copyContent?${encodeURIComponent(JSON.stringify(blameInformationOrCommit.hash))} "${l10n.t('Copy Commit Hash')}")`);
markdownString.appendMarkdown(`[$(copy)](command:git.copyContentToClipboard?${encodeURIComponent(JSON.stringify(blameInformationOrCommit.hash))} "${l10n.t('Copy Commit Hash')}")`);
markdownString.appendMarkdown('  |  ');
markdownString.appendMarkdown(`[$(gear)](command:workbench.action.openSettings?%5B%22git.blame%22%5D "${l10n.t('Open Settings')}")`);

Expand Down Expand Up @@ -571,7 +576,9 @@ class GitBlameEditorDecoration implements HoverProvider {
}

private _onDidChangeConfiguration(e?: ConfigurationChangeEvent): void {
if (e && !e.affectsConfiguration('git.blame.editorDecoration.template')) {
if (e &&
!e.affectsConfiguration('git.commitShortHashLength') &&
!e.affectsConfiguration('git.blame.editorDecoration.template')) {
return;
}

Expand Down Expand Up @@ -610,7 +617,7 @@ class GitBlameEditorDecoration implements HoverProvider {

const decorations = blameInformation.map(blame => {
const contentText = typeof blame.blameInformation !== 'string'
? this._controller.formatBlameInformationMessage(template, blame.blameInformation)
? this._controller.formatBlameInformationMessage(textEditor.document.uri, template, blame.blameInformation)
: blame.blameInformation;

return this._createDecoration(blame.lineNumber, contentText);
Expand Down Expand Up @@ -663,7 +670,8 @@ class GitBlameStatusBarItem {
}

private _onDidChangeConfiguration(e: ConfigurationChangeEvent): void {
if (!e.affectsConfiguration('git.blame.statusBarItem.template')) {
if (!e.affectsConfiguration('git.commitShortHashLength') &&
!e.affectsConfiguration('git.blame.statusBarItem.template')) {
return;
}

Expand All @@ -690,11 +698,11 @@ class GitBlameStatusBarItem {
const config = workspace.getConfiguration('git');
const template = config.get<string>('blame.statusBarItem.template', '${authorName} (${authorDateAgo})');

this._statusBarItem.text = `$(git-commit) ${this._controller.formatBlameInformationMessage(template, blameInformation[0].blameInformation)}`;
this._statusBarItem.text = `$(git-commit) ${this._controller.formatBlameInformationMessage(window.activeTextEditor.document.uri, template, blameInformation[0].blameInformation)}`;
this._statusBarItem.tooltip = this._controller.getBlameInformationHover(window.activeTextEditor.document.uri, blameInformation[0].blameInformation);
this._statusBarItem.command = {
title: l10n.t('View Commit'),
command: 'git.blameStatusBarItem.viewCommit',
command: 'git.viewCommit',
arguments: [window.activeTextEditor.document.uri, blameInformation[0].blameInformation.hash]
} satisfies Command;
}
Expand Down
68 changes: 7 additions & 61 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Model } from './model';
import { GitResourceGroup, Repository, Resource, ResourceGroupType } from './repository';
import { DiffEditorSelectionHunkToolbarContext, applyLineChanges, getModifiedRange, getWorkingTreeAndIndexDiffInformation, getWorkingTreeDiffInformation, intersectDiffWithRange, invertLineChange, toLineChanges, toLineRanges } from './staging';
import { fromGitUri, toGitUri, isGitUri, toMergeUris, toMultiFileDiffEditorUris } from './uri';
import { dispose, grep, isDefined, isDescendant, pathEquals, relativePath, truncate } from './util';
import { dispose, getCommitShortHash, grep, isDefined, isDescendant, pathEquals, relativePath, truncate } from './util';
import { GitTimelineItem } from './timelineProvider';
import { ApiRepository } from './api/api1';
import { getRemoteSourceActions, pickRemoteSource } from './remoteSource';
Expand Down Expand Up @@ -4271,61 +4271,6 @@ export class CommandCenter {
});
}

@command('git.viewCommit', { repository: true })
async viewCommit(repository: Repository, historyItem1: SourceControlHistoryItem, historyItem2?: SourceControlHistoryItem): Promise<void> {
if (!repository || !historyItem1) {
return;
}

if (historyItem2) {
const mergeBase = await repository.getMergeBase(historyItem1.id, historyItem2.id);
if (!mergeBase || (mergeBase !== historyItem1.id && mergeBase !== historyItem2.id)) {
return;
}
}

let title: string | undefined;
let historyItemParentId: string | undefined;

// If historyItem2 is not provided, we are viewing a single commit. If historyItem2 is
// provided, we are viewing a range and we have to include both start and end commits.
// TODO@lszomoru - handle the case when historyItem2 is the first commit in the repository
if (!historyItem2) {
const commit = await repository.getCommit(historyItem1.id);
title = `${historyItem1.id.substring(0, 8)} - ${truncate(commit.message)}`;
historyItemParentId = historyItem1.parentIds.length > 0 ? historyItem1.parentIds[0] : `${historyItem1.id}^`;
} else {
title = l10n.t('All Changes ({0} ↔ {1})', historyItem2.id.substring(0, 8), historyItem1.id.substring(0, 8));
historyItemParentId = historyItem2.parentIds.length > 0 ? historyItem2.parentIds[0] : `${historyItem2.id}^`;
}

const multiDiffSourceUri = Uri.from({ scheme: 'scm-history-item', path: `${repository.root}/${historyItemParentId}..${historyItem1.id}` });

await this._viewChanges(repository, historyItem1.id, historyItemParentId, multiDiffSourceUri, title);
}

@command('git.viewAllChanges', { repository: true })
async viewAllChanges(repository: Repository, historyItem: SourceControlHistoryItem): Promise<void> {
if (!repository || !historyItem) {
return;
}

const modifiedShortRef = historyItem.id.substring(0, 8);
const originalShortRef = historyItem.parentIds.length > 0 ? historyItem.parentIds[0].substring(0, 8) : `${modifiedShortRef}^`;
const title = l10n.t('All Changes ({0} ↔ {1})', originalShortRef, modifiedShortRef);

const multiDiffSourceUri = toGitUri(Uri.file(repository.root), historyItem.id, { scheme: 'git-changes' });

await this._viewChanges(repository, modifiedShortRef, originalShortRef, multiDiffSourceUri, title);
}

async _viewChanges(repository: Repository, historyItemId: string, historyItemParentId: string, multiDiffSourceUri: Uri, title: string): Promise<void> {
const changes = await repository.diffBetween(historyItemParentId, historyItemId);
const resources = changes.map(c => toMultiFileDiffEditorUris(c, historyItemParentId, historyItemId));

await commands.executeCommand('_workbench.openMultiDiffEditor', { multiDiffSourceUri, title, resources });
}

@command('git.copyCommitId', { repository: true })
async copyCommitId(repository: Repository, historyItem: SourceControlHistoryItem): Promise<void> {
if (!repository || !historyItem) {
Expand All @@ -4344,14 +4289,15 @@ export class CommandCenter {
env.clipboard.writeText(historyItem.message);
}

@command('git.blameStatusBarItem.viewCommit', { repository: true })
async viewStatusBarCommit(repository: Repository, historyItemId: string): Promise<void> {
@command('git.viewCommit', { repository: true })
async viewCommit(repository: Repository, historyItemId: string): Promise<void> {
if (!repository || !historyItemId) {
return;
}

const rootUri = Uri.file(repository.root);
const commit = await repository.getCommit(historyItemId);
const title = `${historyItemId.substring(0, 8)} - ${truncate(commit.message)}`;
const title = `${getCommitShortHash(rootUri, historyItemId)} - ${truncate(commit.message)}`;
const historyItemParentId = commit.parents.length > 0 ? commit.parents[0] : `${historyItemId}^`;

const multiDiffSourceUri = Uri.from({ scheme: 'scm-history-item', path: `${repository.root}/${historyItemParentId}..${historyItemId}` });
Expand All @@ -4362,8 +4308,8 @@ export class CommandCenter {
await commands.executeCommand('_workbench.openMultiDiffEditor', { multiDiffSourceUri, title, resources });
}

@command('git.blameStatusBarItem.copyContent')
async blameStatusBarCopyContent(content: string): Promise<void> {
@command('git.copyContentToClipboard')
async copyContentToClipboard(content: string): Promise<void> {
if (typeof content !== 'string') {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface LogFileOptions {
/** Optional. Specifies whether to start retrieving log entries in reverse order. */
readonly reverse?: boolean;
readonly sortByAuthorDate?: boolean;
readonly shortStats?: boolean;
}

function parseVersion(raw: string): string {
Expand Down Expand Up @@ -1290,6 +1291,10 @@ export class Repository {
}
}

if (options?.shortStats) {
args.push('--shortstat');
}

if (options?.sortByAuthorDate) {
args.push('--author-date-order');
}
Expand Down
Loading

0 comments on commit a3671f2

Please sign in to comment.