def get_branch_pairs(branch_list, naming):
    """Return a list of BranchPair where items in 'branch_list' are suitable.

    Note that if a review_branch or tracker_branch does not have a pair then
    the other member of the tuple is set to 'None'.

    :branch_list: a list of branch name strings to generate the pairs from
    :returns: a list of BranchPair where items in 'branch_list' are suitable

    """
    tracker_branches = _get_branches(
        branch_list, naming.make_tracker_branch_from_name)
    review_branches = _get_branches(
        branch_list, naming.make_review_branch_from_name)

    # XXX: pychecker and pyflakes don't understand dictcomps yet so do it like
    #      this instead
    name_to_tracked = dict([(b.review_name, b) for b in tracker_branches])
    name_to_review = dict([(b.branch, b) for b in review_branches])

    tracked = set(name_to_tracked.keys())
    actual = set(name_to_review.keys())

    abandoned_trackers = [name_to_tracked[b] for b in tracked - actual]
    new_reviews = [name_to_review[b] for b in tracked - actual]
    matched = actual & tracked

    res = [BranchPair(name_to_review[b], name_to_tracked[b]) for b in matched]
    res += [BranchPair(None, b) for b in abandoned_trackers]
    res += [BranchPair(b, None) for b in new_reviews]

    return res


# -----------------------------------------------------------------------------
# Copyright (C) 2013-2014 Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------ END-OF-FILE ----------------------------------
dataset/ETHPy150Open bloomberg/phabricator-tools/py/abd/abdt_naming.py/get_branch_pairs/swapped operands of `-`