package com.atlassian.bitbucket.mesh.git.builder.repack;

import javax.annotation.Nullable;

/**
 * Controls whether {@code git repack} repacks objects that are already included in a pack, or only packs loose
 * objects. By {@link GitRepackAll#DEFAULT default}, only loose objects are packed.
 */
public enum GitRepackAll {

    /**
     * Packs all <i>loose</i> objects. Objects in existing packs, whether reachable or not, are left as-is.
     */
    DEFAULT,
    /**
     * Repacks all <i>reachable</i> objects, including those that are already in another pack, and writes any
     * previously-packed objects that are no longer reachable as loose objects. This prevents those objects
     * from being implicitly pruned when existing packs are pruned after the new pack is created.
     */
    LOOSEN_UNREACHABLE("-A"),
    /**
     * Repacks all <i>reachable</i> objects, leaving any previously-packed objects which are now unreachable in
     * their packs. If existing packs are pruned after the creation of the new pack, any still-packed unreachable
     * objects are implicitly pruned with them.
     */
    REACHABLE("-a");

    private final String flag;

    GitRepackAll() {
        flag = null;
    }

    GitRepackAll(String flag) {
        this.flag = flag;
    }

    @Nullable
    public String getFlag() {
        return flag;
    }

    public boolean isFlagged() {
        return flag != null;
    }
}
