Skip to content

[Enhancement] Add new graph-highlighting option "Selected Commits (only first-parent)" - #2646

Merged
love-linger merged 5 commits into
sourcegit-scm:developfrom
goran-w:improve_graph_highlighting
Aug 24, 2026
Merged

[Enhancement] Add new graph-highlighting option "Selected Commits (only first-parent)"#2646
love-linger merged 5 commits into
sourcegit-scm:developfrom
goran-w:improve_graph_highlighting

Conversation

@goran-w

@goran-w goran-w commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

This PR does some refactoring of the graph-highlighting code and adds a new highlighting-option variant "Selected Commits (only first-parent)".

The new highlighting-option is similar to the existing highlighting-option "Selected Commits Only", but restricted to only ever highlighting the first-parent when going backwards in history from the selected commit(s). This feature was first discussed in comments on a related issue here.

I find it very helpful to restrict the highlighting to first-parent, while still drawing the other parents. I've implemented it in the easiest way I could find, which was to only apply it to "selected commits" in a new option variant. (It would be possible, but a bit more involved, to instead implement it as a separate "perpendicular" option that could be applied to the "All" and "Current branch" variants as well...)

NOTE: This new highlighting-option is somewhat related to the Git-option --first-parent (which is applied by SourceGit's show-flag "First-parent only"), but it's not the same! The new option only restricts the highlighting of non-first-parents, while the existing show-flag hides them entirely. (Also, the option and flag can be used simultaneously without issues.)

@goran-w
goran-w force-pushed the improve_graph_highlighting branch from 57309e2 to befcd17 Compare August 22, 2026 23:21
@goran-w goran-w changed the title [Enhancement] Add new graph-highlighting option "Selected Commits (Only First Parent)" [Enhancement] Add new graph-highlighting option "Selected Commits (only first-parent)" Aug 22, 2026
@goran-w
goran-w force-pushed the improve_graph_highlighting branch from befcd17 to f15eaf8 Compare August 23, 2026 18:26
* The remaining parents are covered further down (under condition '!firstParentOnlyEnabled').
* This is made in prep for upcoming work on adding a new highlighting option.
@goran-w
goran-w force-pushed the improve_graph_highlighting branch from f15eaf8 to 3ede806 Compare August 23, 2026 18:38
@love-linger
love-linger merged commit 3d281f2 into sourcegit-scm:develop Aug 24, 2026
14 checks passed
@love-linger love-linger self-assigned this Aug 24, 2026
@love-linger love-linger added the enhancement New feature or request label Aug 24, 2026
lucienlmy pushed a commit to lucienlmy/sourcegit that referenced this pull request Aug 24, 2026
…rst-parent)" (sourcegit-scm#2646)

* Refactor: move relevant code to new method Histories.RecalculateMergeState()
* Reduce redundant code in RecalculateMergeState()
* Reduce redundant highlighting-code by modifying if-conditions
* Highlight first parent separately for "extra" commits
* The remaining parents are covered further down (under condition '!firstParentOnlyEnabled').
* This is made in prep for upcoming work on adding a new highlighting option.
* Add new graph-highlight option "Selected Commits (only first-parent)"
@JC-Chung

Copy link
Copy Markdown
Contributor

SelectedCommitsOnlyFirstParent was inserted in the middle of the enum (between SelectedCommitsOnly and CurrentBranchAndSelectedCommits), shifting CurrentBranchAndSelectedCommits from 3 to 4:

public enum CommitGraphHighlighting
{
    All = 0,
    CurrentBranchOnly,
    SelectedCommitsOnly,
    SelectedCommitsOnlyFirstParent,   // new
    CurrentBranchAndSelectedCommits,  // 3 -> 4
}

Since GraphHighlighting is persisted as a raw int in sourcegit.uistates, users who had CurrentBranchAndSelectedCommits saved will silently get SelectedCommitsOnlyFirstParent after upgrading. Maybe append the new value at the end instead?

@love-linger

Copy link
Copy Markdown
Collaborator

@JC-Chung good catch. I've pushed a new commit that fixes it.

@goran-w

goran-w commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@JC-Chung good catch. I've pushed a new commit that fixes it.

For reference, this was done in commit e308279. Excellent catch, indeed! Thanks!

@goran-w
goran-w deleted the improve_graph_highlighting branch August 24, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants