From 6cb7234cb5d438cdad6c78164f44dc16dee01642 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Wed, 21 Jun 2023 21:42:50 +0100 Subject: [PATCH] BBIM fix Git panel polling repo on refresh (#3096) Just scrolling Git panel shouldn't do any Git IO --- .../blenderbim/bim/module/ifcgit/data.py | 25 +++++++++++++++++++ .../blenderbim/bim/module/ifcgit/operator.py | 21 +++++++++++++--- .../blenderbim/bim/module/ifcgit/prop.py | 2 +- .../blenderbim/bim/module/ifcgit/ui.py | 12 ++++----- src/blenderbim/blenderbim/core/ifcgit.py | 3 ++- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/data.py b/src/blenderbim/blenderbim/bim/module/ifcgit/data.py index 611b879c64..2a74731d02 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/data.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/data.py @@ -34,6 +34,10 @@ class IfcGitData: "name_ifc": cls.name_ifc(), "dir_name": cls.dir_name(), "base_name": cls.base_name(), + "working_dir": cls.working_dir(), + "untracked_files": cls.untracked_files(), + "is_detached": cls.is_detached(), + "active_branch_name": cls.active_branch_name(), "is_dirty": cls.is_dirty(), "commit": cls.commit(), "current_revision": cls.current_revision(), @@ -118,6 +122,27 @@ class IfcGitData: return os.path.basename(path_ifc) return None + @classmethod + def working_dir(cls): + if cls.repo(): + return cls.repo().working_dir + + @classmethod + def untracked_files(cls): + if cls.repo(): + return cls.repo().untracked_files + return [] + + @classmethod + def is_detached(cls): + if cls.repo(): + return cls.repo().head.is_detached + + @classmethod + def active_branch_name(cls): + if cls.repo() and not cls.is_detached(): + return cls.repo().active_branch.name + @classmethod def is_dirty(cls): if cls.repo() and cls.git_exe(): diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py index 0cafb6b987..2d1c5094b9 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py @@ -149,6 +149,8 @@ class AddTag(bpy.types.Operator): def poll(cls, context): IfcGitData.make_sure_is_loaded() props = context.scene.IfcGitProperties + if props.new_tag_name == "": + return False repo = IfcGitData.data["repo"] if repo and ( not tool.IfcGit.is_valid_ref_format(props.new_tag_name) @@ -194,7 +196,7 @@ class RefreshGit(bpy.types.Operator): def poll(cls, context): IfcGitData.make_sure_is_loaded() repo = IfcGitData.data["repo"] - if repo != None and repo.heads: + if repo: return True return False @@ -213,6 +215,12 @@ class DisplayRevision(bpy.types.Operator): bl_idname = "ifcgit.display_revision" bl_options = {"REGISTER"} + @classmethod + def poll(cls, context): + props = context.scene.IfcGitProperties + if props.ifcgit_commits: + return True + def execute(self, context): core.colourise_revision(tool.IfcGit) @@ -242,6 +250,12 @@ class SwitchRevision(bpy.types.Operator): bl_idname = "ifcgit.switch_revision" bl_options = {"REGISTER"} + @classmethod + def poll(cls, context): + props = context.scene.IfcGitProperties + if props.ifcgit_commits: + return True + def execute(self, context): core.switch_revision(tool.IfcGit, tool.Ifc) @@ -259,7 +273,8 @@ class Merge(bpy.types.Operator): @classmethod def poll(cls, context): IfcGitData.make_sure_is_loaded() - if IfcGitData.data["ifcmerge_exe"]: + props = context.scene.IfcGitProperties + if IfcGitData.data["ifcmerge_exe"] and props.ifcgit_commits and not IfcGitData.data["is_detached"]: return True return False @@ -318,8 +333,8 @@ class AddRemote(bpy.types.Operator): if ( not repo or not tool.IfcGit.is_valid_ref_format(props.remote_name) - or props.remote_name in [remote.name for remote in repo.remotes] or not props.remote_url + or props.remote_name in [remote.name for remote in repo.remotes] ): return False return True diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py b/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py index 8273ac7cfa..c34b2f6e84 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py @@ -7,7 +7,7 @@ from bpy.props import ( IntProperty, EnumProperty, ) -from blenderbim.bim.module.ifcgit.data import IfcGitData, refresh +from blenderbim.bim.module.ifcgit.data import IfcGitData def git_branches(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py index 690934701e..286e900adc 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py @@ -1,6 +1,6 @@ import bpy import time -from blenderbim.bim.module.ifcgit.data import IfcGitData, refresh +from blenderbim.bim.module.ifcgit.data import IfcGitData class IFCGIT_PT_panel(bpy.types.Panel): @@ -34,8 +34,8 @@ class IFCGIT_PT_panel(bpy.types.Panel): if path_ifc: if IfcGitData.data["repo"]: name_ifc = IfcGitData.data["name_ifc"] - row.label(text=IfcGitData.data["repo"].working_dir, icon="SYSTEM") - if name_ifc in IfcGitData.data["repo"].untracked_files: + row.label(text=IfcGitData.data["working_dir"], icon="SYSTEM") + if name_ifc in IfcGitData.data["untracked_files"]: row.operator( "ifcgit.addfile", text="Add '" + name_ifc + "' to repository", @@ -79,7 +79,7 @@ class IFCGIT_PT_panel(bpy.types.Panel): row = layout.row() row.prop(props, "commit_message") - if IfcGitData.data["repo"].head.is_detached: + if IfcGitData.data["is_detached"]: row = layout.row() row.label(text="HEAD is detached, commit will create a branch", icon="ERROR") row.prop(props, "new_branch_name") @@ -88,10 +88,10 @@ class IFCGIT_PT_panel(bpy.types.Panel): row.operator("ifcgit.commit_changes", icon="GREASEPENCIL") row = layout.row() - if IfcGitData.data["repo"].head.is_detached: + if IfcGitData.data["is_detached"]: row.label(text="Working branch: Detached HEAD") else: - row.label(text="Working branch: " + IfcGitData.data["repo"].active_branch.name) + row.label(text="Working branch: " + IfcGitData.data["active_branch_name"]) grouped = layout.row() column = grouped.column() diff --git a/src/blenderbim/blenderbim/core/ifcgit.py b/src/blenderbim/blenderbim/core/ifcgit.py index fe368d1d5d..c1a1472255 100644 --- a/src/blenderbim/blenderbim/core/ifcgit.py +++ b/src/blenderbim/blenderbim/core/ifcgit.py @@ -57,7 +57,8 @@ def push(ifcgit, repo, remote_name, operator): def refresh_revision_list(ifcgit, repo, ifc): - ifcgit.refresh_revision_list(ifc.get_path()) + if repo.heads: + ifcgit.refresh_revision_list(ifc.get_path()) def colourise_revision(ifcgit):