NormalizeCommitRange ensures commits are in chronological order (older first). If the commits are reversed (newer...older), it swaps them. Returns (olderCommit, newerCommit, swapped, error)
(repoPath, from, to string)
| 169 | // If the commits are reversed (newer...older), it swaps them. |
| 170 | // Returns (olderCommit, newerCommit, swapped, error) |
| 171 | func NormalizeCommitRange(repoPath, from, to string) (string, string, bool, error) { |
| 172 | // Check if 'from' is an ancestor of 'to' (correct order) |
| 173 | isCorrectOrder, err := isAncestor(repoPath, from, to) |
| 174 | if err != nil { |
| 175 | return from, to, false, err |
| 176 | } |
| 177 | |
| 178 | if isCorrectOrder { |
| 179 | // Already in correct order (from is older) |
| 180 | return from, to, false, nil |
| 181 | } |
| 182 | |
| 183 | // Check if 'to' is an ancestor of 'from' (reversed order) |
| 184 | isReversed, err := isAncestor(repoPath, to, from) |
| 185 | if err != nil { |
| 186 | return from, to, false, err |
| 187 | } |
| 188 | |
| 189 | if isReversed { |
| 190 | // Commits are reversed, swap them |
| 191 | return to, from, true, nil |
| 192 | } |
| 193 | |
| 194 | // Commits are not in a linear ancestry (e.g., different branches) |
| 195 | // Keep original order - git diff will still work |
| 196 | return from, to, false, nil |
| 197 | } |
| 198 | |
| 199 | // GetCommitRangeLabel returns a label like "abc123...def456" for display |
| 200 | func GetCommitRangeLabel(repoPath, fromCommit, toCommit string) (string, error) { |