@DiapDealer
The more I think about it, the more I like your idea of going the tag delete and tag create approach with manually cleaning up the loose object (old Tag), at least that way the annotated tag itself stores the new message making it easier to work with real git if anyone likes to do that.
I have created some code that should be close. I do not have a full build environment here on my laptop (I am at my cottage to celebrate Canadian Thanksgiving and then close it up).
If you have any free time and access to checkpoint repos try playing around with this routine to see if it will do what we want. Otherwise in a week or so when I return home I will see if I can get that routine working (at least manually).
Code:
def update_annotated_tag_message(localRepo, bookid, tagname, newmessage)
repo_home = pathof(localRepo)
repo_home = repo_home.replace("/", os.sep)
repo_path = os.path.join(repo_home, "epub_" + bookid)
cdir = os.getcwd()
if os.path.exists(repo_path):
os.chdir(repo_path)
with open_repo_closing(".") as r:
tag_name = utf8str(tagname)
tags = sorted(r.refs.as_dict(b"refs/tags"))
tagkey = b"refs/tags/" + tag_name
if tag_name in tags:
obj = r[tagkey]
if isinstance(obj,Tag):
# create a duplicate Tag with updated message
nobj = Tag()
nobj.tag_time = obj.tag_time
nobj.tag_timezone = obj.tag_timezone
nobj.message = utf8str(newmessage + "\n")
nobj.name = obj.name
nobj.tagger = obj.tagger
nobj.object = obj.object
old_sha = obj.sha
# delete the old tag from the object store refs dictionary
del r.refs[_make_tag_ref(tag_name)]
# remove the old annotated object itself from the object store
r.object_store._remove_loose_object(old_sha)
# add in the updated tag to the object store
r.object_store.add_object(nobj)
# create a ref in the refs dictionary for the updated tag
tag_id = nobj.id
r.refs[_make_tag_ref(tag_name)] = tag_id
os.chdir(cdir)