Skip to content

Commit

Permalink
Merge pull request #1828 from timbrel/minor-do-not-preselect-fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Dec 8, 2023
2 parents 31c8b4f + 06b3ec6 commit 0f32c20
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
19 changes: 17 additions & 2 deletions core/commands/commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from itertools import takewhile
from itertools import chain, takewhile
import os

import sublime
Expand All @@ -8,6 +8,7 @@
from .diff import DECODE_ERROR_MESSAGE
from . import intra_line_colorizer
from ..git_command import GitCommand, GitSavvyError
from ..fns import head
from ..runtime import enqueue_on_worker, text_command
from ..settings import SettingsMixin
from ..ui_mixins.quick_panel import LogHelperMixin
Expand Down Expand Up @@ -651,7 +652,21 @@ def action(entry):
view.sel().clear()
view.sel().add(len(text))

self.show_log_panel(action, preselected_commit_message=clean_subject)
def preselected_commit(items):
# type: (List[LogEntry]) -> int
return next(chain(
head(idx for idx, item in enumerate(items) if item.summary == clean_subject),
head(
idx for idx, item in enumerate(items)
if (
not item.summary.startswith("fixup! ")
and not item.summary.startswith("squash! ")
)
) if prefix else [],
[-1]
))

self.show_log_panel(action, preselected_commit=preselected_commit)


def cleanup_subject(subject):
Expand Down
17 changes: 15 additions & 2 deletions core/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import intra_line_colorizer
from . import stage_hunk
from .navigate import GsNavigate
from ..fns import filter_, flatten, pairwise, unique
from ..fns import head, filter_, flatten, pairwise, unique
from ..parse_diff import SplittedDiff
from ..git_command import GitCommand
from ..runtime import ensure_on_ui, enqueue_on_worker
Expand Down Expand Up @@ -794,7 +794,20 @@ def action(entry):
"initial_text": "fixup! {}".format(commit_message)
})

self.show_log_panel(action)
def preselected_commit(items):
# type: (List[LogEntry]) -> int
return next(chain(
head(
idx for idx, item in enumerate(items)
if (
not item.summary.startswith("fixup! ")
and not item.summary.startswith("squash! ")
)
),
[-1]
))

self.show_log_panel(action, preselected_commit=preselected_commit)


MYPY = False
Expand Down
5 changes: 5 additions & 0 deletions core/fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def drop(n, iterable):
return islice(iterable, n, None)


def head(iterable):
# type: (Iterable[T]) -> List[T]
return take(1, iterable)


def tail(iterable):
# type: (Iterable[T]) -> Iterator[T]
return drop(1, iterable)
Expand Down
10 changes: 3 additions & 7 deletions core/ui_mixins/quick_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ def on_selection(self, commit):


class LogHelperMixin(GitCommand):
def show_log_panel(self, action, preselected_commit_message=None):
# type: (Callable[[LogEntry], None], str) -> None
def show_log_panel(self, action, preselected_commit=lambda items: -1):
# type: (Callable[[LogEntry], None], Callable[[List[LogEntry]], int]) -> None
window = self._current_window()
if not window:
return
Expand Down Expand Up @@ -622,11 +622,7 @@ def format_item(entry: LogEntry) -> str:
entry.summary
)))

preselected_idx = next(
(idx for idx, item in enumerate(items) if item.summary == preselected_commit_message),
-1
) if preselected_commit_message else -1

preselected_idx = preselected_commit(items)
show_panel(
window,
map(format_item, items),
Expand Down

0 comments on commit 0f32c20

Please sign in to comment.