<commit_before>pkg:parse-id+() {
  pkg_commit=''

  local id=$1

  pkg:parse-id "$id"

  if [[ ! $pkg_version ]]; then
    pkg_version=$(pkg:get-version "$pkg_id")
  fi

  pkg_commit=$(pkg:get-commit "$pkg_id" "$pkg_version")

  pkg_src=$BPAN_INSTALL/src/$pkg_host/$pkg_owner/$pkg_name/$pkg_version
}

pkg:parse-id() {
  pkg_name=''
  pkg_owner=''
  pkg_host=''
  pkg_version=''
  pkg_id=''
  pkg_src=''
  pkg_repo=''

  local id=$1
  local index=bpan    # TODO pass in value for multi index

  local w='[-a-zA-Z0-9_]'
  local v='[.0-9]'
  local ns='[^[:space:]]'

  [[ $id =~ ^($w+:)?($w+/)?($w+)(=$v+)?(:$ns+)?$ ]] ||
    error "Invalid package id '$id'"

  pkg_host=${BASH_REMATCH[1]:-$(ini:get "index.$index.host")} || true
  pkg_host=${pkg_host%:}
  pkg_owner=${BASH_REMATCH[2]:-$(ini:get "index.$index.owner")} || true
  pkg_owner=${pkg_owner%/}
  pkg_name=${BASH_REMATCH[3]}
  pkg_version=${BASH_REMATCH[4]}
  pkg_version=${pkg_version#=}
  pkg_file=${BASH_REMATCH[5]}
  if [[ $pkg_file ]]; then
    pkg_file=${pkg_file#:}
    pkg_file=${pkg_file/@/$pkg_name}
    if ! [[ $pkg_file =~ ^(bin|lib)/ ]]; then
      pkg_file=lib/$pkg_file
    fi
    if [[ $pkg_file == lib/* && $pkg_file != *.bash ]]; then
      pkg_file=$pkg_file.bash
    fi
  fi
  pkg_id=$pkg_host:$pkg_owner/$pkg_name

  pkg_repo=$(
    owner=$pkg_owner
    name=$pkg_name
    ini:vars owner name
    key=host.$pkg_host.clone
    ini:get "$key" ||
      error "Can't find config value for '$key'"
  )

  pkg_src=$BPAN_INSTALL/src/$pkg_host/$pkg_owner/$pkg_name/$pkg_version
}

pkg:config-vars() {
  local index=bpan    # TODO pass in value for multi index
  local repo

  bpan_index_clone_url=$(ini:get "index.$index.clone")
  bpan_index_branch=$(ini:get "index.$index.branch")

  repo=$(ini:get index.$index.repo)
  bpan_index_repo_dir=src/github/$repo
  bpan_index_api_url=$(ini:get index.$index.api)
  bpan_index_publish_url=$(ini:get index.$index.publish)
  bpan_index_file=$(ini:get index.$index.file)

  bpan_index_file=$BPAN_INSTALL/$bpan_index_repo_dir/$bpan_index_file
}

pkg:index-update() (
  pkg:config-vars
<commit_msg>Get package host from config file<commit_after>pkg:parse-id+() {
  pkg_commit=''

  local id=$1

  pkg:parse-id "$id"

  if [[ ! $pkg_version ]]; then
    pkg_version=$(pkg:get-version "$pkg_id")
  fi

  pkg_commit=$(pkg:get-commit "$pkg_id" "$pkg_version")

  pkg_src=$BPAN_INSTALL/src/$pkg_host/$pkg_owner/$pkg_name/$pkg_version
}

pkg:parse-id() {
  pkg_name=''
  pkg_owner=''
  pkg_host=''
  pkg_version=''
  pkg_id=''
  pkg_src=''
  pkg_repo=''

  local id=$1
  local index=bpan    # TODO pass in value for multi index

  local w='[-a-zA-Z0-9_]'
  local v='[.0-9]'
  local ns='[^[:space:]]'

  [[ $id =~ ^($w+:)?($w+/)?($w+)(=$v+)?(:$ns+)?$ ]] ||
    error "Invalid package id '$id'"

  pkg_host=${BASH_REMATCH[1]:-$(ini:get "index.$index.host")} || true
  pkg_host=${pkg_host%:}
  pkg_owner=${BASH_REMATCH[2]:-$(ini:get "index.$index.owner")} || true
  pkg_owner=${pkg_owner%/}
  pkg_name=${BASH_REMATCH[3]}
  pkg_version=${BASH_REMATCH[4]}
  pkg_version=${pkg_version#=}
  pkg_file=${BASH_REMATCH[5]}
  if [[ $pkg_file ]]; then
    pkg_file=${pkg_file#:}
    pkg_file=${pkg_file/@/$pkg_name}
    if ! [[ $pkg_file =~ ^(bin|lib)/ ]]; then
      pkg_file=lib/$pkg_file
    fi
    if [[ $pkg_file == lib/* && $pkg_file != *.bash ]]; then
      pkg_file=$pkg_file.bash
    fi
  fi
  pkg_id=$pkg_host:$pkg_owner/$pkg_name

  pkg_repo=$(
    owner=$pkg_owner
    name=$pkg_name
    ini:vars owner name
    key=host.$pkg_host.clone
    ini:get "$key" ||
      error "Can't find config value for '$key'"
  )

  pkg_src=$BPAN_INSTALL/src/$pkg_host/$pkg_owner/$pkg_name/$pkg_version
}

pkg:config-vars() {
  local index=bpan    # TODO pass in value for multi index
  local repo host

  bpan_index_clone_url=$(ini:get "index.$index.clone")
  bpan_index_branch=$(ini:get "index.$index.branch")

  host=$(ini:get "index.$index.host")
  repo=$(ini:get index.$index.repo)

  bpan_index_repo_dir=src/$host/$repo
  bpan_index_api_url=$(ini:get index.$index.api)
  bpan_index_publish_url=$(ini:get index.$index.publish)
  bpan_index_file=$(ini:get index.$index.file)

  bpan_index_file=$BPAN_INSTALL/$bpan_index_repo_dir/$bpan_index_file
}

pkg:index-update() (
  pkg:config-vars

{'fraction_non_alphanumeric': 0.1943859649122807, 'fraction_numerical': 0.005146198830409357, 'mean_word_length': 4.279012345679012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3466496', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1706, 'n_words': 260}