Skip to content
Snippets Groups Projects
dim 27.6 KiB
Newer Older
Simona Vetter's avatar
Simona Vetter committed
#!/bin/bash

# Copyright © 2012-2014 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# Authors:
#    Daniel Vetter <daniel.vetter@ffwll.ch>

# drm-intel-next maintainer script

# TODO
# - Add functions to setup/update all the branches/trees
# - Improve docs/workflow for topic branches
# - extract the integration tree logic and make it generally useful, maybe for a
#   drm-integration tree ...
# - add a Link: tag referring to mid.mail-archive.com/<msg-id> to merged
#   patches
# - Improve nightly-forget to forget a specific merge instead of just the first
#   dinq/dif merge.
Simona Vetter's avatar
Simona Vetter committed

# fail on any goof-up
Simona Vetter's avatar
Simona Vetter committed

# User configuration. Set in environment or configuration file. See
# dimrc.sample for an example.
#

# dim configuration file
DIM_CONFIG=${DIM_CONFIG:-$HOME/.dimrc}
if [ -r $DIM_CONFIG ]; then
    . $DIM_CONFIG
fi

# prefix for repo directories
DIM_PREFIX=${DIM_PREFIX:-$HOME/linux}

# main maintainer repo under $DIM_PREFIX
DIM_DRM_INTEL=${DIM_DRM_INTEL:-src}

# name of the $drm_intel_ssh remote within $DIM_DRM_INTEL
DIM_DRM_INTEL_REMOTE=${DIM_DRM_INTEL_REMOTE:-danvet}

# name of the $drm_upstream_git remote within $DIM_DRM_INTEL
DIM_DRM_UPSTREAM_REMOTE=${DIM_DRM_UPSTREAM_REMOTE:-airlied}

# mail user agent. must support a subset of mutt(1) command line options:
# usage: $DIM_MUA [-s subject] [-i file] [-c cc-addr] to-addr [...]
DIM_MUA=${DIM_MUA:-mutt}

# greetings pull request template
DIM_TEMPLATE_HELLO=${DIM_TEMPLATE_HELLO:-$HOME/.dim.template.hello}

# signature pull request template
DIM_TEMPLATE_SIGNATURE=${DIM_TEMPLATE_SIGNATURE:-$HOME/.dim.template.signature}

Simona Vetter's avatar
Simona Vetter committed
today=`date +%Y-%m-%d`

drm_intel_ssh=ssh://git.freedesktop.org/git/drm-intel
drm_intel_git=git://anongit.freedesktop.org/drm-intel
drm_upstream_git=git://people.freedesktop.org/~airlied/linux
Simona Vetter's avatar
Simona Vetter committed
sound_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
driver_core_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
linux_upstream_git=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Simona Vetter's avatar
Simona Vetter committed

# email aliases
addr_drm_maintainer="Dave Airlie <airlied@gmail.com>"
addr_intel_gfx_maintainer1="Daniel Vetter <daniel.vetter@ffwll.ch>"
addr_intel_gfx_maintainer2="Jani Nikula <jani.nikula@linux.intel.com>"
addr_intel_gfx="intel-gfx@lists.freedesktop.org"
addr_dri_devel="dri-devel@lists.freedesktop.org"
addr_intel_qa1="\"Sun, Yi\" <yi.sun@intel.com>"
addr_intel_qa2="\"Jeff Zheng\" <jeff.zheng@intel.com>"
#
# Command line options.
#

DRY_RUN=
DRY=
Simona Vetter's avatar
Simona Vetter committed
function warn_or_fail
{
	if [[ $FORCE ]] ; then
		echo WARNING: $1, but continuing
	else
		echo ERROR: $1, aborting
		exit 1
	fi
}

while getopts df opt; do
	case "$opt" in
		d)
			DRY_RUN=--dry-run
			DRY=echo
			;;
			echo "Try 'dim help' for more information."
			exit
	esac
done
shift `expr $OPTIND - 1`

# first positional argument is the subcommand
if [ "$#" = "0" ]; then
    subcommand="help"
else
    subcommand="$1"
    shift
fi
Simona Vetter's avatar
Simona Vetter committed
function update_linux_next
{
	cd $DIM_PREFIX/drm-intel-nightly

	# always update drm-intel-fixes
	git push $DRY_RUN origin +origin/drm-intel-fixes:for-linux-next-fixes >& /dev/null

	if git merge-base --is-ancestor origin/drm-intel-next-fixes origin/drm-intel-fixes ; then
		# -fixes has caught up to dinf, i.e. we're out of the merge
		# window. Push the next queue.
		echo Pushing dinq to for-linux-next
		git push $DRY_RUN origin +origin/drm-intel-next-queued:for-linux-next >& /dev/null
Simona Vetter's avatar
Simona Vetter committed
	else
		# dinf is ahead of -fixes, i.e. drm-next has already closed for
		# the next merge window and we've started to gather new fixes
		# for the current -next cycle. Push dinf
		echo Pushing dinf to for-linux-next
		git push $DRY_RUN origin +origin/drm-intel-next-fixes:for-linux-next >& /dev/null
Simona Vetter's avatar
Simona Vetter committed
	fi
}

function check_conflicts
{
	if git diff | grep '\(<<<<<<<\|=======\|>>>>>>>\||||||||\)' ; then
		if [ -n "$1" ]; then
			echo $*
		fi
Simona Vetter's avatar
Simona Vetter committed
		exit 1
	fi
	true
}

function update_rerere_cache
{
	cd $DIM_PREFIX/drm-intel-rerere/
	cp rr-cache/* $DIM_PREFIX/drm-intel-nightly/.git/rr-cache/ -r
	cd -
}

Simona Vetter's avatar
Simona Vetter committed
function update_nightly
{
	local integration_branch=drm-intel-nightly
	local specfile=`mktemp`
	local time="`date --utc +%Yy-%mm-%dd-%Hh-%Mm-%Ss` UTC"
Simona Vetter's avatar
Simona Vetter committed
	local first=1

	local rerere=$DIM_PREFIX/drm-intel-rerere

	cd $rerere
	if [[ `git status --porcelain | grep -v "^[ ?][ ?]" | wc -l` -gt 0 ]]; then
Simona Vetter's avatar
Simona Vetter committed
		warn_or_fail "-nightly configuration file not commited"
	echo -n "Updating rerere cache and nightly.conf... "
	update_rerere_cache >& /dev/null
	echo "Done."

	source $rerere/nightly.conf
	cd $DIM_PREFIX/$integration_branch
	if ! git branch | grep $integration_branch | grep '\*' >& /dev/null ; then
		echo "Branch setup for the integration repo is borked"
		exit 1
	fi

	for remote in $(echo $nightly_branches | tr " " "\n" | sed 's|/.*$||g' | sort -u); do
		echo -n "Fetching $remote... "
		# git fetch returns 128 if there's nothing to be fetched
		git fetch $remote >& /dev/null || true
		echo "Done."
	done
Simona Vetter's avatar
Simona Vetter committed
	# merge -fixes
	for tree in $nightly_branches; do
		local branch=${tree%:*}
		local sha1=${tree#*:}
Simona Vetter's avatar
Simona Vetter committed
		local name=${branch##*/}

		# the : separator is optional
		if [[ $sha1 == $tree ]] ; then
			sha1=
		fi

		echo -n "Merging $branch... "

		if [[ -n $sha1 ]] ; then
			echo -n "Using override sha1: $sha1... "
Simona Vetter's avatar
Simona Vetter committed
		if [ $first == 1 ] ; then
			echo "Reset. Done."
			git reset --hard $sha1 >& /dev/null
Simona Vetter's avatar
Simona Vetter committed
			first=0
		elif git merge --rerere-autoupdate --ff-only $sha1 >& /dev/null ; then
			# nothing to do if just fast-forward
			echo "Fast-forward. Done."
Simona Vetter's avatar
Simona Vetter committed
		else
Simona Vetter's avatar
Simona Vetter committed
			local fixup_file=$rerere/$integration_branch-$name-fixup.patch

			echo $fixup_file > .fixup_file_path

			git merge --rerere-autoupdate --no-commit $sha1 >& /dev/null || true
Simona Vetter's avatar
Simona Vetter committed
			if [ -f $fixup_file ] ; then
				echo -n "Applying manual fixup patch for $integration_branch merge... "
Simona Vetter's avatar
Simona Vetter committed
				patch -p1 -i $fixup_file
Simona Vetter's avatar
Simona Vetter committed
			fi
			check_conflicts "Fail: conflict merging $tree"
Simona Vetter's avatar
Simona Vetter committed
			git add -u

			# because we filter out fast-forward merges there will
			# always be something to commit
			git commit --no-edit --quiet
			echo "Done."
Simona Vetter's avatar
Simona Vetter committed
		fi

		echo -e "$branch `git rev-parse $sha1`\n\t`git log -1 $sha1 --pretty=format:%s`" >> $specfile
Simona Vetter's avatar
Simona Vetter committed
	done

	echo -n "Adding integration manifest $integration_branch: $time... "
Simona Vetter's avatar
Simona Vetter committed
	mv $specfile integration-manifest
	git add integration-manifest
	git commit --quiet -m "$integration_branch: $time integration manifest"
	echo "Done."
Simona Vetter's avatar
Simona Vetter committed

	echo -n "Pushing $integration_branch... "
	git push $DRY_RUN origin +HEAD >& /dev/null && echo "Done."
Simona Vetter's avatar
Simona Vetter committed

	echo -n "Updating rerere cache... "
Simona Vetter's avatar
Simona Vetter committed
	if git branch | grep rerere-cache | grep '\*' >& /dev/null ; then
		git pull >& /dev/null
		cp $DIM_PREFIX/$integration_branch/.git/rr-cache/* rr-cache -r
Simona Vetter's avatar
Simona Vetter committed
		git add *.patch >& /dev/null || true
		git add rr-cache/* > /dev/null
		if git commit -m "$time: $integration_branch rerere cache update" >& /dev/null; then
			echo -n "New commit. "
Simona Vetter's avatar
Simona Vetter committed
		else
			echo -n "Nothing changed. "
Simona Vetter's avatar
Simona Vetter committed
		fi
		echo -n "Pushing rerere cache... "
		git push $DRY_RUN origin HEAD >& /dev/null && echo "Done."
Simona Vetter's avatar
Simona Vetter committed
	else
		echo "Fail: Branch setup for the rerere-cache is borked."
# push branch $1, rebuild nightly. the rest of the arguments are passed to git
# push.
function dim_push
{
	branch=$1
	shift

	assert_branch $branch

	git push $DRY_RUN $DIM_DRM_INTEL_REMOTE $branch "$@"

	update_nightly
	update_linux_next
}

# ensure we're on branch $1, and apply patches. the rest of the arguments are
# passed to git am.
function dim_apply
{
	branch=$1
	shift

	assert_branch $branch

	if [[ -n `git status --porcelain --untracked-files=no` ]] ; then
		echo Repository not clean, aborting
		exit 2
	fi

	git am -3 "$@"
	dim_checkpatch HEAD
	git commit --amend &
}

Simona Vetter's avatar
Simona Vetter committed
function check_repo_clean
{
	cd $1
	if ! git diff-index --quiet HEAD ; then
		echo $2 repo not clean, aborting
		exit 1
	fi

}

# $1 is the git sha1 to check
function dim_checkpatch
Simona Vetter's avatar
Simona Vetter committed
{
	local commit=$1

	git --no-pager log --oneline -1 $commit
	git show $commit --pretty=email | scripts/checkpatch.pl -q --strict - || true
	if git show $commit | grep '^\+.*\WBUG' > /dev/null; then
Simona Vetter's avatar
Simona Vetter committed
		warn_or_fail "New BUG macro added"
	git show $commit | grep '^\+.*drm_i915_private_t' > /dev/null && echo "WARNING: New drm_i915_private_t added" || true
Simona Vetter's avatar
Simona Vetter committed
}

function dim_checkrange
{
	local range

	if [ -z "$1" ]; then
		range="HEAD^..HEAD"
	elif [ -n "`echo $1 | grep '\.\.'`" ]; then
		range="$1"
	else
		range="$1..HEAD"
	fi

	for commit in $(git rev-list --reverse $range); do
		dim_checkpatch $commit || true
	done
}

function prep_pull_mail_greetings
{
	if [ -r $DIM_TEMPLATE_HELLO ]; then
		cat $DIM_TEMPLATE_HELLO
	else
		cat <<-EOF
		Hi Dave,

		EOF
	fi
}

function prep_pull_mail_signature
{
	if [ -r $DIM_TEMPLATE_SIGNATURE ]; then
		cat $DIM_TEMPLATE_SIGNATURE
	else
		cat <<-EOF

		Cheers, Daniel


		EOF
	fi
}

# print pull mail overview based on tags in $@, if any
# without tags, print a reminder
function prep_pull_mail_overview
Simona Vetter's avatar
Simona Vetter committed
{
	if [ "$#" = "0" ]; then
		echo "*** insert pull request overview here ***"
	else
		for tag in $@ ; do
			local obj=`git rev-parse $tag`
			if [[ `git cat-file -t $obj` == "tag" ]] ; then
				echo $tag:
				git cat-file -p $obj | tail -n+6
			fi
		done
	fi
Simona Vetter's avatar
Simona Vetter committed
}

# prepare a pull request mail
# $@: tags, if any, to extract into the pull request overview
Simona Vetter's avatar
Simona Vetter committed
function prep_pull_mail
{
	prep_pull_mail_greetings > ~/tmp/dim-pull-request
	prep_pull_mail_overview $@ >> ~/tmp/dim-pull-request
	prep_pull_mail_signature >> ~/tmp/dim-pull-request
Simona Vetter's avatar
Simona Vetter committed
}

# dim_pull_request branch upstream
function dim_pull_request
{
	branch=$1
	upstream=$2

	git fetch ${upstream%%/*} >& /dev/null || true
	echo "Using $upstream as the upstream"

	if [ "$branch" = "drm-intel-next" ]; then
		# drm-intel-next pulls have been tagged using dim update-next
		drm_intel_next_tags=`git log $DIM_DRM_INTEL_REMOTE/drm-intel-next ^$upstream --decorate | grep "(.*tag: drm-intel-next-" | sed -e "s/^.*(.*tag: \(drm-intel-next-[^ ,]*\).*)$/\1/"`
		prep_pull_mail $drm_intel_next_tags
		tag=`git describe --all --exact $DIM_DRM_INTEL_REMOTE/drm-intel-next`
	else
		tag=$branch-$today
		$DRY git tag -f $tag $DIM_DRM_INTEL_REMOTE/$branch
		$DRY git push -f $DIM_DRM_INTEL_REMOTE $tag
		prep_pull_mail
	fi

	git request-pull $upstream $drm_intel_git $tag >> ~/tmp/dim-pull-request
	$DIM_MUA -s "[PULL] $branch" \
		-i ~/tmp/dim-pull-request \
		-c "$addr_intel_gfx" \
		-c "$addr_dri_devel" \
		-c "$addr_intel_gfx_maintainer1" \
		-c "$addr_intel_gfx_maintainer2" \
		"$addr_drm_maintainer"
}

Simona Vetter's avatar
Simona Vetter committed
function setup_dim
{
Simona Vetter's avatar
Simona Vetter committed

	cd $DIM_DRM_INTEL
	if ! git remote -v | grep "^origin[[:space:]]" | grep $linux_upstream_git > /dev/null; then
		echo "please set up remote origin for $linux_upstream_git"
		exit 1
	fi
	if ! git remote -v | grep "^$DIM_DRM_INTEL_REMOTE[[:space:]]" | grep $drm_intel_ssh > /dev/null; then
		echo "please set up remote $DIM_DRM_INTEL_REMOTE for $drm_intel_ssh (or update config)"
		exit 1
	fi
	if ! git remote -v | grep "^$DIM_DRM_UPSTREAM_REMOTE[[:space:]]" | grep $drm_upstream_git > /dev/null; then
		echo "please set up remote $DIM_DRM_UPSTREAM_REMOTE for $drm_upstream_git (or update config)"
		exit 1
	fi
	cd ..

Simona Vetter's avatar
Simona Vetter committed
	if [ ! -d maintainer-tools ]; then
		git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git $drm_intel_ssh maintainer-tools
Simona Vetter's avatar
Simona Vetter committed
	fi
	cd maintainer-tools
	git config remote.origin.url $drm_intel_ssh
	echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > .git/objects/info/alternates
	git repack -a -d -l
Simona Vetter's avatar
Simona Vetter committed
	if ! git branch | grep maintainer-tools > /dev/null ; then
		git checkout -t origin/maintainer-tools
	fi
	cd ..

	if [ ! -d drm-intel-rerere ]; then
		git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git $drm_intel_ssh drm-intel-rerere
Simona Vetter's avatar
Simona Vetter committed
	fi
	cd drm-intel-rerere
	git config remote.origin.url $drm_intel_ssh
	echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > .git/objects/info/alternates
	git repack -a -d -l
Simona Vetter's avatar
Simona Vetter committed
	if ! git branch | grep rerere-cache > /dev/null ; then
		git checkout -t origin/rerere-cache
	fi
	cd ..

	if [ ! -d drm-intel-nightly ]; then
		git clone --reference=$DIM_PREFIX/$DIM_DRM_INTEL/.git $drm_intel_ssh drm-intel-nightly
Simona Vetter's avatar
Simona Vetter committed
	fi
	cd drm-intel-nightly
	mkdir -p .git/rr-cache
	git config remote.origin.url $drm_intel_ssh
	echo "$DIM_PREFIX/$DIM_DRM_INTEL/.git/objects" > .git/objects/info/alternates
	git repack -a -d -l
	if ! git branch | grep drm-intel-nightly > /dev/null ; then
		git checkout -t origin/drm-intel-nightly
	fi
Simona Vetter's avatar
Simona Vetter committed
	if git remote | grep drm-upstream > /dev/null ; then
		git config remote.drm-upstream.url $drm_upstream_git
	else
		git remote add drm-upstream $drm_upstream_git
	fi
Simona Vetter's avatar
Simona Vetter committed
	if git remote | grep sound-upstream > /dev/null ; then
		git config remote.sound-upstream.url $sound_upstream_git
	else
		git remote add sound-upstream $sound_upstream_git
	fi
	if git remote | grep driver-core-upstream > /dev/null ; then
		git config remote.driver-core-upstream.url $driver_core_upstream_git
	else
		git remote add driver-core-upstream $driver_core_upstream_git
	fi
Simona Vetter's avatar
Simona Vetter committed
}

function assert_branch
{
	local branch=$1
	if git branch | grep $branch | grep '\*' ; then
		return 0
	else
		echo "You're on the wrong branch, expected $branch"
		return 1
	fi
if [ ! -d $DIM_PREFIX/$DIM_DRM_INTEL ]; then
	echo "please set up your maintainer linux repository at"
	echo "$DIM_PREFIX/$DIM_DRM_INTEL (or check your config)"
	exit 1
fi

cd $DIM_PREFIX/$DIM_DRM_INTEL
Simona Vetter's avatar
Simona Vetter committed

case "$subcommand" in
Simona Vetter's avatar
Simona Vetter committed
	setup)
		setup_dim
		;;
	nightly-forget)
		cd $DIM_PREFIX/drm-intel-nightly
Simona Vetter's avatar
Simona Vetter committed
		git fetch origin >& /dev/null
		git reset --hard origin/drm-intel-next-queued >& /dev/null
		git merge origin/drm-intel-fixes
		git rerere forget
		;;
	update-branches|ub)
		check_repo_clean $DIM_PREFIX/$DIM_DRM_INTEL Kernel
Simona Vetter's avatar
Simona Vetter committed
		dim co
		git rebase -i
Simona Vetter's avatar
Simona Vetter committed
		dim cof
		git rebase -i
		dim conf
		git rebase -i
Simona Vetter's avatar
Simona Vetter committed
		git checkout drm-intel-next
		git reset --hard $DIM_DRM_INTEL_REMOTE/drm-intel-next
Simona Vetter's avatar
Simona Vetter committed
		# TODO: Restore -nightly merge state from the rerere-cache
		# branch
Simona Vetter's avatar
Simona Vetter committed
		;;
	rebuild-nightly)
		update_nightly
		;;
Simona Vetter's avatar
Simona Vetter committed
	cat-to-fixup)
		cd $DIM_PREFIX/drm-intel-nightly
		cat > `cat .fixup_file_path`
		;;
Simona Vetter's avatar
Simona Vetter committed
	push-queued|pq)
		dim_push drm-intel-next-queued "$@"
Simona Vetter's avatar
Simona Vetter committed
		;;
	push-next-fixes|pnf)
		dim_push drm-intel-next-fixes "$@"
Simona Vetter's avatar
Simona Vetter committed
	push-fixes|pf)
		dim_push drm-intel-fixes "$@"
Simona Vetter's avatar
Simona Vetter committed
		;;
	co)
		git checkout drm-intel-next-queued
		;;
	cof)
		git checkout drm-intel-fixes
		;;
	conf)
		git checkout drm-intel-next-fixes
		;;
	apply-branch|ab|sob)
Simona Vetter's avatar
Simona Vetter committed
		;;
	apply-queued|aq)
		dim_apply drm-intel-next-queued "$@"
Simona Vetter's avatar
Simona Vetter committed
		;;
	apply-fixes|af)
		dim_apply drm-intel-fixes "$@"
Simona Vetter's avatar
Simona Vetter committed
		;;
	apply-next-fixes|anf)
		dim_apply drm-intel-next-fixes "$@"
Simona Vetter's avatar
Simona Vetter committed
	apply-resolved|ar)
		make -j 20 && git add -u && git am --resolved
		dim_checkpatch HEAD
		git commit --amend &
Simona Vetter's avatar
Simona Vetter committed
		;;
	apply-igt|ai)
		cd ~/xorg/intel-gpu-tools/
		git am -3 -s
		;;
	magic-patch|mp)
		conflict_files=`patch -p1 | grep "saving rejects" | sed -e "s/.*saving rejects to file \(.*\)/\1/"`

		if [[ $conflict_files != "" ]] ; then
			echo conflicts found!
		fi

		for file in $conflict_files ; do
			echo wiggling in ${file%.rej}:
			#cat $file
			rm -f ${file%.rej}.porig
			wiggle -r ${file%.rej} $file || true
		done
		;;
	magic-rebase-resolve|mrr)
		git diff HEAD | patch -p1 -R
		cat .git/rebase-merge/patch | dim mp
		make -j 20
		git add -u
		git rebase --continue
		;;
	tc)
		git tag --contains $1 | grep ^v | sort -V | head -n 1
Simona Vetter's avatar
Simona Vetter committed
		;;
	check-patch|cp)
Simona Vetter's avatar
Simona Vetter committed
		;;
	cherry-pick)
		if [[ "x$1" = "x" ]]; then
			echo "usage: $0 $subcommand commit-ish"
			exit 1
		fi
		sha=`git rev-parse $1`
		sha_short=${sha:0:8}

		# need latest -nightly
		git fetch $DIM_DRM_INTEL_REMOTE
		echo Possible fixup patches for your cherry-pick:
		git log --grep=$sha_short --pretty=oneline $sha..$DIM_DRM_INTEL_REMOTE/drm-intel-nightly
		$DRY git cherry-pick $1
		;;
Simona Vetter's avatar
Simona Vetter committed
	pull-request)
		if [[ "x$1" = "x" || "x$2" = "x" ]]; then
			echo "usage: $0 $subcommand branch upstream"
			exit 1
		fi
		dim_pull_request $*
		;;
	pull-request-next)
		upstream=${1:-$DIM_DRM_UPSTREAM_REMOTE/drm-next}
		dim_pull_request drm-intel-next $upstream
Simona Vetter's avatar
Simona Vetter committed
		;;
	pull-request-fixes)
		upstream=${1:-origin/master}
		dim_pull_request drm-intel-fixes $upstream
Simona Vetter's avatar
Simona Vetter committed
		;;
		upstream=${1:-$DIM_DRM_UPSTREAM_REMOTE/drm-next}
		dim_pull_request drm-intel-next-fixes $upstream
		;;
Simona Vetter's avatar
Simona Vetter committed
	update-next)
		assert_branch drm-intel-next-queued
		git fetch $DIM_DRM_INTEL_REMOTE
		if ! git branch --merged $DIM_DRM_INTEL_REMOTE/drm-intel-nightly | grep drm-intel-fixes &> /dev/null ; then
Simona Vetter's avatar
Simona Vetter committed
			echo "drm-intel-fixes not merged into -nigthly, please update!"
			exit 2
		fi
		if ! git branch --merged $DIM_DRM_INTEL_REMOTE/drm-intel-nightly | grep drm-intel-next-queued &> /dev/null ; then
Simona Vetter's avatar
Simona Vetter committed
			echo "drm-intel-next-queued not merged into -nigthly, please update!"
			exit 2
		fi

		driver_date=`date +%Y%m%d`
Simona Vetter's avatar
Simona Vetter committed
		$DRY sed -i -e "s/^#define DRIVER_DATE.*\"[0-9]*\"$/#define DRIVER_DATE\t\t\"$driver_date\"/" \
			drivers/gpu/drm/i915/i915_drv.h
Simona Vetter's avatar
Simona Vetter committed
		$DRY git add drivers/gpu/drm/i915/i915_drv.h
		echo -e "drm/i915: Update DRIVER_DATE to $driver_date\n\nSigned-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>" | \
			git commit -s -F -

		gitk drm-intel-next-queued ^$DIM_DRM_UPSTREAM_REMOTE/drm-next &
Simona Vetter's avatar
Simona Vetter committed

Simona Vetter's avatar
Simona Vetter committed
		$DRY git push $DRY_RUN $DIM_DRM_INTEL_REMOTE drm-intel-next-queued:drm-intel-next
Simona Vetter's avatar
Simona Vetter committed
		tag=drm-intel-next-$today
		$DRY git tag -f -a $tag $DIM_DRM_INTEL_REMOTE/drm-intel-next
Simona Vetter's avatar
Simona Vetter committed
		$DRY git push $DRY_RUN -f $DIM_DRM_INTEL_REMOTE $tag
Simona Vetter's avatar
Simona Vetter committed

		echo "Updating -testing to latest -nightly"
Simona Vetter's avatar
Simona Vetter committed
		$DRY git push $DRY_RUN $DIM_DRM_INTEL_REMOTE +$DIM_DRM_INTEL_REMOTE/drm-intel-nightly:drm-intel-testing
		$DRY git tag -f drm-intel-testing-$today $DIM_DRM_INTEL_REMOTE/drm-intel-testing
		$DRY git push -f $DIM_DRM_INTEL_REMOTE drm-intel-testing-$today
Simona Vetter's avatar
Simona Vetter committed

		cat > ~/tmp/test-request <<-HERE
		Hi all,

		New -testing cycle with cool stuff:
		HERE
		obj=`git rev-parse $tag`
		if [[ `git cat-file -t $obj` == "tag" ]] ; then
			git cat-file -p $obj | tail -n+6 >> ~/tmp/test-request
		else
			echo "<tag doesn't contain a changelog overview, fix this>" >> ~/tmp/test-request
		fi
		cat >> ~/tmp/test-request <<-HERE

		Happy testing!

		Cheers, Daniel
		HERE

		$DIM_MUA -s "Updated drm-intel-testing" \
			-i ~/tmp/test-request \
			-c "$addr_intel_gfx" \
			-c "$addr_intel_gfx_maintainer1" \
			-c "$addr_intel_gfx_maintainer2" \
			"$addr_intel_qa1" \
			"$addr_intel_qa2"
Simona Vetter's avatar
Simona Vetter committed
		;;
Simona Vetter's avatar
Simona Vetter committed
	tag-next)
		cd $DIM_PREFIX/$DIM_DRM_INTEL
		git fetch $DIM_DRM_INTEL_REMOTE

		if [ $(git rev-parse drm-intel-next) == $(git rev-parse drm-intel-next@{u}) ] ; then
			echo "Tagging current drm-intel-next"

			tag=drm-intel-next-$today
			$DRY git tag -f $tag $DIM_DRM_INTEL_REMOTE/drm-intel-next
			$DRY git push $DRY_RUN -f $DIM_DRM_INTEL_REMOTE $tag
		else
			echo "drm-intel-next not up-to-date, aborting"
			exit
		fi

		;;
	create-branch)
		if [[ "x$1" = "x" ]]; then
			echo "usage: $0 $subcommand branch [commit-ish]"
			exit 1
		fi
		branch=$1
		if [[ "x$2" = "x" ]]; then
			start=HEAD
		else
			start=$2
		fi
		git branch $branch $start
		git push $DRY_RUN $DIM_DRM_INTEL_REMOTE +$branch --set-upstream
		cd $DIM_PREFIX/drm-intel-rerere
		echo "nightly_branches=\"\$nightly_branches origin/$branch\"" \
			>> nightly.conf
		git add nightly.conf
		git commit --quiet -m "Adding $branch to -nightly"
		;;
	remove-branch)
		if [[ "x$1" = "x" ]]; then
			echo "usage: $0 $subcommand branch"
			exit 1
		fi
		branch=$1
		if ! git branch -d $branch ; then
			warn_or_fail "Can't remove $branch in working repo"
		fi
		cd $DIM_PREFIX/drm-intel-nightly
		git push $DRY_RUN origin --delete $branch
		git fetch origin --prune
		cd $DIM_PREFIX/drm-intel-rerere
		full_branch="origin/$branch"
		sed -e "/${full_branch//\//\\\/}/d" -i nightly.conf
		git add nightly.conf
		git commit --quiet -m "Deleted $branch and removed from -nightly"
Simona Vetter's avatar
Simona Vetter committed
	checker)
		rm drivers/gpu/drm/i915/*.o &> /dev/null || true
		rm drivers/gpu/drm/i915/*.ko &> /dev/null || true
		make C=1 drivers/gpu/drm/i915/i915.ko
		;;
	*)
		if hash rst2man 2>/dev/null; then
			renderer=rst2man
			pager="man -l -"
		else
			renderer=cat
			pager=${PAGER:-cat}
		fi
		$renderer <<HERE | $pager
=====
 dim
=====
Simona Vetter's avatar
Simona Vetter committed

---------------------------
drm-intel maintainer script
---------------------------
Simona Vetter's avatar
Simona Vetter committed

:Author: Daniel Vetter <daniel.vetter@ffwll.ch>
:Author: Jani Nikula <jani.nikula@intel.com>
:Date: 2014-05-15
:Copyright: 2012-2014 Intel Corporation
:Manual section: 1
:Manual group: maintainer tools
Simona Vetter's avatar
Simona Vetter committed

Simona Vetter's avatar
Simona Vetter committed

**dim** [*option* ...] *command*

DESCRIPTION
===========

drm-intel maintainer script.

OPTIONS
=======

-f		Ignore some error conditions.
-d		Dry run.

COMMANDS
========

setup *prefix*
--------------
Setup git maintainer branches in the given prefix.

nightly-forget
--------------
Forget git rerere solutions for nightly merges in case they
contain a bogus merge resolution.

update-branches
---------------
Updates all maintainer branches. Only needs to be run to synchronize branches
between different machines (or maintainers fwiw). As long a given branch is
always maintained from the same machine, even if different branches are
maintained on different machines (by different maintainers), there's no need to
run this command.

rebuild-nightly
---------------
Rebuilds the nightly branch. Useful when ad-hoc trees are
included in -nightly.

Simona Vetter's avatar
Simona Vetter committed
cat-to-fixup
------------

Pipes stdin into the fixup patch file for the current -nightly merge.

push-fixes|pf [*git push arguments*]
------------------------------------

push-next-fixes|pnf [*git push arguments*]
------------------------------------------

push-queued|pq [*git push arguments*]
-------------------------------------

Updates the drm-intel-fixes, drm-intel-next-fixes or the drm-intel-next-queued
branch respectively. Complains if that's not the current branch, assuming that
patches got merged to the wrong branch.

conf
----
Checks out the drm-intel-fixes branch, dinf or dinq respectively for merging
patches.
apply-branch|ab|sob branch [*git am arguments*]
-----------------------------------------------
Applys a patch to the given branch, complaining if it is not
checked out yet.

apply-fixes|af [*git am arguments*]
-----------------------------------

apply-next-fixes|anf [*git am arguments*]
-----------------------------------------

apply-queued|aq [*git am arguments*]
------------------------------------
Applies a patch to -fixes, -next-fixes or -next-queued respectively, complains
if it's not the right branch. Additional arguments are passed to git am.

magic-patch|mp
--------------
Apply a patch using patch and then wiggle in any conflicts.

magic-rebase-resolve|mrr
------------------------
Tries to resolve a rebase conflict by first resetting the tree
and the using the magic patch tool. Then builds the tree, adds
any changes with git add -u and continues the rebase.

apply-resolved|ar
-----------------
Compile-test the current tree and if successfully resolve a
confilicted git am. Also runs the patch checker afterwards.

apply-igt|ai
------------
Apply a patch to the i-g-t repository.

tc *commit-ish*
---------------
Prints the linux kernel tag which contains the supplied commit-ish

check-patch|cp [*commit-ish* [.. *commit-ish*]]
-----------------------------------------------
Runs the given commit range commit-ish..commit-ish through the check tools. If
no commit-ish is passed, defaults to HEAD^..HEAD. If one commit-ish is passed
instead of a range, the range commit-ish..HEAD is used.
cherry-pick *commit-ish* [*git cherry-pick arguments*]
------------------------------------------------------

Improved git cherry-pick version which also scans drm-intel-nightly for any
mentions of the cherry-picked commit. Should be used when cherry-pick from -next
to -fixes to make sure all fixups are picked, too. In dry-run mode/-d only the
patch list is generated.

pull-request *branch* *upstream*
--------------------------------
Fetch the *upstream* remote to make sure it's up-to-date, create and push a date
based tag for the *branch*, generate a pull request template with the specified
*upstream*, and finally start \$DIM_MUA with the template with subject and
recipients already set.

Since the tag for the *branch* is date based, the pull request can be
regenerated with the same commands if something goes wrong.

pull-request-fixes [*upstream*]
-------------------------------
This is a special case of **pull-request**, with *drm-intel-fixes* as the
branch and *origin/master* as the default upstream.
pull-request-next-fixes [*upstream*]
------------------------------------
This is a special case of **pull-request**, with *drm-intel-next-fixes* as
the branch and *\$DRM_UPSTREAM/drm-next* as the default upstream.

pull-request-next [*upstream*]
------------------------------
This is similar to **pull-request**, but for feature pull requests, with
*drm-intel-next* as the branch and *\$DRM_UPSTREAM/drm-next* as the default
upstream.

The difference to **pull-request** is that this command does not generate a
tag; this must have been done previously using **update-next**. This also means
that the pull request can be regenerated with the same commands if something
goes wrong.

update-next
-----------
Pushes out the latest dinq to drm-intel-next and tags it. Also
pushes out the latest nightly to drm-intel-testing. For an
overview a gitk view of the currently unmerged feature pile is
opened.

Also checks that the drm-intel-fixes|-next-queued are fully
merged into -nightly to avoid operator error.

Simona Vetter's avatar
Simona Vetter committed
tag-next
--------

Pushes a new tag for the current drm-intel-next state after checking that the
remote is up-to-date. Useful if drm-intel-next has been changed since the last
run of the update-next command (e.g. to apply a hotfix before sending out the
pull request).

checker
-------
Run sparse on the kernel.
create-branch *branch* [*commit-ish*]
-------------------------------------

Create a new topic branch with the given name. Note that topic/ is not
automatically prepended. The branch starts at HEAD or the given commit-ish.

remove-branch *branch*
----------------------

Remove the given topic branch.

help
----
Show this help. Install **rst2man(1)** for best results.