This repository has been archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters