def _global_init(p4):
    """Create global Git Fusion Perforce data:
    * user git-fusion-user
    * depot //.git-fusion
    * group git-fusion-pull
    * group git-fusion-push
    * protects entries
    """

    #
    # The global initialization process below must be idempotent in the sense
    # that it is safe to perform more than once. As such, there are checks to
    # determine if work is needed or not, and if that work results in an
    # error, log and carry on with the rest of the steps, with the assumption
    # that a previous attempt had failed in the middle (or possibly that
    # another instance of Git Fusion has started at nearly the same time as
    # this one).
    #

    with p4gf_group.PermErrorOK(p4):
        p4gf_util.ensure_user_gf(p4)

    with p4gf_group.PermErrorOK(p4):
        p4gf_util.ensure_depot_gf(p4)

    p4gf_group.create_global_perm(p4, p4gf_group.PERM_PULL)
    p4gf_group.create_global_perm(p4, p4gf_group.PERM_PUSH)
    p4gf_group.create_default_perm(p4)

    ### ONCE ADMIN works, downgrade our auto-generated Protections
    ### table to git-fusion-user=admin, not super, and user * = write.

    # Require that single git-fusion-user have admin privileges
    # over the //.git-fusion/ depot
    is_protects_empty = False
    try:
        ### ONCE ADMIN works, remove the use of -u option
        p4.run('protects', '-u', p4gf_const.P4GF_USER, '-m',
               '//{depot}/...'.format(depot=p4gf_const.P4GF_DEPOT))
    except P4.P4Exception:
        if p4gf_p4msg.find_msgid(p4, p4gf_p4msgid.MsgDm_ProtectsEmpty):
            is_protects_empty = True
        # All other errors are fatal, propagated.

    if is_protects_empty:
        ### ONCE ADMIN works, modify the protects table as follows
        # - order the lines in increasing permission
        # - end with at least one user (even a not-yet-created user) with super
        #     write user * * //...
        #     admin user git-fusion-user * //...
        #     super user super * //...
        p4gf_util.set_spec(p4, 'protect', values={
            'Protections': ["super user * * //...",
                            "super user {user} * //...".format(user=p4gf_const.P4GF_USER),
                            "admin user {user} * //{depot}/..."
                            .format(user=p4gf_const.P4GF_USER, depot=p4gf_const.P4GF_DEPOT)]})
def ensure_depot():
    """Create depot P4GF_DEPOT if not already exists."""
    created = p4gf_util.ensure_depot_gf(p4)
    if created:
        Verbosity.report(Verbosity.INFO, _("Depot '{}' created.").format(p4gf_const.P4GF_DEPOT))
    else:
        Verbosity.report(Verbosity.INFO, _("Depot '{}' already exists. Not creating.")
                     .format(p4gf_const.P4GF_DEPOT))
    return created
def ensure_depot():
    """Create depot .git-fusion if not already exists."""
    created = p4gf_util.ensure_depot_gf(p4)
    if created:
        report(INFO, "Depot {} created.".format(p4gf_const.P4GF_DEPOT))
    else:
        report(INFO, "Depot {} already exists. Not creating."
                     .format(p4gf_const.P4GF_DEPOT))
    return created
def ensure_depot():
    """Create depot .git-fusion if not already exists."""
    created = p4gf_util.ensure_depot_gf(p4)
    if created:
        report(INFO, "Depot {} created.".format(p4gf_const.P4GF_DEPOT))
    else:
        report(
            INFO, "Depot {} already exists. Not creating.".format(
                p4gf_const.P4GF_DEPOT))
    return created
def ensure_depot():
    """Create depot P4GF_DEPOT if not already exists."""
    created = p4gf_util.ensure_depot_gf(p4)
    if created:
        Verbosity.report(
            Verbosity.INFO,
            _("Depot '{}' created.").format(p4gf_const.P4GF_DEPOT))
    else:
        Verbosity.report(
            Verbosity.INFO,
            _("Depot '{}' already exists. Not creating.").format(
                p4gf_const.P4GF_DEPOT))
    return created