Menu ▾ ▴

#1 Error 'module' object has no attribute 'mergestate'

1.0
closed
nedmech
None
2020-09-29
2020-09-25
Michael S.
No

Hi,

I'm not sure about the project's activity since it has been moved from Bitbucket to SourceForge.
I will report the following bug anyways:

After upgrading to TortoiseHg/Mercurial 5.5 the following error occurs when I perform a local merge with a branch:

TimestampMod|Post-Merge Hook accessed!
Fehler: Hook post-merge. TimestampMod löste eine Ausnahme aus:
'module' object has no attribute 'mergestate'
(run with --traceback for stack trace)

Best regards,
Michael

Discussion

  • Michael S.

    Michael S. - 2020-09-25

    Found the reason here:
    https://www.mercurial-scm.org/wiki/Release5.5

    The mercurial API has changed:

    The mergestate class along with some related methods and constants have
    moved from mercurial.merge to a new mercurial.mergestate module.

    Here is my quick & dirty resolution:

    Edit in the import modules section line 54 from

    merge as mergemod, # required for merge state (check unresolved).
    

    to

    mergestate as mergemod, # required for merge state (check unresolved).
    

    But I think this makes the Extension incompatible to the API < v5.5. I'm no python developer. Thus I don't know how to handle this issue gracefully.

    Best regards
    Michael

     
    • nedmech

      nedmech - 2020-09-25

      Hi Michael,

      Thanks for the issue report and for doing some of the research for me! This project is not really active right now since I haven't been updating my Mercurial/TortoiseHg version recently due to my current job being stuck on 5.0.2 for a while now. Python's not my primary language either, but I think I can see how to make a "try...else..." type include for that module. Can you edit your file and test something for me?

      Delete line 54 entirely, then insert the following at line 57 (after the closing parenthesis):

      try: # import library required for merge state (check unresolved).
          import mercurial.merge as mergemod
      except ImportError:
          # NOTE: 'mergestate' class was moved 'mercurial.merge' to
          # 'mercurial.mergestate' in mercurial API version 5.5
          import mercurial.mergestate as mergemod
      

      That should attempt to import the original library, then fall into the new 5.5 name if it doesn't succeed. It seems to be working fine for my 5.0.2 version.

       
  • Michael S.

    Michael S. - 2020-09-26

    Hi Nathan,

    thank you for your quick reply!

    Unfortunately your proposed edit doesn't work, because the module 'mercurial.merge' still exists in API V5.5. Just the class 'mergestate' was extracted to 'mercurial.mergestate'. Therefore the import does always succeed but 'mergestate' may still not be available...

    But that's no big problem: Swapping the statements in the try/except branches resolves the issue:

    try: # import library required for merge state (check unresolved).
        # NOTE: 'mergestate' class was moved from 'mercurial.merge' to
        # 'mercurial.mergestate' in mercurial API version 5.5
        import mercurial.mergestate as mergemod
    except ImportError:
        # fallback: 'mergestate' class is probably still located in module 
        # 'mercurial.merge' (mercurial API version < 5.5)
        import mercurial.merge as mergemod
    

    Tested whit TortoiseHg 5.5.1.

     
    • nedmech

      nedmech - 2020-09-28

      Unfortunately, neither of our attempts was fully cross-compatible across the API change. I've ended up importing the class instead of the module to remove the ambigutiy of the import path. Try grabbing the file from the tip of my development branch and see if it works for you in 5.5.

      https://sourceforge.net/p/timestampmod/code/ci/development/tree/TimestampMod.py?format=raw

       
      • Michael S.

        Michael S. - 2020-09-29

        Yes! It's working with TortoiseHg 5.5.1.
        Thank you very much!

         
        • nedmech

          nedmech - 2020-09-29

          Excellent! I'll go ahead and merge the fix back into the default branch and tag the release. Thanks for your help testing.

           
  • nedmech

    nedmech - 2020-09-29
    • status: open --> closed
     
  • nedmech

    nedmech - 2020-09-29

    Closing ticket - issue resolved.

     

Log in to post a comment.