Require gear 0.4.0

It has a bugfix that could avoid starving gear workers.

Change-Id: I1be3f23bff2f75c2f06c1b5b4034978c6af161d5
Use the 'resolve' merge strategy by default

We can more closely approximate Gerrit's behavior by using the
'resolve' git merge strategy.  Make that the default, and leave
the previous behavior ('git merge') as an option.  Also, finish
and correct the partially implemented plumbing for other merge
strategies (including cherry-pick).

(Note the previous unfinished implementation attempted to mimic
Gerrit's option names; the new implementation does not, but rather
documents the alignment.  It's not a perfect translation anyway,
and this gives us more room to support other strategies not
currently supported by Gerrit).

Change-Id: Ie1ce4fde5980adf99bba69a5aa1d4e81026db676
Fetch specific refs on ref-updated events

The current behavior is that for every event, run
'git remote origin update', which is quite a bit of overhead and
doesn't match what the comments say should be happening.  The goal
is to ensure that when new tags arrive, we have them locally in
our repo.  It's also not a bad idea for us to keep up with remote
branch movements as well.

This updates the event pre-processor to fetch the ref for each
ref-updated event as they are processed.  This is much faster than
the git remote update that was happening before.  It also adds
a git remote update to the repo initialization step so that when
Zuul starts, it will pick up any remote changes since it last ran.

Change-Id: I671bb43eddf41c7403de53bb4a223762101adc3c
Don't reset the local repo

Instead of "resetting" the local repo (git remote update,
git checkout master, git reset --hard, git clean -xfdq) before
merging each change, just fetch the remote ref for the branch
and check that out (as a detached head).  Or, if we are merging
a change that depends on another change in the queue, just check
that change out.

Change-Id: I0a9b839a0c75c04eca7393d7bb58cf89448b6494
Fix graceful exit

When the gearman server was added, the exit handler was not updated
correctly.  It should tell the scheduler to exit, wait for the
scheduler to empty its pipelines, and then kill the gearman server
and exit.

Change-Id: Ie0532c2ea058ed56217e41641f8eec45080a9470
Report item stats when removing a change

If a change is removed outside of the main process method (eg
it is superceded), stats were not reported.  Report them in that
case.

Change-Id: I9e753599dc3ecdf0d4bffc04f4515c04d882c8be
Set merge result correctly on exceptions

If an exception was received during a report, _reportItem would
erroneously indicate that it had been reported without error.
If a merge was expected, isMerged would be called which may then
raise a further exception which would stop queue processing.

Instead, set the default return value for _reportItem to True
because trigger.report returns a true value on error.  This will
cause the change to be marked as reported (with a value of ERROR),
the merge check skipped, and the change will be quickly removed
from the pipeline.

Change-Id: I08b7cee486111200ac9857644d478727c635908d