Git - remove diffCommand proposal (#242675)

This commit is contained in:
Ladislau Szomoru
2025-03-05 10:44:12 +00:00
committed by GitHub
parent 6dc103659b
commit d234a62e39
4 changed files with 17 additions and 21 deletions

View File

@@ -5,14 +5,14 @@
import * as os from 'os';
import * as path from 'path';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind, TextDocument, LogOutputChannel, l10n, Memento, UIKind, QuickInputButton, ThemeIcon, SourceControlHistoryItem, SourceControl, InputBoxValidationMessage, Tab, TabInputNotebook, QuickInputButtonLocation, languages } from 'vscode';
import { Command, commands, Disposable, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind, TextDocument, LogOutputChannel, l10n, Memento, UIKind, QuickInputButton, ThemeIcon, SourceControlHistoryItem, SourceControl, InputBoxValidationMessage, Tab, TabInputNotebook, QuickInputButtonLocation, languages } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator';
import { ForcePushMode, GitErrorCodes, Ref, RefType, Status, CommitOptions, RemoteSourcePublisher, Remote } from './api/git';
import { Git, Stash } from './git';
import { Model } from './model';
import { GitResourceGroup, Repository, Resource, ResourceGroupType } from './repository';
import { DiffEditorSelectionHunkToolbarContext, applyLineChanges, getIndexDiffInformation, getModifiedRange, getWorkingTreeDiffInformation, intersectDiffWithRange, invertLineChange, toLineChanges, toLineRanges } from './staging';
import { DiffEditorSelectionHunkToolbarContext, LineChange, applyLineChanges, getIndexDiffInformation, getModifiedRange, getWorkingTreeDiffInformation, intersectDiffWithRange, invertLineChange, toLineChanges, toLineRanges } from './staging';
import { fromGitUri, toGitUri, isGitUri, toMergeUris, toMultiFileDiffEditorUris } from './uri';
import { DiagnosticSeverityConfig, dispose, getCommitShortHash, grep, isDefined, isDescendant, isLinuxSnap, isRemote, isWindows, pathEquals, relativePath, toDiagnosticSeverity, truncate } from './util';
import { GitTimelineItem } from './timelineProvider';
@@ -275,7 +275,6 @@ class StashItem implements QuickPickItem {
interface ScmCommandOptions {
repository?: boolean;
diff?: boolean;
}
interface ScmCommand {
@@ -712,12 +711,7 @@ export class CommandCenter {
) {
this.disposables = Commands.map(({ commandId, key, method, options }) => {
const command = this.createCommand(commandId, key, method, options);
if (options.diff) {
return commands.registerDiffInformationCommand(commandId, command);
} else {
return commands.registerCommand(commandId, command);
}
return commands.registerCommand(commandId, command);
});
this.disposables.push(workspace.registerTextDocumentContentProvider('git-output', this.commandErrors));
@@ -1643,8 +1637,8 @@ export class CommandCenter {
await this.runByRepository(modifiedUri, async (repository, resource) => await repository.stage(resource, result));
}
@command('git.stageSelectedRanges', { diff: true })
async stageSelectedChanges(changes: LineChange[]): Promise<void> {
@command('git.stageSelectedRanges')
async stageSelectedChanges(): Promise<void> {
const textEditor = window.activeTextEditor;
if (!textEditor) {
@@ -1658,7 +1652,6 @@ export class CommandCenter {
const workingTreeLineChanges = toLineChanges(workingTreeDiffInformation);
this.logger.trace(`[CommandCenter][stageSelectedChanges] changes: ${JSON.stringify(changes)}`);
this.logger.trace(`[CommandCenter][stageSelectedChanges] diffInformation: ${JSON.stringify(workingTreeDiffInformation)}`);
this.logger.trace(`[CommandCenter][stageSelectedChanges] diffInformation changes: ${JSON.stringify(workingTreeLineChanges)}`);
@@ -1838,8 +1831,8 @@ export class CommandCenter {
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
}
@command('git.revertSelectedRanges', { diff: true })
async revertSelectedRanges(changes: LineChange[]): Promise<void> {
@command('git.revertSelectedRanges')
async revertSelectedRanges(): Promise<void> {
const textEditor = window.activeTextEditor;
if (!textEditor) {
@@ -1853,7 +1846,6 @@ export class CommandCenter {
const workingTreeLineChanges = toLineChanges(workingTreeDiffInformation);
this.logger.trace(`[CommandCenter][revertSelectedRanges] changes: ${JSON.stringify(changes)}`);
this.logger.trace(`[CommandCenter][revertSelectedRanges] diffInformation: ${JSON.stringify(workingTreeDiffInformation)}`);
this.logger.trace(`[CommandCenter][revertSelectedRanges] diffInformation changes: ${JSON.stringify(workingTreeLineChanges)}`);
@@ -1928,8 +1920,8 @@ export class CommandCenter {
await repository.revert([]);
}
@command('git.unstageSelectedRanges', { diff: true })
async unstageSelectedRanges(changes: LineChange[]): Promise<void> {
@command('git.unstageSelectedRanges')
async unstageSelectedRanges(): Promise<void> {
const textEditor = window.activeTextEditor;
if (!textEditor) {
@@ -1967,7 +1959,6 @@ export class CommandCenter {
const indexLineChanges = toLineChanges(indexDiffInformation);
this.logger.trace(`[CommandCenter][unstageSelectedRanges] changes: ${JSON.stringify(changes)}`);
this.logger.trace(`[CommandCenter][unstageSelectedRanges] diffInformation: ${JSON.stringify(indexDiffInformation)}`);
this.logger.trace(`[CommandCenter][unstageSelectedRanges] diffInformation changes: ${JSON.stringify(indexLineChanges)}`);

View File

@@ -3,9 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TextDocument, Range, LineChange, Selection, Uri, TextEditor, TextEditorDiffInformation } from 'vscode';
import { TextDocument, Range, Selection, Uri, TextEditor, TextEditorDiffInformation } from 'vscode';
import { fromGitUri, isGitUri } from './uri';
export interface LineChange {
readonly originalStartLineNumber: number;
readonly originalEndLineNumber: number;
readonly modifiedStartLineNumber: number;
readonly modifiedEndLineNumber: number;
}
export function applyLineChanges(original: TextDocument, modified: TextDocument, diffs: LineChange[]): string {
const result: string[] = [];
let currentLine = 0;