code: def collect_branch(
      repo: "Repo",
      rev: str,
      end_rev: Optional[str] = None,
      **kwargs,
  ) -> Iterator["ExpState"]:
      """Iterate over exp states in a Git branch.
  
      Git branch will be traversed in reverse, starting from rev.
  
      Args:
          rev: Branch tip (head).
          end_rev: If specified, traversal will stop when end_rev is reached
              (exclusive, end_rev will not be collected).
      """
      try:
          for branch_rev in repo.scm.branch_revs(rev, end_rev):
              yield collect_rev(repo, branch_rev, **kwargs)
      except (SCMError, InnerSCMError):
          pass
  
imports: import itertools
  import os
  from dataclasses import fields
  from datetime import datetime
  from typing import TYPE_CHECKING, Collection, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from funcy import first
  from scmrepo.exceptions import SCMError
  from dvc.log import logger
  from dvc.scm import Git, SCMError, iter_revs
  from .exceptions import InvalidExpRefError
  from .refs import EXEC_BRANCH, ExpRefInfo
  from .serialize import ExpRange, ExpState, SerializableError, SerializableExp
  from .utils import describe
label_desc: Use image node_id 3 for calling a global function with example usage: collect_branch(repo, rev, end_rev) without return types