code: def format_diffindex(diff_index):
      
      for diff in diff_index:
          if diff.new_file:
              yield format_diff_A(diff)
          elif diff.deleted_file:
              yield format_diff_D(diff)
          elif diff.renamed:
              yield format_diff_R(diff)
          elif diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob:
              yield format_diff_M(diff)
docs: Return a JSON formattable representation of a DiffIndex.
  
      Returns a generator that returns dictionaries representing the changes.
  
      .. code::
          [
              {
                  'type': 'A',
                  'path': 'path/to/added/file.txt',
              },
              {
                  'type': 'D',
                  'path': 'path/to/deleted/file.txt',
              },
              {
                  'type': 'M',
                  'path': 'path/to/modified/file.txt',
              },
              {
                  'type': 'R',
                  'rename_from': 'original/path/to/file.txt',
                  'rename_to': 'new/path/to/file.txt',
              },
          ]
  
      :returns: generator