#!/bin/bash # Stateless script to create stacked patch series (with guilt) on a specified # git repository. # # Used mostly to help with patch maintenance on xfsprogs project. # # The idea is to use it as a hook in neomutt, select a bunch of patches create # stgit series based on those. # # The script relies on b4 tool to create mailboxes from the patches's msg-ids, # and those mboxes sent to stgi to transform them in patch series. #Piped message(s) emails=$2 #Repository to act on REPO="$1" patch=/tmp/$$.patch mbox=/tmp/mutt_mbox.tmp MBOX_DIR=/tmp/MBOX_DIR # Logging IMPORT_LOG=/tmp/$$.import_log #Commands used B4=`which b4` GIT=`which git` GUILT=`which guilt` #Repositories location KERNEL_REPO=$HOME/Source/kernel/linux.pristine XFSPROGS_REPO=$HOME/Source/xfsprogs/xfsprogs-dev.pristine XFSDUMP_REPO=$HOME/Source/xfsdump/xfsdump-dev.pristine cleanup(){ rm -rf $MBOX_DIR rm -rf $IMPORT_LOG rm -rf /tmp/*.error_log } setup(){ if [ -d $MBOX_DIR ]; then mkdir -p $MBOX_DIR fi } # Create multiple mboxes from tagged messages import_from_list(){ ID_LIST=/tmp/$$.idlist ERR_LOG=/tmp/$$_import.error_log cat $emails | grep Message-Id | awk '{print $2}'> $ID_LIST for i in `cat $ID_LIST`; do b4 -q am -t -s -o $MBOX_DIR $i &> $ERR_LOG done rm $ID_LIST } # Import patches from mailboxes into a git branch create_git_branch(){ if [ $REPO == "xfsprogs" ]; then cd $XFSPROGS_REPO elif [ $REPO == "xfsdump" ]; then cd $XFSDUMP_REPO else echo "Invalid repository" exit 1 fi for i in `ls $MBOX_DIR | grep ".mbx"`; do series=$(echo $i | sed 's/.mbx//') ERR_LOG=/tmp/$series.error_log #stack=$(echo $i) echo "=====================" echo "- Applying Series:" echo "$series" echo # Ensure we are at for-next branch, to avoid stacking different # series in the same branch echo "- Creating new Branch:" $GIT checkout -q -B IMPORT_$series >> $ERR_LOG echo echo "- Resetting branch to for-next" $GIT reset -q --hard for-next >> $ERR_LOG #$GIT checkout -q for-next > $ERR_LOG echo echo "- Importing commits" $GIT am $MBOX_DIR/$i 2>> $ERR_LOG >> $IMPORT_LOG #if [ $? != 0 ]; then if [ -s $ERR_LOG ]; then echo "GIT AM ERROR: Failed to import series: $series" #echo "DEBUG: $MBOX_DIR/$i" #echo "DEBUG: $PWD" echo "See: $ERR_LOG" $GIT am --abort >> $IMPORT_LOG continue else echo echo "-= SERIES APPLIED =-" fi done echo echo "- Moving back to master branch..." $GIT checkout -q master >> $ERR_LOG echo echo "-= Job finished =-" echo "=====================" } show_dialog(){ dialog --clear --menu "Select reposiroty" 0 0 20 "kernel" "" "xfsprogs" "" 2>&1 >/dev/tty } # Prog starts here cleanup mkdir $MBOX_DIR import_from_list $emails create_git_branch #create_patch_stacks $XFSPROGS_REPO #create_patch_stacks $XFSDUMP_REPO