code: def _get_update_diff_index(
      repo: "Repo",
      out: "Output",
      local_index: Union["DataIndex", "DataIndexView"],
      remote_index: Union["DataIndex", "DataIndexView"],
      remote: "Remote",
  ) -> "DataIndex":
      from dvc_data.hashfile.tree import Tree
      from dvc_data.index import DataIndex
      from dvc_data.index.diff import ADD, MODIFY, UNCHANGED, diff
  
      old, new = _get_diff_indexes(out, local_index, remote_index)
      index = DataIndex()
      for change in diff(
          old,
          new,
          meta_only=True,
          meta_cmp_key=partial(_meta_checksum, remote.fs),
          with_unchanged=True,
      ):
          if change.typ in (ADD, MODIFY):
              entry = change.new
              # preserve md5's which were calculated in out.save() after
              # downloading
              if out.isdir():
                  if not entry.meta.isdir:
                      fs_path = repo.fs.join(repo.root_dir, *entry.key)
                      tree = out.obj
                      assert isinstance(tree, Tree)
                      _, entry.hash_info = tree.get(  # type: ignore[misc]
                          repo.fs.relparts(fs_path, out.fs_path)
                      )
              else:
                  entry.hash_info = out.hash_info
              index[change.new.key] = change.new
          elif change.typ == UNCHANGED:
              index[change.old.key] = change.old
      return index
  
file_path: dvc/dvc/repo/worktree.py
imports: from functools import partial
  from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Tuple, Union
  from funcy import first
  from dvc.log import logger
  from dvc.stage.exceptions import StageUpdateError
label_desc: Use image node_id 11 for calling a global function with example usage: _get_update_diff_index(repo, out, local_index, remote_index, remote) and returns: index