docs: def get_entry_id(entry, fullpath, assign_id):
      """ Get or generate an entry ID for an entry """
      warn_duplicate = False
  
      if 'Entry-ID' in entry:
          entry_id = int(entry['Entry-ID'])
      else:
          entry_id = None
  
      # See if we've inadvertently duplicated an entry ID
      if entry_id:
          try:
              other_entry = model.Entry.get(id=entry_id)
              if (other_entry
                      and os.path.isfile(other_entry.file_path)
                      and not os.path.samefile(other_entry.file_path, fullpath)):
                  warn_duplicate = entry_id
                  entry_id = None
          except FileNotFoundError:
              # the other file doesn't exist, so just let it go
              pass
  
      # Do we need to assign a new ID?
      if not entry_id and not assign_id:
          # We're not assigning IDs yet
          return None
  
      if not entry_id:
          # See if we already have an entry with this file path
          by_filepath = model.Entry.get(file_path=fullpath)
          if by_filepath:
              entry_id = by_filepath.id
  
      if not entry_id:
          # We still don't have an ID; generate one pseudo-randomly, based on the
          # entry file path. This approach averages around 0.25 collisions per ID
          # generated while keeping the entry ID reasonably short. In general,
          # count*N averages 1/(N-1) collisions per ID.
  
          limit = max(10, orm.get(orm.count(e) for e in model.Entry) * 5)
          attempt = 0
  
          while not entry_id or model.Entry.get(id=entry_id):
              # Stably generate a quasi-random entry ID from the file path
              md5 = hashlib.md5()
              md5.update("{} {}".format(fullpath, attempt).encode('utf-8'))
              entry_id = int.from_bytes(md5.digest(), byteorder='big') % limit
              attempt = attempt + 1
  
      if warn_duplicate is not False:
          logger.warning("Entry '%s' had ID %d, which belongs to '%s'. Reassigned to %d",
                         fullpath, warn_duplicate, other_entry.file_path, entry_id)
  
      return entry_id