def mode_str_to_int(modestr: Union[bytes, str]) -> int:
    """Convert mode bits from an octal mode string to an integer mode for git.

    :param modestr:
        String like ``755`` or ``644`` or ``100644`` - only the last 6 chars will be
        used.

    :return:
        String identifying a mode compatible to the mode methods ids of the :mod:`stat`
        module regarding the rwx permissions for user, group and other, special flags
        and file system flags, such as whether it is a symlink.
    """
    mode = 0
    for iteration, char in enumerate(reversed(modestr[-6:])):
        char = cast(Union[str, int], char)
        mode += int(char) << iteration * 3
    # END for each char
    return mode
Convert mode bits from an octal mode string to an integer mode for git.

    :param modestr:
        String like ``755`` or ``644`` or ``100644`` - only the last 6 chars will be
        used.

    :return:
        String identifying a mode compatible to the mode methods ids of the :mod:`stat`
        module regarding the rwx permissions for user, group and other, special flags
        and file system flags, such as whether it is a symlink.
    
git/objects/util.py