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

# Copyright © 2012-2016 Intel Corporation
Simona Vetter's avatar
Simona Vetter committed
#
# 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>
#    Jani Nikula <jani.nikula@intel.com>
Simona Vetter's avatar
Simona Vetter committed

# drm-intel-next maintainer script

# 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}

# 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}

# make options (not used for C=1)
DIM_MAKE_OPTIONS=${DIM_MAKE_OPTIONS:--j20}

# command to run after dim apply
DIM_POST_APPLY_ACTION=${DIM_POST_APPLY_ACTION:-}

# 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_tip_ssh=ssh://git.freedesktop.org/git/drm-tip
drm_upstream_git=git://people.freedesktop.org/~airlied/linux
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_qa="\"Christophe Prigent\" <christophe.prigent@intel.com>"
# integration configuration
integration_config=nightly.conf

function read_integration_config
{
	# clear everything first to allow configuration reload
	unset drm_tip_repos drm_tip_config
	declare -g -A drm_tip_repos
	declare -g -a drm_tip_config

	if [ -r $DIM_PREFIX/drm-rerere/$integration_config ]; then
		source $DIM_PREFIX/drm-rerere/$integration_config
	fi

	dim_branches=
	for conf in "${drm_tip_config[@]}"; do
		local repo branch override
		read repo branch override <<< $conf
		if [[ "$repo" = "drm-intel" || "$repo" = "drm-misc" ]]; then
			dim_branches="$dim_branches $branch"
		fi
	done
}
read_integration_config

#
# Command line options.
#

DRY_RUN=
Simona Vetter's avatar
Simona Vetter committed
INTERACTIVE=
Simona Vetter's avatar
Simona Vetter committed
function warn_or_fail
{
	if [[ $FORCE ]] ; then
		echoerr "WARNING: $1, but continuing"
Simona Vetter's avatar
Simona Vetter committed
	else
		echoerr "ERROR: $1, aborting"
	case "$opt" in
		d)
			DRY_RUN=--dry-run
			DRY=echo
			;;
Simona Vetter's avatar
Simona Vetter committed
		i)
			INTERACTIVE='eval read -rsp "Press any key to continue..." -n1 key2; echo'
			;;
			echoerr "See '$dim help' for more information."
			exit
	esac
done
shift `expr $OPTIND - 1`

# first positional argument is the subcommand
if [ -n "$HELP" -o "$#" = "0" ]; then
else
    subcommand="$1"
    shift
fi
if [ "$subcommand" != "setup" -a "$subcommand" != "help" -a "$subcommand" != "usage" ]; then
	for d in $DIM_PREFIX $DIM_PREFIX/$DIM_DRM_INTEL $DIM_PREFIX/drm-rerere $DIM_PREFIX/drm-tip; do
		if [ ! -d $d ]; then
			echo "$d is missing, please check your configuration and/or run dim setup"
			exit 1
		fi
	done
#
# Variable naming convetion:
#
# repo:
#	symbolic git repository name from $integration_config
# remote:
#	local remote name in the git repository for the current path
# branch:
#	git branch name - dim assumes that the remote and local name match
# url:
#	url to a repo, using ssh:// protocol
# git_url:
#	url to a repo, but using anonymous git:// protocol
#
# The below functions map between these.
#

function url_to_remote # url
	if [[ -z "$url" ]]; then
		echoerr "$0 without url"
		exit 1
	fi

	remote=$(git remote -v | grep -m 1 "$url" | cut -f 1)

	if [[ -z "$remote" ]]; then
		echoerr "No git remote for url $url found in $(pwd)"
		echoerr "Please set it up using:"
		echoerr "    $ git remote add <name> $url"
		echoerr "with a name of your choice."
		exit 1
	fi

	echo $remote
}
function branch_to_remote # branch
{
	local remote

	remote=`git rev-parse --abbrev-ref --symbolic-full-name $1@{upstream}`
	remote=${remote%%/*}

	echo $remote
}

function repo_to_remote # repo
{
	url_to_remote ${drm_tip_repos[$1]}
}

function branch_to_repo # branch
{
	for conf in "${drm_tip_config[@]}"; do
		local repo branch override
		read repo branch override <<< $conf

		if [[ $branch == $1 ]] ; then
			echo $repo
		fi
	done

	echo ""
}

function dim_uptodate
{
	local using

	using="${BASH_SOURCE[0]}"

	if [[ ! -e "$using" ]]; then
		echoerr "could not figure out the version being used ($using)."
		exit 1
	fi

	if [[ ! -e "$DIM_PREFIX/maintainer-tools/.git" ]]; then
		echoerr "could not find the upstream repo for $dim."
	if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show @{upstream}:dim |\
			diff "$using" - >& /dev/null; then
		echoerr "not running upstream version of the script."
if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
        dim_uptodate
fi

# get message id from file
# $1 = file
message_get_id ()
{
	python <<EOF
from email.parser import Parser
headers = Parser().parse(open('$1', 'r'))
message_id = headers['message-id']
if message_id is not None:
    print(message_id.strip('<>'))
EOF
}

# append all arguments as tags at the end of the commit message of HEAD
function dim_commit_add_tag
	for arg; do
		# the first sed deletes all trailing blank lines at the end
		git log -1 --pretty=%B | \
			sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | \
			sed "\$a${arg}" | \
			git commit --amend -F-
	done

# update for-linux-next and for-linux-next-fixes branches
function update_linux_next # branch next next-fixes fixes
Simona Vetter's avatar
Simona Vetter committed
{
	local branch linux_next linux_next_fixes linux_fixes repo remote

	cd $DIM_PREFIX/drm-tip
	branch=$1
	linux_next=$2
	linux_next_fixes=$3
	linux_fixes=$4
	repo=`branch_to_repo $branch`

	if [[ $repo != `branch_to_repo $linux_next` ]] ; then
		return
	fi

	remote=`repo_to_remote $repo`
	# always update drm-intel-fixes
	echo -n "Pushing $linux_fixes to for-linux-next-fixes... "
	git push $DRY_RUN $remote +$remote/$linux_fixes:for-linux-next-fixes # >& /dev/null
	if git merge-base --is-ancestor $remote/$linux_next_fixes $remote/$linux_fixes ; then
		# -fixes has caught up to dinf, i.e. we're out of the merge
		# window. Push the next queue.
		echo -n "Out of merge window. Pushing $linux_next to for-linux-next... "
		git push $DRY_RUN $remote +$remote/$linux_next: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 -n "Pushing $linux_next_fixes to for-linux-next... "
		git push $DRY_RUN $remote +$remote/$linux_next_fixes:for-linux-next >& /dev/null
Simona Vetter's avatar
Simona Vetter committed
	fi
}

function check_conflicts # tree
Simona Vetter's avatar
Simona Vetter committed
{
Simona Vetter's avatar
Simona Vetter committed
	if git diff | grep -q '\(<<<<<<<\|=======\|>>>>>>>\||||||||\)' ; then
		# we need an empty line to make it look pretty
		echoerr ""
		echoerr "FAILURE: Could not merge $1"
		echoerr "See the section \"Resolving Conflicts when Rebuilding drm-tip\""
		echoerr "in the drm-intel.rst documentation for how to handle this situation."
Simona Vetter's avatar
Simona Vetter committed
		exit 1
	fi
	true
}

function rr_cache_dir
{
Simona Vetter's avatar
Simona Vetter committed
	if [ -d $DIM_PREFIX/drm-tip/.git/ ] ; then
		echo $DIM_PREFIX/drm-tip/.git/rr-cache/
	else
		echo $DIM_PREFIX/$DIM_DRM_INTEL/.git/rr-cache/
	fi
}

function update_rerere_cache
{
	cd $DIM_PREFIX/drm-rerere/
Simona Vetter's avatar
Simona Vetter committed
	mkdir `rr_cache_dir` &> /dev/null || true
	cp rr-cache/* `rr_cache_dir` -r
	cd - > /dev/null
Simona Vetter's avatar
Simona Vetter committed
function dim_revert_rerere
{
	cd $DIM_PREFIX/drm-rerere/
Simona Vetter's avatar
Simona Vetter committed
	git revert $1
	rm `rr_cache_dir`/* -Rf
dim_alias_rebuild_nightly=rebuild-tip
function dim_rebuild_tip
Simona Vetter's avatar
Simona Vetter committed
{
	local integration_branch specfile time first rerere repo url remote
Simona Vetter's avatar
Simona Vetter committed

	integration_branch=drm-tip
	specfile=`mktemp`
	time="`date --utc +%Yy-%mm-%dd-%Hh-%Mm-%Ss` UTC"
	first=1

	rerere=$DIM_PREFIX/drm-rerere
	if [[ `git status --porcelain | grep -v "^[ ?][ ?]" | wc -l` -gt 0 ]]; then
		warn_or_fail "integration configuration file $integration_config not commited"
	echo -n "Updating rerere cache... "
	update_rerere_cache >& /dev/null
	echo "Done."

	echo -n "Reloading $integration_config... "
	echo "Done."
	cd $DIM_PREFIX/$integration_branch
Simona Vetter's avatar
Simona Vetter committed
	if ! git branch --list $integration_branch | grep -q '\*' ; then
		echo "Branch setup for the integration repo is borked"
		exit 1
	fi

	for repo in "${!drm_tip_repos[@]}"; do
		url=${drm_tip_repos[$repo]}
		remote=$(url_to_remote $url)
		echo -n "Fetching $repo (as $remote) ... "
		# git fetch returns 128 if there's nothing to be fetched
		git fetch -q $remote || true
Simona Vetter's avatar
Simona Vetter committed
	# merge -fixes
	for conf in "${drm_tip_config[@]}"; do
		local branch override sha1 fixup_file

		read repo branch override <<< $conf
		url=${drm_tip_repos[$repo]}
		remote=$(url_to_remote $url)
		sha1=$remote/$branch
		echo -n "Merging $repo (local remote $remote) $branch... "
		if [[ -n "$override" ]]; then
			sha1=$override
			echo -n "Using override sha1: $sha1... "
Simona Vetter's avatar
Simona Vetter committed
		if [ $first == 1 ] ; then
			git reset --hard $sha1 &> /dev/null
			echo "Reset. Done."
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
			fixup_file=$rerere/$repo-${branch//\//-}-fixup.patch
Simona Vetter's avatar
Simona Vetter committed
			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 "$repo/$branch"
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 "$repo $branch `git rev-parse $sha1`\n\t`git log -1 $sha1 --pretty=format:%s`" >> $specfile
Simona Vetter's avatar
Simona Vetter committed

		$INTERACTIVE
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

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

	echo -n "Updating rerere cache... "
	if git branch --list rerere-cache | grep -q '\*' ; then
		remote=`branch_to_remote rerere-cache`
Simona Vetter's avatar
Simona Vetter committed
		git pull >& /dev/null
		rm `rr_cache_dir`/rr-cache -Rf &> /dev/null || true
		cp `rr_cache_dir`/* rr-cache -r
Simona Vetter's avatar
Simona Vetter committed
		git add *.patch >& /dev/null || true
		git add rr-cache/* > /dev/null
		git rm rr-cache/rr-cache &> /dev/null || true
Simona Vetter's avatar
Simona Vetter committed
		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 $remote HEAD >& /dev/null && echo "Done."
Simona Vetter's avatar
Simona Vetter committed
	else
		echo "Fail: Branch setup for the rerere-cache is borked."
Simona Vetter's avatar
Simona Vetter committed
	fi
}
# push branch $1, rebuild drm-tip. the rest of the arguments are passed to git
function dim_push_branch
	if [[ "x$1" = "x" ]]; then
		echo "usage: $dim $subcommand branch"
	remote=`branch_to_remote $branch`

	git push $DRY_RUN $remote $branch "$@"
	update_linux_next $branch drm-intel-next-queued drm-intel-next-fixes drm-intel-fixes
	update_linux_next $branch drm-misc-next drm-misc-next-fixes drm-misc-fixes

	dim_rebuild_tip
Jani Nikula's avatar
Jani Nikula committed
dim_alias_pq=push-queued
function dim_push_queued
{
	dim_push_branch drm-intel-next-queued "$@"
}

dim_alias_pnf=push-next-fixes
function dim_push_next_fixes
{
	dim_push_branch drm-intel-next-fixes "$@"
}

dim_alias_pf=push-fixes
function dim_push_fixes
{
	dim_push_branch drm-intel-fixes "$@"
}

# ensure we're on branch $1, and apply patches. the rest of the arguments are
# passed to git am.
dim_alias_ab=apply-branch
dim_alias_sob=apply-branch
function dim_apply_branch
	local branch file message_id commiter_email patch_from sob

	branch=$1
	message_id=$(message_get_id $file)
	commiter_email=$(git config --get user.email)
	patch_from=$(grep "From:" "$file" | head -1)
	if [[ "$patch_from" != *"$commiter_email"* ]] ; then
		sob=-s
	fi

	cat $file | git am --scissors -3 $sob "$@"
	if [ -n "$message_id" ]; then
		dim_commit_add_tag "Link: http://patchwork.freedesktop.org/patch/msgid/$message_id"
	else
		echo "No message-id found in the patch file."
dim_alias_aq=apply-queued
function dim_apply_queued
{
	dim_apply_branch drm-intel-next-queued "$@"
}

dim_alias_af=apply-fixes
function dim_apply_fixes
{
	dim_apply_branch drm-intel-fixes "$@"
}

dim_alias_anf=apply-next-fixes
function dim_apply_next_fixes
{
	dim_apply_branch drm-intel-next-fixes "$@"
}

function dim_cherry_pick
{
	local remote sha sha_short

	remote=`url_to_remote $drm_tip_ssh`
	if [[ "x$1" = "x" ]]; then
		echo "usage: $dim $subcommand commit-ish"
		exit 1
	fi
	sha=`git rev-parse $1`
	sha_short=${sha:0:8}

	git fetch -q $remote || true
	echo Possible fixup patches for your cherry-pick:
	git log --grep=$sha_short --pretty=oneline $sha..$remote/drm-tip
	$DRY git cherry-pick -s -x -e $1
function dim_cherry_pick_branch
{
	# Look for commits in dinq tagged as fixes.
	for commit in $(git log --reverse --format=format:%h --grep="drm-intel-fixes@lists.freedesktop.org" --grep="stable@vger.kernel.org" origin/master..$DIM_DRM_INTEL_REMOTE/drm-intel-next-queued -- drivers/gpu/drm/i915); do
		echo "Considering $(git --no-pager log --oneline -1 $commit)"
		log=$(mktemp)

		# Look at history for already cherry-picked fixes.
		# Note: use *local* branches to account for unpushed commits.
		git log drm-intel-fixes --after=12months --oneline \
		    --grep="cherry picked .* $commit" > $log
		if [ "$(cat $log)" = "" ]; then
			git log drm-intel-next-fixes --after=12months --oneline \
			    --grep="cherry picked .* $commit" > $log
		fi

		if [ "$(cat $log)" = "" ]; then
			# Try cherry-pick, offer options on fail.
			if ! git cherry-pick -e -x -s $commit; then
				select choice in "Diff" "Resolve" "Skip" "Abort"; do
					case $choice in
						Diff)
							git diff
							;;
						Resolve)
							exit
							;;
						Skip)
							git cherry-pick --abort
							break
							;;
						Abort)
							git cherry-pick --abort
							exit
							;;
					esac
				done
			fi
		else
			echo "Already backported as:"
			sed 's/^/\t/' < $log
		fi
		rm -f $log
	done
}

function dim_cherry_pick_fixes
{
	assert_branch drm-intel-fixes
	dim_cherry_pick_branch "$@"
}

function dim_cherry_pick_next_fixes
{
	assert_branch drm-intel-next-fixes
	dim_cherry_pick_branch "$@"
}

dim_alias_ar=apply-resolved
function dim_apply_resolved
{
	make $DIM_MAKE_OPTIONS && git add -u && git am --resolved
	checkpatch_commit HEAD
	git commit --amend &
}

dim_alias_mrr=magic-rebase-resolve
function dim_magic_rebase_resolve
{
	git diff HEAD | patch -p1 -R
	cat .git/rebase-merge/patch | dim mp
	make $DIM_MAKE_OPTIONS
	git add -u
	git rebase --continue
}

dim_alias_ai=apply-igt
function dim_apply_igt
{
	cd ~/xorg/intel-gpu-tools/
	git am --whitespace=fix -3 -s
}

dim_alias_mp=magic-patch
function dim_magic_patch
	if [[ "$1" = "-a" ]]; then
		cd `cat ~/.dim-last-path`
	fi

	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
}

function dim_create_branch
{
	if [[ "x$1" = "x" ]]; then
		echo "usage: $dim $subcommand branch [commit-ish]"
	if [[ "x$2" = "x" ]]; then
		start=HEAD
	else
		start=$2
	fi

	cd $DIM_PREFIX/$DIM_DRM_INTEL

	if ( repo_to_remote ${branch%%/*} ) &> /dev/null ; then
		repo=${branch%%/*}
		branch=${branch#*/}
	fi

	remote=`repo_to_remote $repo`
	$DRY git branch $branch $start
	git push $DRY_RUN $remote +$branch --set-upstream
	cd $DIM_PREFIX/drm-rerere
	$DRY sed -i "s/^\() # DO NOT CHANGE THIS LINE\)$/\t\"$repo\t\t${branch//\//\\\/}\"\n\1/" $integration_config

	$DRY git add $integration_config
	$DRY git commit --quiet -m "Add $repo $branch to $integration_config"
}

function dim_remove_branch
{
	if [[ "x$1" = "x" ]]; then
		echo "usage: $dim $subcommand branch"

	cd $DIM_PREFIX/$DIM_DRM_INTEL

	if [[ -d $DIM_PREFIX/$branch ]] ; then
		rm -R $DIM_PREFIX/$branch
		git worktree prune &> /dev/null || true
	fi

	if [[ `git branch --list $branch`  != "" ]] &&
	   ! $DRY git branch -d $branch  ; then
			warn_or_fail "Can't remove $branch in working repo"
	cd $DIM_PREFIX/drm-tip
	repo=`branch_to_repo $branch`

	if [[ $repo == "" ]] ; then
		echoerr "$branch not found in $integration_config"
	remote=`repo_to_remote $repo`

	git push $DRY_RUN $remote --delete $branch
	$DRY git fetch $remote --prune
	cd $DIM_PREFIX/drm-rerere
	$DRY sed -i "/^[[:space:]]*\"${repo}[[:space:]]\+${branch//\//\\\/}.*$/d" $integration_config

	$DRY git add $integration_config
	$DRY git commit --quiet -m "Remove $repo $branch from $integration_config"
function dim_cd
	if [[ -d $DIM_PREFIX/$1 ]] ; then
		path=$DIM_PREFIX/$1
		path=$DIM_PREFIX/$DIM_DRM_INTEL

	echo $path > ~/.dim-last-path
	cd $path
dim_alias_co=checkout
function dim_checkout
	if [[ "x$1" = "x" ]]; then
		echo "usage: $dim $subcommand branch"
	dim_cd $branch
	if [[ `git branch --list $branch` ==  "" ]] ; then
		repo=`branch_to_repo $branch`
Simona Vetter's avatar
Simona Vetter committed
		if [[ $branch == "drm-intel-next" ]] ; then
			repo="drm-intel"
		fi

		if [[ $repo == "" ]] ; then
			echoerr "$branch not found in $integration_config"
			exit 1
		remote=`repo_to_remote $repo`

		if [ "$remote" == "" ] ; then
			exit 1
		fi
		git fetch -q $remote || true
		git checkout -t $remote/$branch
		git checkout $branch
function dim_conq
{
	dim_checkout drm-intel-next-queued "$@"
}

function dim_cof
{
	dim_checkout drm-intel-fixes "$@"
}

function dim_conf
{
	dim_checkout drm-intel-next-fixes "$@"
}

# $1 is the git sha1 to check
function checkpatch_commit
Simona Vetter's avatar
Simona Vetter committed
{
	local commit cmd bug_lines non_i915_files

	commit=$1
	cmd="git show --pretty=email $commit"

	git --no-pager log --oneline -1 $commit
	$cmd | scripts/checkpatch.pl -q --emacs --strict - || true
	# FIXME: this relies on local assignment not failing on command
	# substitution failures
	local bug_lines=$($cmd | grep -m 1 -B 1 '^\+.*\WBUG' | grep -c '^[+-].*\WBUG')
	if test "$bug_lines" -eq 1; then
		warn_or_fail "New BUG macro added"
	fi

        if [ "$branch" = "drm-intel-next-queued" ]; then
		# FIXME: this relies on local assignment not failing on command
		# substitution failures
		local non_i915_files=$(git diff-tree --no-commit-id --name-only -r $commit | \
			grep -v "^\(drivers/gpu/drm/i915/\|include/drm/i915\|include/uapi/drm/i915\)")

		if [ -n "$non_i915_files" ]; then
			echo -e "The following files are outside of i915 maintenance scope:\n"
			echo "$non_i915_files"
			echo -e "\nConfirm you have appropriate Acked-by and Reviewed-by for above files."
		fi
	fi
Simona Vetter's avatar
Simona Vetter committed
}

# turn $1 in to a git commit range
function rangeish()
		echo "HEAD^..HEAD"
	elif [ -n "`echo $1 | grep '\.\.'`" ]; then
}

dim_alias_check_patch=checkpatch
dim_alias_cp=checkpatch
function dim_checkpatch
{
	local range

	range=$(rangeish "$1")

	for commit in $(git rev-list --reverse $range); do
		checkpatch_commit $commit || true
	local range

	range=$(rangeish "$1")

	make $DIM_MAKE_OPTIONS
	touch --no-create `git diff --name-only $range` `git diff --name-only`
	make C=1
}

Jani Nikula's avatar
Jani Nikula committed
function dim_checker
{
	rm -f drivers/gpu/drm/i915/*.o drivers/gpu/drm/i915/*.ko
Jani Nikula's avatar
Jani Nikula committed
	make C=1 drivers/gpu/drm/i915/i915.ko
}

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
			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