<commit_before>#!/bin/bash
#
# Compares local branch of crowbar and barclamps repositories with upstream
# using 'git cherry -v'.  Run with --help for help.

compare () {
    local="$1"
    upstream="$2"
    subbranch="$3"
    name="$4"

    if ! git cat-file -e $upstream/$subbranch >&/dev/null; then
        echo "$upstream/$subbranch does not exist in $name" >&2
        return 1
    fi
    git cherry -v $upstream/$subbranch $local/$subbranch
    #git --no-pager log --no-merges --pretty=format:%H $upstream..$local
}

get_barclamps () {
    # This only works if we have the right branch checked out ...
    #git submodule --quiet foreach 'echo $toplevel ${name#barclamps/}'

    # ... so hardcode the list of barclamps we care about:
    for bc in \
        ceph cinder crowbar database deployer dns ganglia git glance \
        ipmi keystone kong logging mysql nagios network nova \
        nova_dashboard ntp openstack postgresql provisioner \
        quantum swift tempest test
    do
        echo `pwd` $bc
    done
}

me=`basename $0`

usage () {
    # Call as: usage [EXITCODE] [USAGE MESSAGE]
    exit_code=1
    if [[ "$1" == [0-9] ]]; then
        exit_code="$1"
        shift
    fi
    if [ -n "$1" ]; then
        echo "$*" >&2
        echo
    fi

    cat <<EOF >&2
Usage: $me [SUB-BRANCH [LOCAL [UPSTREAM]]]

Compares local branch of crowbar and barclamps repositories with upstream
using 'git cherry -v'.  Commits missing from upstream are prefixed with
a plus (+) symbol, and commits with an equivalent change already upstream
are prefixed with a minus (-) symbol.

Must be run from the top-level crowbar repository.

LOCAL is the local feature "super-branch" to compare [$DEFAULT_LOCAL]
UPSTREAM is the upstream feature "super-branch" to compare [$DEFAULT_UPSTREAM]
SUB-BRANCH is the sub-branch of the crowbar "super-branch" to compare [$DEFAULT_SUB_BRANCH]
EOF
    exit "$exit_code"
}

DEFAULT_SUB_BRANCH=openstack-os-build
DEFAULT_LOCAL=release/essex-hack-suse
DEFAULT_UPSTREAM=origin/release/essex-hack

if [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ $# -gt 3 ]; then
    usage 0
fi


if ! [ -f dev ]; then
    echo "You must run this from the top of the crowbar tree; aborting." >&2
    exit 1
fi

local=${2:-$DEFAULT_LOCAL}
upstream=${3:-$DEFAULT_UPSTREAM}

echo -e "\e[0;1mComparing top-level crowbar repo with upstream ...\e[0m"
compare $local $upstream ${1:-$DEFAULT_SUB_BRANCH} 'top-level crowbar repo'

get_barclamps | while read toplevel name; do
    if ! cd $toplevel/barclamps/$name; then
        echo -e "\n\e[1;33m$name barclamp not found; skipping.\e[0m"
        continue
    fi

    echo -e "\n\e[0;1mComparing $name barclamp with upstream ...\e[0m"
    compare $local $upstream master "$name barclamp"
done<commit_msg>toplevel only needs to be set once<commit_after>#!/bin/bash
#
# Compares local branch of crowbar and barclamps repositories with upstream
# using 'git cherry -v'.  Run with --help for help.

compare () {
    local="$1"
    upstream="$2"
    subbranch="$3"
    name="$4"

    if ! git cat-file -e $upstream/$subbranch >&/dev/null; then
        echo "$upstream/$subbranch does not exist in $name" >&2
        return 1
    fi
    git cherry -v $upstream/$subbranch $local/$subbranch
    #git --no-pager log --no-merges --pretty=format:%H $upstream..$local
}

get_barclamps () {
    # This only works if we have the right branch checked out ...
    #git submodule --quiet foreach 'echo ${name#barclamps/}'

    # ... so hardcode the list of barclamps we care about:
    for bc in \
        ceph cinder crowbar database deployer dns ganglia git glance \
        ipmi keystone kong logging mysql nagios network nova \
        nova_dashboard ntp openstack postgresql provisioner \
        quantum swift tempest test
    do
        echo $bc
    done
}

me=`basename $0`

usage () {
    # Call as: usage [EXITCODE] [USAGE MESSAGE]
    exit_code=1
    if [[ "$1" == [0-9] ]]; then
        exit_code="$1"
        shift
    fi
    if [ -n "$1" ]; then
        echo "$*" >&2
        echo
    fi

    cat <<EOF >&2
Usage: $me [SUB-BRANCH [LOCAL [UPSTREAM]]]

Compares local branch of crowbar and barclamps repositories with upstream
using 'git cherry -v'.  Commits missing from upstream are prefixed with
a plus (+) symbol, and commits with an equivalent change already upstream
are prefixed with a minus (-) symbol.

Must be run from the top-level crowbar repository.

LOCAL is the local feature "super-branch" to compare [$DEFAULT_LOCAL]
UPSTREAM is the upstream feature "super-branch" to compare [$DEFAULT_UPSTREAM]
SUB-BRANCH is the sub-branch of the crowbar "super-branch" to compare [$DEFAULT_SUB_BRANCH]
EOF
    exit "$exit_code"
}

DEFAULT_SUB_BRANCH=openstack-os-build
DEFAULT_LOCAL=release/essex-hack-suse
DEFAULT_UPSTREAM=origin/release/essex-hack

if [ "$1" == '-h' ] || [ "$1" == '--help' ] || [ $# -gt 3 ]; then
    usage 0
fi


if ! [ -f dev ]; then
    echo "You must run this from the top of the crowbar tree; aborting." >&2
    exit 1
fi

toplevel=`pwd`

local=${2:-$DEFAULT_LOCAL}
upstream=${3:-$DEFAULT_UPSTREAM}

echo -e "\e[0;1mComparing top-level crowbar repo with upstream ...\e[0m"
compare $local $upstream ${1:-$DEFAULT_SUB_BRANCH} 'top-level crowbar repo'

get_barclamps | while read name; do
    if ! cd $toplevel/barclamps/$name; then
        echo -e "\n\e[1;33m$name barclamp not found; skipping.\e[0m"
        continue
    fi

    echo -e "\n\e[0;1mComparing $name barclamp with upstream ...\e[0m"
    compare $local $upstream master "$name barclamp"
done
{'fraction_non_alphanumeric': 0.12039045553145336, 'fraction_numerical': 0.012292118582791034, 'mean_word_length': 2.9863112391930837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6522037', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1832, 'n_words': 631}