BlenderBIM list and create git tags #3096

This commit is contained in:
Bruno Postle
2023-05-13 09:57:10 +01:00
parent f7b9a7bfb5
commit df74d5efbe
6 changed files with 91 additions and 0 deletions
@@ -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,
@@ -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"""
@@ -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=[
@@ -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"""
+4
View File
@@ -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()
+15
View File
@@ -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):