Skip to content

Commit

Permalink
Merge pull request #1909 from timbrel/fix-annotate-new-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste authored Apr 22, 2024
2 parents 77c4e98 + c3d3659 commit 3d75d38
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions core/interfaces/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ class Succeeded(TypedDict):
FetchStateMachine = Union[
Loading, Erred, Succeeded
]
RemoteTagsInfo = Dict[str, FetchStateMachine]


class TagsViewState(TypedDict, total=False):
git_root: str
long_status: str
local_tags: TagList
remotes: Dict[str, str]
remote_tags: Dict[str, FetchStateMachine]
remote_tags_info: RemoteTagsInfo
recent_commits: List[Commit]
max_items: Optional[int]
show_remotes: bool
Expand Down Expand Up @@ -134,7 +135,7 @@ class TagsInterface(ui.ReactiveInterface, GitCommand):
def initial_state(self):
return {
'show_remotes': self.savvy_settings.get("show_remotes_in_branch_dashboard"),
'remote_tags': {}
'remote_tags_info': {}
}

def title(self):
Expand All @@ -160,8 +161,8 @@ def refresh_view_state(self):
})

@ui.inject_state()
def maybe_populate_remote_tags(self, remotes, show_remotes, remote_tags):
# type: (Dict[str, str], bool, Dict[str, FetchStateMachine]) -> None
def maybe_populate_remote_tags(self, remotes, remote_tags_info):
# type: (Dict[str, str], RemoteTagsInfo) -> None
def do_tags_fetch(remote_name):
try:
new_state = {
Expand All @@ -175,14 +176,14 @@ def do_tags_fetch(remote_name):
}

def sink():
remote_tags[remote_name] = new_state
remote_tags_info[remote_name] = new_state
self.just_render()
enqueue_on_worker(sink) # fan-in

if remotes and not remote_tags:
if remotes and not remote_tags_info:
for remote_name in remotes:
run_on_new_thread(do_tags_fetch, remote_name) # fan-out
remote_tags[remote_name] = {
remote_tags_info[remote_name] = {
"state": "loading"
}

Expand Down Expand Up @@ -214,27 +215,31 @@ def render_head(self, recent_commits):
return "{0.hash} {0.message}".format(recent_commits[0])

@ui.section("local_tags")
def render_local_tags(self, local_tags, max_items):
# type: (TagList, int) -> ui.RenderFnReturnType
def render_local_tags(self, local_tags, max_items, remote_tags_info):
# type: (TagList, int, RemoteTagsInfo) -> ui.RenderFnReturnType
if not any(local_tags.all):
return NO_LOCAL_TAGS_MESSAGE

remote_tags, remote_tag_names = set(), set()
# wait until all settled to prohibit intermediate state to be drawn
# what we draw explicitly relies on *all* known remote tags
if all(info["state"] != "loading" for info in self.state["remote_tags"].values()):
for info in self.state["remote_tags"].values():
if remote_tags_info and all(info["state"] != "loading" for info in remote_tags_info.values()):
remote_tags, remote_tag_names = set(), set()
for info in remote_tags_info.values():
if info["state"] == "succeeded":
for tag in info["tags"]:
remote_tags.add((tag.sha, tag.tag))
remote_tag_names.add(tag.tag)

def maybe_mark(tag):
if remote_tag_names and tag.tag not in remote_tag_names:
return "*" # denote new semver
if remote_tags and (tag.sha, tag.tag) not in remote_tags:
return "!" # denote known semver on a different hash
return " "
def maybe_mark(tag):
if tag.tag not in remote_tag_names:
return "*" # denote new semver
if (tag.sha, tag.tag) not in remote_tags:
return "!" # denote known semver on a different hash
return " "

else:
def maybe_mark(tag):
return " "

return "\n{}\n".format(" " * 60).join( # need some spaces on the separator line otherwise
# the syntax expects the remote section begins
Expand All @@ -260,8 +265,8 @@ def maybe_mark(tag):
)

@ui.section("remote_tags")
def render_remote_tags(self, remotes, show_remotes, remote_tags):
# type: (Dict[str, str], bool, Dict[str, FetchStateMachine]) -> ui.RenderFnReturnType
def render_remote_tags(self, remotes, show_remotes, remote_tags_info):
# type: (Dict[str, str], bool, RemoteTagsInfo) -> ui.RenderFnReturnType
if not remotes:
return "\n"

Expand All @@ -272,7 +277,7 @@ def render_remote_tags(self, remotes, show_remotes, remote_tags):
render_fns = []

for remote_name in remotes:
remote_info = remote_tags.get(remote_name)
remote_info = remote_tags_info.get(remote_name)
if not remote_info:
continue

Expand Down Expand Up @@ -373,7 +378,7 @@ def run(self, edit, show=None):
next_state = not current_state if show is None else show
interface.state["show_remotes"] = next_state
if next_state:
interface.state["remote_tags"] = {}
interface.state["remote_tags_info"] = {}
interface.render()


Expand All @@ -386,7 +391,7 @@ class gs_tags_refresh(TagsInterfaceCommand):
def run(self, edit, reset_remotes=False):
interface = self.interface
if reset_remotes:
interface.state["remote_tags"] = {}
interface.state["remote_tags_info"] = {}

util.view.refresh_gitsavvy(self.view)

Expand All @@ -412,7 +417,7 @@ def run(self, edit):
if local_tags or remote_tags:
flash(self.view, TAG_DELETE_MESSAGE)
if remote_tags:
self.interface.state["remote_tags"] = {}
self.interface.state["remote_tags_info"] = {}
util.view.refresh_gitsavvy(self.view)

def delete_local(self):
Expand Down Expand Up @@ -462,7 +467,7 @@ def push_selected(self, remote):
flash(self.view, END_PUSH_MESSAGE)

interface = self.interface
interface.state["remote_tags"] = {}
interface.state["remote_tags_info"] = {}
util.view.refresh_gitsavvy(self.view)


Expand Down

0 comments on commit 3d75d38

Please sign in to comment.