Skip to content

Commit

Permalink
RevisionDiff: Stage/Unstage selected lines
Browse files Browse the repository at this point in the history
Move handling of stage/unstage/reset line patching from FormCommit to FileViewer.
Instead of FormCommit adding menu items to FileViewer, handle
the actions directly in FileViewer, including the hotkey handling.
Also hotkey for cherry-pick and reset line patches.
This also aligns the stage/reset menu items to other forms.

Apply the line patching also to RevDiff, supporting line patches for
worktree/index properly, including hotkey handling.
When manipulating a diff with an artificial commit, refresh the diff
after patching.

Some code cleanup, like using ViewChangesAsync consistently for diffs/patches

FormCommit; Use common method for head revisions
Set parents for artificial revisions
  • Loading branch information
gerhardol committed Jan 10, 2021
1 parent 892ce08 commit 37ac053
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 462 deletions.
2 changes: 1 addition & 1 deletion GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,7 @@ public IReadOnlyList<GitItemStatus> GetDiffFilesWithSubmodulesStatus(ObjectId fi
/// <param name="secondId">to revision</param>
/// <param name="parentToSecond">The parent for the second revision</param>
/// <remarks>Git revisions are required to determine if <see cref="StagedStatus"/> allows stage/unstage.</remarks>
private static StagedStatus GetStagedStatus([CanBeNull] ObjectId firstId, [CanBeNull] ObjectId secondId, [CanBeNull] ObjectId parentToSecond)
public static StagedStatus GetStagedStatus([CanBeNull] ObjectId firstId, [CanBeNull] ObjectId secondId, [CanBeNull] ObjectId parentToSecond)
{
StagedStatus staged;
if (firstId == ObjectId.IndexId && secondId == ObjectId.WorkTreeId)
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/FormCommit.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

306 changes: 72 additions & 234 deletions GitUI/CommandsDialogs/FormCommit.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions GitUI/CommandsDialogs/RevisionDiffControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion GitUI/CommandsDialogs/RevisionDiffControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public RevisionDiffControl()
_revisionDiffContextMenuController = new FileStatusListContextMenuController();
DiffText.TopScrollReached += FileViewer_TopScrollReached;
DiffText.BottomScrollReached += FileViewer_BottomScrollReached;
DiffText.LinePatchingBlocksUntilReload = true;
}

private void FileViewer_TopScrollReached(object sender, EventArgs e)
Expand Down Expand Up @@ -335,7 +336,7 @@ private ContextMenuSelectionInfo GetSelectionInfo()
bool isAnyTracked = selectedItems.Any(item => item.Item.IsTracked);
bool isAnyIndex = selectedItems.Any(item => item.Item.Staged == StagedStatus.Index);
bool isAnyWorkTree = selectedItems.Any(item => item.Item.Staged == StagedStatus.WorkTree);
bool supportPatches = selectedGitItemCount == 1 && DiffText.HasAnyPatches();
bool supportPatches = selectedGitItemCount == 1 && DiffText.SupportLinePatching;
bool isDeleted = selectedItems.Any(item => item.Item.IsDeleted);
bool isAnySubmodule = selectedItems.Any(item => item.Item.IsSubmodule);
(bool allFilesExist, bool allDirectoriesExist, bool allFilesOrUntrackedDirectoriesExist) = FileOrUntrackedDirExists(selectedItems, _fullPathResolver);
Expand Down Expand Up @@ -479,6 +480,11 @@ private void DiffText_ExtraDiffArgumentsChanged(object sender, EventArgs e)
}).FileAndForget();
}

private void DiffText_PatchApplied(object sender, EventArgs e)
{
RefreshArtificial();
}

private void diffShowInFileTreeToolStripMenuItem_Click(object sender, EventArgs e)
{
// switch to view (and fills the first level of file tree data model if not already done)
Expand Down
1 change: 1 addition & 0 deletions GitUI/CommandsDialogs/RevisionDiffController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public bool ShouldShowMenuCherryPick(ContextMenuSelectionInfo selectionInfo)
&& !selectionInfo.IsBareRepository
&& selectionInfo.AllFilesExist
&& selectionInfo.SupportPatches
&& !(selectionInfo.IsAnyItemWorkTree || selectionInfo.IsAnyItemIndex)
&& !(selectionInfo.SelectedRevision?.IsArtificial ?? false);
}

Expand Down
58 changes: 35 additions & 23 deletions GitUI/Editor/FileViewer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 37ac053

Please sign in to comment.