def _merge_summary(merge_dest, merge_src):
  """Merges to 'summaries' fields in metadata format.

  Two sumaries are required to have the exact same metrics, and this method
  adds the 'total' and 'covered' field of each metric in the second parameter
  to the corresponding field in the first parameter.

  Each parameter is expected to be in the following format:
  [{'name': 'line', 'total': 10, 'covered': 9},
  {'name': 'region', 'total': 10, 'covered': 9},
  {'name': 'function', 'total': 10, 'covered': 9}]
  """

  def get_metrics(summaries):
    return {s['name'] for s in summaries}

  assert get_metrics(merge_dest) == get_metrics(merge_src), (
      '%s and %s are expected to have the same metrics' %
      (merge_dest, merge_src))

  merge_src_dict = {i['name']: i for i in merge_src}

  for merge_dest_item in merge_dest:
    for field in ('total', 'covered'):
      merge_dest_item[field] += merge_src_dict[merge_dest_item['name']][field]