MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / parse_other_extension_submodules

Function parse_other_extension_submodules

xtask/src/extension_catalog.rs:1106–1165  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

1104}
1105
1106fn parse_other_extension_submodules(path: &Path) -> Result<BTreeMap<String, SubmodulePin>> {
1107 let gitmodules = path
1108 .parent()
1109 .and_then(Path::parent)
1110 .map(|root| root.join(".gitmodules"))
1111 .ok_or_else(|| anyhow!("could not resolve postgres-pglite .gitmodules"))?;
1112 let gitmodules_text = fs::read_to_string(&gitmodules)
1113 .with_context(|| format!("read {}", gitmodules.display()))?;
1114 let mut urls = BTreeMap::new();
1115 let mut current: Option<String> = None;
1116 for line in gitmodules_text.lines() {
1117 let trimmed = line.trim();
1118 if trimmed.starts_with("[submodule ") {
1119 current = trimmed
1120 .split('"')
1121 .nth(1)
1122 .and_then(|value| value.strip_prefix("pglite/other_extensions/"))
1123 .map(str::to_owned);
1124 } else if let Some(url) = trimmed.strip_prefix("url = ")
1125 && let Some(name) = &current
1126 {
1127 urls.insert(name.clone(), url.to_owned());
1128 }
1129 }
1130
1131 let status = std::process::Command::new("git")
1132 .args([
1133 "-C",
1134 "assets/checkouts/postgres-pglite",
1135 "submodule",
1136 "status",
1137 ])
1138 .output()
1139 .context("read postgres-pglite submodule status")?;
1140 let status_text = String::from_utf8(status.stdout).context("submodule status utf8")?;
1141 let mut pins = BTreeMap::new();
1142 for line in status_text.lines() {
1143 let trimmed = line.trim_start_matches(['-', '+', ' ']);
1144 let mut parts = trimmed.split_whitespace();
1145 let Some(commit) = parts.next() else {
1146 continue;
1147 };
1148 let Some(path) = parts.next() else {
1149 continue;
1150 };
1151 let Some(name) = path.strip_prefix("pglite/other_extensions/") else {
1152 continue;
1153 };
1154 if let Some(url) = urls.get(name) {
1155 pins.insert(
1156 name.to_owned(),
1157 SubmodulePin {
1158 url: url.clone(),
1159 commit: commit.to_owned(),
1160 },
1161 );
1162 }
1163 }

Callers 1

discover_catalogFunction · 0.85

Calls 4

insertMethod · 0.80
outputMethod · 0.80
argsMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected