View Single Post
Old 10-06-2022, 11:51 AM   #20
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,817
Karma: 6000000
Join Date: Nov 2009
Device: many
@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)

Last edited by KevinH; 10-06-2022 at 12:09 PM.
KevinH is offline   Reply With Quote