
___x_cmd_gitb_update(){
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)      ___x_cmd help -m gitb manager "$@"; return ;;
            *)              break ;;
        esac
    done

    if [ $# -eq 0 ]; then
        ___x_cmd_gitb_update___pipe
    else
        printf "%s\n" "$@" | ___x_cmd_gitb_update___pipe
    fi
}

___x_cmd_gitb_update___pipe(){
    local repo
    while ___x_cmd_readr repo; do
        # TODO: Consider downloading in parallel
        ___x_cmd_gitb_update_one "$repo"
    done
    gitb:info "Exit now."
}

___x_cmd_gitb_update_one(){
    local repo="$1"
    if ___x_cmd_gitb_isexisted "$repo"; then
        ___x_cmd_gitb fetch "$repo"
    else
        ___x_cmd_gitb add   "$repo"
    fi
}

___x_cmd_gitb_isexisted(){
    local repo="$1"
    ___x_cmd_gitb___name_to_brpath_ "$repo"
    local bp="$___X_CMD_GITB___NAME_TO_BRPATH_"
    [ -d "$bp" ]
}

