code: def _merge_push_meta(  # noqa: C901
      out: "Output",
      index: Union["DataIndex", "DataIndexView"],
      remote: Optional[str] = None,
  ):
      """Merge existing output meta with newly pushed meta.
  
      Existing version IDs for unchanged files will be preserved to reduce merge
      conflicts (i.e. the DVC output's version ID may not match the pushed/latest
      version ID as long when the file content of both versions is the same).
      """
      from dvc_data.hashfile.tree import Tree
      from dvc_data.index.save import build_tree
  
      _, key = out.index_key
  
      entry = index.get(key)
      if entry is None:
          return
  
      repo = out.stage.repo
      if out.isdir():
          old_tree = out.get_obj()
          assert isinstance(old_tree, Tree)
          entry.hash_info = old_tree.hash_info
          entry.meta = out.meta
          entries = [entry]
          for subkey, entry in index.iteritems(key):
              entries.append(entry)
              if entry.meta is not None and entry.meta.isdir:
                  continue
              fs_path = repo.fs.join(repo.root_dir, *subkey)
              meta, hash_info = old_tree.get(
                  repo.fs.relparts(fs_path, out.fs_path)
              ) or (
                  None,
                  None,
              )
              entry.hash_info = hash_info
              if entry.meta:
                  entry.meta.remote = remote
              if meta is not None and meta.version_id is not None:
                  # preserve existing version IDs for unchanged files in
                  # this dir (entry will have the latest remote version
                  # ID after checkout)
                  entry.meta = meta
  
          for entry in entries:
              index.add(entry)
  
          tree_meta, new_tree = build_tree(index, key)
          out.obj = new_tree
          out.hash_info = new_tree.hash_info
          out.meta = tree_meta
      else:
          if entry.hash_info:
              out.hash_info = entry.hash_info
          if out.meta.version_id is None:
              out.meta = entry.meta
      if out.meta:
          out.meta.remote = remote
  
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 5 for calling a global function with example usage: _merge_push_meta(out, index, remote) without return types