-
Notifications
You must be signed in to change notification settings - Fork 29
Add OpenZFS auto merge script #51
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are already these lines:
openzfs-tracking.sh already has there requirements. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to run a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to change this to |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.