Fix gerrit staging-ls performance.

When searching open changes, full commit log was traversed and each change
was queried from database by the change-id found. Because we always list
the staging or build branch and know the destination branch, we can stop the
search when hitting the destination head. No need to go way back in history,
as over time this gets slower and slower.

Task-number: QTQAINFRA-568
Change-Id: I19e142f65e0996644dcbd50a08f61bbeb886dbf0
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Janne Anttila <janne.anttila@digia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
Fix failing staging-approve by abandoning certain changes.

Sometimes build refs contain changes not being in INTEGRATING state
and it causes gerrit staging-approve command to fail. This happens
when a merge commit is in build and any of the individual commits
belonging to a merge commit is also separately pushed to gerrit.

Technically what happens is that during staging-approve command, all
change-id field values are read from git commit log. This change-id
is then used to query database and check the status of the change in
destination branch. Usually no record is found for individual commits
belonging to a merge commit because 'git push' command has created
change-id only for merge commit. But if somebody has separately pushed
same individual change to destination branch, a new record is created
to database. Then staging-approve logic finds it and because a change
is not in INTEGRATING state, it is handled as an error.

This patch changes the behavior so that any open change not in state
INTEGRATING is set to state ABANDONED. Comment about this is saved and
email is always sent so people involved get informed and can react
if needed.

Task-number: QTQAINFRA-509
Change-Id: I30a56348e80b8d085e5d315d57c8d5fc8580de81
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Janne Anttila <janne.anttila@digia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>