code: def format_message(
      cls,
      head_rev: str,
      rev: str,
      name: Optional[str] = None,
  ) -> str:
      return cls.MESSAGE_FORMAT.format(
          head_rev=head_rev, rev=rev, name=name if name else ""
      )
  
imports: import re
  from contextlib import contextmanager
  from typing import Dict, Iterable, Iterator, NamedTuple, Optional
  from scmrepo.git import Stash
  from dvc.exceptions import DvcException
  from dvc.log import logger
  from dvc_objects.fs.local import localfs
  from dvc_objects.fs.utils import as_atomic
  from .refs import APPLY_HEAD, APPLY_STASH
label_desc: Use image node_id 2 for calling the ApplyStash obj's underlying member method code with example usage: obj.format_message(cls, head_rev, rev, name) and returns: cls