code: func fixManifestLayers(m *schema1.Manifest) error {
  	imgs := make([]*image.V1Image, len(m.FSLayers))
  	for i := range m.FSLayers {
  		img := &image.V1Image{}
  
  		if err := json.Unmarshal([]byte(m.History[i].V1Compatibility), img); err != nil {
  			return err
  		}
  
  		imgs[i] = img
  		if err := v1.ValidateID(img.ID); err != nil {
  			return err
  		}
  	}
  
  	if imgs[len(imgs)-1].Parent != "" && runtime.GOOS != "windows" {
  		// Windows base layer can point to a base layer parent that is not in manifest.
  		return errors.New("invalid parent ID in the base layer of the image")
  	}
  
  	// check general duplicates to error instead of a deadlock
  	idmap := make(map[string]struct{})
  
  	var lastID string
  	for _, img := range imgs {
  		// skip IDs that appear after each other, we handle those later
  		if _, exists := idmap[img.ID]; img.ID != lastID && exists {
  			return fmt.Errorf("ID %+v appears multiple times in manifest", img.ID)
  		}
  		lastID = img.ID
  		idmap[lastID] = struct{}{}
  	}
  
  	// backwards loop so that we keep the remaining indexes after removing items
  	for i := len(imgs) - 2; i >= 0; i-- {
  		if imgs[i].ID == imgs[i+1].ID { // repeated ID. remove and continue
  			m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...)
  			m.History = append(m.History[:i], m.History[i+1:]...)
  		} else if imgs[i].Parent != imgs[i+1].ID {
  			return fmt.Errorf("invalid parent ID. Expected %v, got %v", imgs[i+1].ID, imgs[i].Parent)
  		}
  	}
  
  	return nil
  }
docs: // fixManifestLayers removes repeated layers from the manifest and checks the
  // correctness of the parent chain.