Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Add OpenZFS auto merge script
Browse files Browse the repository at this point in the history
  • Loading branch information
gmelikov committed Jan 25, 2017
1 parent 51c0640 commit a4874a1
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 2 deletions.
178 changes: 178 additions & 0 deletions scripts/openzfs-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/bin/bash
#
# This script tries to merge OpenZFS commits to ZoL.
#
# Instruction:
#
# Repository setup must be similar with openzfs-tracking.sh
# requirements.
#
# Repository setup for valid compilation check:
# sh autogen.sh
# ./configure --enable-debug
#
# mandatory git settings:
# [merge]
# renameLimit = 999999
#
# Copyright (c) 2016 George Melikov. All rights reserved.
#

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

REPOSITORY_PATH='.'
TMP_FILE='/tmp/gittmpmessage.txt'

# list with potential OpenZFS commits
UNPORTED_COMMITS_FILE=$SCRIPTDIR'/hashes.txt'

# Next files will generate automatically
# list with commits git can't merge automatically
EXCEPTIONS_GIT=$SCRIPTDIR'/exceptions.txt'
# list with commits which can't be compiled without errors
EXCEPTIONS_COMPILE=$SCRIPTDIR'/uncompiled.txt'
# list with commits which has cstyle error
EXCEPTIONS_CSTYLE=$SCRIPTDIR'/unsctyled.txt'
# list with merged
EXCEPTIONS_MERGED=$SCRIPTDIR'/merged.txt'

LGREEN='\033[1;32m' # ${LGREEN}
NORMAL='\033[0m' # ${NORMAL}
COUNT_MERGED=0
LIST_MERGED=
COUNT_COMPILE=0
LIST_COMPILE=
COUNT_CSTYLE=0
LIST_CSTYLE=

usage() {
cat << EOF
USAGE:
$0 [-h] [-d directory] [-i commits.txt]
DESCRIPTION:
Auto merge OpenZFS commits to ZFS on Linux git
repositories.
Result - git branch with name 'autoport-oz#issue'
OPTIONS:
-h Show this message
-d directory Git repo with openzfs and zfsonlinux remotes
-i commits.txt File with OpenZFS commit hashes to merge
(one hash per row)
EOF
}

clean_unmerged() {
git cherry-pick --abort
git checkout master
git branch -D "autoport-oz$OPENZFS_ISSUE"
rm "$TMP_FILE"
}

while getopts 'hd:i:' OPTION; do
case $OPTION in
h)
usage
exit 1
;;
d)
REPOSITORY_PATH="$OPTARG"
;;
i)
UNPORTED_COMMITS_FILE=$OPTARG
;;
esac
done

cd "$REPOSITORY_PATH"
USER_NAME=$(git config user.name)
USER_MAIL=$(git config user.email)

while read p; do
OPENZFS_COMMIT=$p
ERR=0
#if commit wasn't tried earlier
EXCEPTION=$(grep -s -E "^$OPENZFS_COMMIT" "$EXCEPTIONS_GIT" "$EXCEPTIONS_COMPILE" "$EXCEPTIONS_CSTYLE" "$EXCEPTIONS_MERGED")
if [ -n "$EXCEPTION" ]; then
continue
fi

#prepare git
git checkout master
git log --remotes=openzfs/master --format=%B -n 1 $OPENZFS_COMMIT > "$TMP_FILE"
OPENZFS_COMMIT_AUTHOR=$(git log --format="%aN <%aE>" --remotes=openzfs/master -n 1 $OPENZFS_COMMIT)
OPENZFS_ISSUE=$(grep -oP '^[^0-9]*\K[0-9]+' -m 1 "$TMP_FILE")

git fetch --all
echo -e "${LGREEN} - OpenZFS issue #$OPENZFS_ISSUE $OPENZFS_COMMIT ${NORMAL}"
echo -e "${LGREEN} Checkout new branch ${NORMAL}"
git branch -D "autoport-oz$OPENZFS_ISSUE"
git checkout -b "autoport-oz$OPENZFS_ISSUE"

echo -e "${LGREEN} Cherry-pick... ${NORMAL}"
if ! git cherry-pick $OPENZFS_COMMIT; then
printf 'cherry-pick failed' >&2
clean_unmerged
echo $OPENZFS_COMMIT >> "$EXCEPTIONS_GIT"
continue
fi

echo -e "${LGREEN} Compile... ${NORMAL}"
if ! make -s -j$(nproc); then
printf 'compilation failed' >&2
echo $OPENZFS_COMMIT >> "$EXCEPTIONS_COMPILE"
COUNT_COMPILE=$(($COUNT_COMPILE+1))
LIST_COMPILE="$LIST_COMPILE
autoport-oz$OPENZFS_ISSUE"
ERR=1
fi

echo -e "${LGREEN} Cstyle... ${NORMAL}"
if ! make cstyle; then
printf 'style check failed' >&2
echo $OPENZFS_COMMIT >> "$EXCEPTIONS_CSTYLE"
COUNT_CSTYLE=$(($COUNT_CSTYLE+1))
LIST_CSTYLE="$LIST_CSTYLE
autoport-oz$OPENZFS_ISSUE"
ERR=1
fi

#generate commit description
sed -i '1s/^/OpenZFS /' "$TMP_FILE"
sed -i 's/ / - /2' "$TMP_FILE"
sed -i "1 a Authored by: $OPENZFS_COMMIT_AUTHOR" "$TMP_FILE"

echo 'Ported-by: '$USER_NAME' <'$USER_MAIL'>' >> "$TMP_FILE"
echo '' >> "$TMP_FILE"
echo 'OpenZFS-issue: https://www.illumos.org/issues/'$OPENZFS_ISSUE >> "$TMP_FILE"
echo 'OpenZFS-commit: https://github.com/openzfs/openzfs/commit/'$OPENZFS_COMMIT >> "$TMP_FILE"
git commit --amend -F "$TMP_FILE"
rm "$TMP_FILE"

if [ "$ERR" -eq "0" ]; then
git push origin "autoport-oz$OPENZFS_ISSUE"
echo $OPENZFS_COMMIT >> $EXCEPTIONS_MERGED
echo -e "${LGREEN} - OpenZFS issue #$OPENZFS_ISSUE $OPENZFS_COMMIT merged without warnings! ${NORMAL}"
COUNT_MERGED=$(($COUNT_MERGED+1))
LIST_MERGED="$LIST_MERGED
autoport-oz$OPENZFS_ISSUE"
fi

done <$UNPORTED_COMMITS_FILE

#show results
echo $COUNT_MERGED
if [ "$COUNT_MERGED" -gt "0" ]; then
echo -e "${LGREEN}-$COUNT_MERGED merged commits without warnings:${NORMAL}"
echo $LIST_MERGED
fi
if [ "$COUNT_COMPILE" -gt "0" ]; then
echo -e "${LGREEN}-$COUNT_COMPILE commits with compile errors:${NORMAL}"
echo $LIST_COMPILE
fi
if [ "$COUNT_CSTYLE" -gt "0" ]; then
echo -e "${LGREEN}-$COUNT_CSTYLE commits with cstyle warnings:${NORMAL}"
echo $LIST_CSTYLE
fi
12 changes: 10 additions & 2 deletions scripts/openzfs-tracking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ OPTIONS:
-h Show this message
-d directory Git repo with openzfs and zfsonlinux remotes
-e exceptions Exception file (using ZoL wiki if not specified)
-c file.txt Write OpenZFS unmerged commits' hashes to file,
if specified (for openzfs-merge.sh)
EXAMPLE:
Expand All @@ -90,7 +92,7 @@ $0 -d ~/openzfs-tracking/zfs \\
EOF
}

while getopts 'hd:e:' OPTION; do
while getopts 'hd:c:e:' OPTION; do
case $OPTION in
h)
usage
Expand All @@ -99,6 +101,9 @@ while getopts 'hd:e:' OPTION; do
d)
ZFSONLINUX_DIR=$OPTARG
;;
c)
HASHES_FILE=$OPTARG
;;
e)
ZFSONLINUX_EXCEPTIONS=$OPTARG
;;
Expand Down Expand Up @@ -234,7 +239,7 @@ do

# Match issue against any open pull requests.
ZFSONLINUX_PR=$(echo $ZFSONLINUX_PRS | jq -r ".[] | select(.title | \
contains(\"OpenZFS $OPENZFS_ISSUE\")) | { html_url: .html_url }" | \
contains(\"OpenZFS $OPENZFS_ISSUE \")) | { html_url: .html_url }" | \
grep html_url | cut -f2- -d':' | tr -d ' "')
ZFSONLINUX_REGEX="^(openzfs|illumos)+.*[ #]+$OPENZFS_ISSUE[ ,]+*.*"

Expand Down Expand Up @@ -283,6 +288,9 @@ do
ZFSONLINUX_HASH=""
ZFSONLINUX_STATUS=$STATUS_MISSING
ZFSONLINUX_STATUS_TEXT=$STATUS_MISSING_TEXT
if [ -n "$HASHES_FILE" ]; then
echo $OPENZFS_HASH >> $HASHES_FILE
fi
fi
fi

Expand Down

0 comments on commit a4874a1

Please sign in to comment.