#!/bin/bash

ANDROID_BUILD_TOP="$(dirname $(realpath "$0"))"
CHECK="$(echo $1 | grep -q check && echo 1)"
GERRIT_USERNAME="$(git config review.review.lineageos.org.username)"

function repopick() {
    if [[ "$CHECK" = "1" ]]; then
        echo -n "${@: -1} - " ; ssh lineage-gerrit gerrit query ${@: -1} --format=JSON | jq --slurp -r '.[0].status'
    else
        ${ANDROID_BUILD_TOP}/vendor/lineage/build/tools/repopick.py \
            -g "ssh://$GERRIT_USERNAME@review.lineageos.org:29418" $@ &
    fi
}

function repopickchain() {
    if [[ "$CHECK" = "1" ]]; then
        echo -n "$1 - " ; ssh lineage-gerrit gerrit query $1 --format=JSON | jq --slurp -r '.[0].status'
    else
        `${ANDROID_BUILD_TOP}/gen_chain $@`
    fi
}

function rc() {
    echo `${ANDROID_BUILD_TOP}/gen_chain $@ | cut -b10-`
}

source /home/nolenjohnson/lineage-23/build/envsetup.sh
source /home/nolenjohnson/lineage-23/picks

# vendor/lineage
repopick 424851 424905 424906 424853 # Switch lineage GSI to soong

## Devices

## aura
repopick -f 437270 437271 437272 # DNM
## To-Bringup

## berlin
repopick -i -t moto-livedisplay-aidl
## Ready to Ship

## floral
repopick 442546 442545 # {sunfish,floral}: Remove vendor/lineage device framework matrix inclusion
repopick 443074 442546 # {sunfish,floral}: Migrate to AIDL LiveDisplay HAL
## TODO: Need to pick kernel backports

## ingot
## Ready to Ship

## pstar
## Ready to Ship

## pro1x
repopick -p 443586 445277 # 5.10 kernel backports
## Ready to Ship

## tangorpro
## Ready to Ship

## TP1803
repopick 436766 # BPF override - depends platform change
repopick -f -p 436765 # kernel merge - waiting for ship date, either this or better backport
## TODO: Merge the above, or rework the BPF chain(s)

## troika/kane
repopick 442755 # memtrack & FCC
repopick -f 445287 # [DNM] exynos9610: Nuke livedisplay
## TODO: Need to pick kernel backports or merge 4.14-stable (?)
