diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py b/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py index 41e5886336..ad0337832a 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/__init__.py @@ -21,6 +21,7 @@ from . import ui, prop, operator classes = ( operator.AddFileToRepo, + operator.AddTag, operator.CommitChanges, operator.CreateRepo, operator.DiscardUncommitted, @@ -29,6 +30,7 @@ classes = ( operator.Merge, operator.RefreshGit, operator.SwitchRevision, + prop.IfcGitTag, prop.IfcGitListItem, prop.IfcGitProperties, ui.IFCGIT_PT_panel, diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py index bd7ed4a56e..9bf88c58d4 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/operator.py @@ -107,6 +107,33 @@ class CommitChanges(bpy.types.Operator): return {"FINISHED"} +class AddTag(bpy.types.Operator): + """Tag selected revision""" + + bl_label = "Add tag" + bl_idname = "ifcgit.add_tag" + bl_options = {"REGISTER"} + + @classmethod + def poll(cls, context): + props = context.scene.IfcGitProperties + repo = IfcGitData.data["repo"] + if repo and ( + not tool.IfcGit.is_valid_ref_format(props.new_tag_name) + or props.new_tag_name in [tag.name for tag in repo.tags] + ): + return False + return True + + def execute(self, context): + + repo = IfcGitData.data["repo"] + core.add_tag(tool.IfcGit, repo) + bpy.ops.ifcgit.refresh() + refresh() + return {"FINISHED"} + + class RefreshGit(bpy.types.Operator): """Refresh revision list""" diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py b/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py index 5f2d4886d9..0780e6df3e 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/prop.py @@ -32,6 +32,19 @@ def update_revlist(self, context): props.commit_index = 0 +class IfcGitTag(PropertyGroup): + """Properties of a Git tag""" + + name: StringProperty( + name="Tag name", + default="", + ) + message: StringProperty( + name="Tag message", + default="", + ) + + class IfcGitListItem(PropertyGroup): """Group of properties representing an item in the list.""" @@ -57,6 +70,7 @@ class IfcGitListItem(PropertyGroup): name="Commit Message", default="", ) + tags: CollectionProperty(type=IfcGitTag, name="List of revision tags") class IfcGitProperties(PropertyGroup): @@ -73,6 +87,16 @@ class IfcGitProperties(PropertyGroup): description="A short name used to refer to this branch", default="", ) + new_tag_name: StringProperty( + name="New tag name", + description="A short name used to refer to this tag", + default="", + ) + new_tag_message: StringProperty( + name="Tag message (optional)", + description="An optional human readable description of this tag", + default="", + ) display_branch: EnumProperty(items=git_branches, update=update_revlist) ifcgit_filter: EnumProperty( items=[ diff --git a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py index e4a714850b..ddae10e108 100644 --- a/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py +++ b/src/blenderbim/blenderbim/bim/module/ifcgit/ui.py @@ -132,6 +132,25 @@ class IFCGIT_PT_panel(bpy.types.Panel): row = column.row() row.label(text=item.message) + for tag in item.tags: + box = layout.box() + item = box.row() + column = item.column(align=True) + row = column.row() + row.label(text=tag.name) + if tag.message: + row = column.row() + row.label(text=tag.message) + # TODO + # item.operator("ifcgit.delete_tag", icon="PANEL_CLOSE") + + row = layout.row() + row.prop(props, "new_tag_name") + row = layout.row() + row.prop(props, "new_tag_message") + row = layout.row() + row.operator("ifcgit.add_tag", icon="GREASEPENCIL") + class COMMIT_UL_List(bpy.types.UIList): """List of Git commits""" diff --git a/src/blenderbim/blenderbim/core/ifcgit.py b/src/blenderbim/blenderbim/core/ifcgit.py index ff6a17178c..deb0358c91 100644 --- a/src/blenderbim/blenderbim/core/ifcgit.py +++ b/src/blenderbim/blenderbim/core/ifcgit.py @@ -25,6 +25,10 @@ def commit_changes(ifcgit, ifc, repo, context): ifcgit.create_new_branch() +def add_tag(ifcgit, repo): + ifcgit.add_tag(repo) + + def refresh_revision_list(ifcgit, repo, ifc): ifcgit.clear_commits_list() path_ifc = ifc.get_path() diff --git a/src/blenderbim/blenderbim/tool/ifcgit.py b/src/blenderbim/blenderbim/tool/ifcgit.py index 81d0251b32..7826ab5c75 100644 --- a/src/blenderbim/blenderbim/tool/ifcgit.py +++ b/src/blenderbim/blenderbim/tool/ifcgit.py @@ -62,6 +62,14 @@ class IfcGit: repo.index.commit(message=props.commit_message) props.commit_message = "" + @classmethod + def add_tag(cls, repo): + props = bpy.context.scene.IfcGitProperties + item = props.ifcgit_commits[props.commit_index] + repo.create_tag(props.new_tag_name, ref=item.hexsha, message=props.new_tag_message) + props.new_tag_name = "" + props.new_tag_message = "" + @classmethod def create_new_branch(cls): props = bpy.context.scene.IfcGitProperties @@ -115,6 +123,13 @@ class IfcGit: list_item.author_email = commit.author.email if commit in commits_relevant: list_item.relevant = True + if commit.hexsha in lookup: + for tag in lookup[commit.hexsha]: + list_item.tags.add() + list_item.tags[-1].name = tag.name + if tag.tag: + # a lightweight tag has no message + list_item.tags[-1].message = tag.tag.message @classmethod def is_valid_ref_format(cls, string):