From 1cd8a1e7c2de52270e2ae0bcde4bab78e45c2a7a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 15 Aug 2026 23:28:33 +0200 Subject: [PATCH] Share how a ref's diff endpoints are derived MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit files context works out the two ends to diff from the ref (or range of refs) it was entered for. The panels that hold those refs themselves — commits, sub-commits, stash, reflog — are about to need the same two ends, to hand out the diff behind what they render into the focused main view. Pull the derivation out of the context so they can ask for it rather than each spelling out the parent-of-from rule again. Co-authored-by: Claude Opus 5 (1M context) --- pkg/gui/context/commit_files_context.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 9689df29b..4ad7334ef 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -85,10 +85,16 @@ func (self *CommitFilesContext) RefForAdjustingLineNumberInDiff() string { } func (self *CommitFilesContext) GetFromAndToForDiff() (string, string) { - if refs := self.GetRefRange(); refs != nil { - return refs.From.ParentRefName(), refs.To.RefName() + return FromAndToForDiff(self.GetRef(), self.GetRefRange()) +} + +// FromAndToForDiff gives the two ends to diff for a ref, or for a range of them: a +// range runs from the parent of its first ref to its last, a single ref from its own +// parent to itself. +func FromAndToForDiff(ref models.Ref, refRange *types.RefRange) (string, string) { + if refRange != nil { + return refRange.From.ParentRefName(), refRange.To.RefName() } - ref := self.GetRef() return ref.ParentRefName(), ref.RefName() }