mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Extract a findTodo helper function
We will reuse it in the next commit.
This commit is contained in:
parent
bd975a8dcb
commit
64a1a455d6
1 changed files with 14 additions and 9 deletions
|
@ -56,6 +56,19 @@ func equalShas(a, b string) bool {
|
|||
return strings.HasPrefix(a, b) || strings.HasPrefix(b, a)
|
||||
}
|
||||
|
||||
func findTodo(todos []todo.Todo, todoToFind Todo) (int, bool) {
|
||||
_, idx, ok := lo.FindIndexOf(todos, func(t todo.Todo) bool {
|
||||
// Comparing just the sha is not enough; we need to compare both the
|
||||
// action and the sha, as the sha could appear multiple times (e.g. in a
|
||||
// pick and later in a merge). For update-ref todos we also must compare
|
||||
// the Ref.
|
||||
return t.Command == todoToFind.Action &&
|
||||
equalShas(t.Commit, todoToFind.Sha) &&
|
||||
t.Ref == todoToFind.Ref
|
||||
})
|
||||
return idx, ok
|
||||
}
|
||||
|
||||
func ReadRebaseTodoFile(fileName string, commentChar byte) ([]todo.Todo, error) {
|
||||
f, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
|
@ -128,15 +141,7 @@ func moveTodosDown(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
|
|||
}
|
||||
|
||||
func moveTodoUp(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) {
|
||||
_, sourceIdx, ok := lo.FindIndexOf(todos, func(t todo.Todo) bool {
|
||||
// Comparing just the sha is not enough; we need to compare both the
|
||||
// action and the sha, as the sha could appear multiple times (e.g. in a
|
||||
// pick and later in a merge). For update-ref todos we also must compare
|
||||
// the Ref.
|
||||
return t.Command == todoToMove.Action &&
|
||||
equalShas(t.Commit, todoToMove.Sha) &&
|
||||
t.Ref == todoToMove.Ref
|
||||
})
|
||||
sourceIdx, ok := findTodo(todos, todoToMove)
|
||||
|
||||
if !ok {
|
||||
// Should never happen
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue