code: def do_tortoisehg_report(repos, output):
      
      import operator
      import xml.etree.ElementTree as ET
  
      root = ET.Element('reporegistry')
      item = ET.SubElement(root, 'treeitem')
  
      group = ET.SubElement(item, 'group', attrib=Dict(name='groupname'))
  
      def fullname_to_shortname(fullname):
          """
          Return a TortoiseHG-friendly path to a repository
  
          Args:
              fullname (str): path to repository
  
          Returns:
              str: path with $HOME replaced with ``~`` and leading ``./``
                  stripped
          """
          shortname = fullname.replace(os.environ['HOME'], '~')
          shortname = shortname.lstrip('./')
          return shortname
  
      for repo in sorted(repos, key=operator.attrgetter('fpath')):
          fullname = os.path.join(
              os.path.dirname(repo.fpath),
              os.path.basename(repo.fpath))
          shortname = fullname_to_shortname(fullname)
          if repo.prefix != '.hg':
              shortname = "%s%s" % (shortname, repo.prefix)
          _ = ET.SubElement(group, 'repo',
                            attrib=Dict(
                                root=repo.fpath,
                                shortname=shortname,
                                basenode='0'*40))
          _
      print('<?xml version="1.0" encoding="UTF-8"?>', file=output)
      print("<!-- autogenerated: %s -->" % "TODO", file=output)
      print(ET.dump(root), file=output)
docs: Generate a thg-reporegistry.xml file from a list of repos and print
      to output
  
      Args:
          repos (iterable): iterable of Repository subclass instances
          output (writeable): output stream to which THG XML will be printed