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 27, 2017
1 parent 51c0640 commit 23a794a
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 1 deletion.
230 changes: 230 additions & 0 deletions scripts/openzfs-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/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
# [user]
# email = [email protected]
# name = George Melikov
#
# 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] [-c commit hash] [-g commit hash]
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)
-c commit hash Prepare branch and try to merge this commit by hash,
leaves branch for manual merge if not successfull
-g commit hash Generate commit description for existing commit in
branch generated by -i parameter
EOF
}

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

prepare_git() {
cd "$REPOSITORY_PATH"
rm "$TMP_FILE"
git checkout master
git fetch --all
git log --remotes=openzfs/master --format=%B -n 1 $OPENZFS_COMMIT > "$TMP_FILE"
OPENZFS_ISSUE=$(grep -oP '^[^0-9]*\K[0-9]+' -m 1 "$TMP_FILE")
}

generate_desc() {
USER_NAME=$(git config user.name)
USER_MAIL=$(git config user.email)
OPENZFS_COMMIT_AUTHOR=$(git log --format="%aN <%aE>" --remotes=openzfs/master -n 1 $OPENZFS_COMMIT)
sed -i '/^$/d' "$TMP_FILE"
sed -i "1s/^$OPENZFS_ISSUE/OpenZFS $OPENZFS_ISSUE -/" "$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"
}

#add description to commit
add_desc_to_commit() {
git commit --amend -F "$TMP_FILE"
}

merge() {
ERR=0

prepare_git

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
echo $OPENZFS_COMMIT >> "$EXCEPTIONS_GIT"
return 1
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_desc

add_desc_to_commit

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
}

iterate_merge() {
while read p; do
OPENZFS_COMMIT=$p

#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

merge
if [ $? -eq "1" ]; then
clean_unmerged
fi


done <$UNPORTED_COMMITS_FILE
}

prepare_manual() {
merge
echo -e "${LGREEN}-Be ready to run 'git cherry-pick --continue after fixing all merge conflicts!${NORMAL}"
}

while getopts 'hd:i:c:g:' OPTION; do
case $OPTION in
h)
usage
exit 1
;;
d)
REPOSITORY_PATH="$OPTARG"
;;
i)
UNPORTED_COMMITS_FILE=$OPTARG
;;
c)
OPENZFS_COMMIT=$OPTARG
prepare_manual
exit 0
;;
g)
OPENZFS_COMMIT=$OPTARG
prepare_git
git checkout "autoport-oz$OPENZFS_ISSUE"
generate_desc
add_desc_to_commit
exit 0
;;
esac
done

iterate_merge


rm "$TMP_FILE"

#show results
echo ' '
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
10 changes: 9 additions & 1 deletion 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 @@ -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 23a794a

Please sign in to comment.