old_contents: def merge_tasks(alpha, beta):
      merged_from = alpha.get('intheammergedfrom', '')
      if merged_from:
          merged_from = merged_from.split(',')
      else:
          merged_from = []
      merged_from.append(str(beta.get('uuid')))
      alpha['intheammergedfrom'] = ','.join(merged_from)
  
      for task in alpha, beta:
          if 'annotations' not in task:
              task['annotations'] = []
  
      original_annotations = alpha.get('annotations')
      original_annotations.extend(beta.get('annotations'))
  
      if 'annotations' not in beta:
          beta['annotations'] = []
      beta['annotations'].append(
          "This task has been merged with another task. "
          "See {uuid}.".format(
              uuid=alpha.get('uuid')
          )
      )
      beta['intheamduplicateof'] = str(alpha.get('uuid'))
      alpha['annotations'] = original_annotations
  
      return alpha, beta
  
new_contents: def merge_tasks(alpha, beta):
      for task in alpha, beta:
          merged_from = task.get('intheammergedfrom', '')
          if merged_from:
              merged_from = set(merged_from.split(','))
          else:
              merged_from = set([])
  
          if 'annotations' not in task:
              task['annotations'] = []
  
      merged_from.add(str(beta.get('uuid')))
      alpha['intheammergedfrom'] = ','.join(merged_from)
  
      original_annotations = alpha.get('annotations')
      original_annotations.extend(beta.get('annotations'))
      alpha['annotations'] = original_annotations
  
      beta['annotations'].append(
          "This task has been merged with another task. "
          "See {uuid}.".format(
              uuid=alpha.get('uuid')
          )
      )
      beta['intheamduplicateof'] = str(alpha.get('uuid'))
  
      return alpha, beta
  
subject: Handle even situations in which a task is merged twice.