Michal Suchanek 095106
#!/bin/sh
Michal Suchanek c7715a
Michal Suchanek c7715a
# Especially during feature development it can easily happen that a patch that
Michal Suchanek c7715a
# was added to base branch as fix is added to derived branch as part of a
Michal Suchanek c7715a
# feature by different developer under different name. Merging the base branch
Michal Suchanek c7715a
# then becomes difficult.
Michal Suchanek c7715a
Michal Suchanek c7715a
# This script checks a few patch tags to match patch files across two
Michal Suchanek c7715a
# kernel-source branches and moves patch files in the working tree to match
Michal Suchanek c7715a
# filenames in the branch you specify.
Michal Suchanek c7715a
Michal Suchanek c7715a
# This then allows merging more easily: instead of duplicated patch files that
Michal Suchanek c7715a
# git does not know how to detect you get conflicting added files under same
Michal Suchanek c7715a
# filename which git does point out.
Michal Suchanek c7715a
Michal Suchanek c7715a
# Also if the reference branch contains duplicate files the rename is not
Michal Suchanek c7715a
# stable. That is if you run renamefiles, commit the result, run it again, and
Michal Suchanek c7715a
# there are changes again you have duplicate patches in the reference branch
Michal Suchanek c7715a
# with which you are trying to aling patch names. This can be either false
Michal Suchanek c7715a
# positive because mutiple patch tags are checked or an actual patch that
Michal Suchanek c7715a
# applies indefinitely because it adds the same context it applies to which is
Michal Suchanek c7715a
# applied multiple times.
Michal Suchanek c7715a
Michal Suchanek 095106
if [ $# != 1 ] ; then
Michal Suchanek 095106
	echo Usage: $0 "<branch name>"
Michal Suchanek 095106
	echo Run in kernel-source to rename patches in the current branch to the same filename as they ahve in the given branch.
Michal Suchanek 095106
	exit 1
Michal Suchanek 095106
fi
Michal Suchanek 095106
branch=$1
Michal Suchanek 095106
trap 'rm -f "$temp"' EXIT
Michal Suchanek 095106
temp=$(mktemp)
Michal Koutný 9e1b93
git grep -iE '^(Git-commit:|No-fix:|\(cherry picked from commit)' $branch -- 'patches.*' | tr ':' ' ' | \
Michal Koutný 68e276
		awk '!/patches.kernel.org/ {fn=$2; hash=$NF; map[hash]=map[hash] fn;}
Michal Koutný 68e276
		      END				   { for (hash in map) printf("map[%s]=\"%s\"\n", hash, map[hash]); }' \
Michal Koutný 68e276
		>$temp
Michal Koutný 68e276
Michal Koutný 68e276
declare -A map
Michal Koutný 68e276
source $temp
Michal Suchanek 095106
Michal Koutný 20e6e6
grep -E "^[[:space:]]*patches\.[a-z]+/" < series.conf | while read patch ; do
Michal Koutný c44b59
	[ ! -f "$patch" ] && continue
Michal Koutný c44b59
	commit="$(awk -v IGNORECASE=1 '/^(Git-commit|No-fix):/ { print $2}
Michal Koutný c44b59
	/^\(cherry picked from commit/ { print $5}' $patch)"
Michal Koutný 68e276
	[ -z "$commit" ] && continue
Michal Koutný 68e276
	for fn in ${map[$commit]} ; do
Michal Koutný 68e276
		[ $fn != $patch ] && git mv $patch  $fn && sed -i -e "s,$patch,$fn," series.conf
Michal Koutný 68e276
	done
Michal Suchanek 095106
done