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

Add OpenZFS auto merge script #51

Merged
merged 1 commit into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be safe to run sh autogen.sh and ./configure for each commit? Is it because Makefile.in's don't often change? There are other .in files as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will we safer, but much more slower.

I didn't have any issues with it yet.

#
# 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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are using a file because it is easier to work with? If so, then this fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was just easier for me.


# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth documenting that this script should be used on a clone where the origin is a fork of ZFS on Linux that has a remote to OpenZFS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already these lines:

# Repository setup must be similar with openzfs-tracking.sh
# requirements.

openzfs-tracking.sh already has there requirements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that. Thanks.

git branch -D "autoport-oz$OPENZFS_ISSUE" > /dev/null
rm "$TMP_FILE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to run a git clean -xdf. This would require you to rerun sh autogen.sh and ./configure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but this variant is faster and it won't remove untracked files.

}

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is --remotes necessary here? The commit hash should be sufficient to find the log entry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just for safety, we use short hashes.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to change this to git branch -D "autoport-oz$OPENZFS_ISSUE" > /dev/null because it displays an error if the branch doesn't exist.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if you should fail if cstyle fails. The patch may work and would involve minor tweaking to address the style problems. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be appropriate to add a flag to the script to control this behavior.

Copy link
Member Author

@gmelikov gmelikov Jan 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought in this way: patch have to be edited -> fail, overwise success.
Yes, it's easy to add a flag, i'll add it.

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