@@ -44,9 +44,27 @@ ReleaseInfo placeholder_release(std::string_view version);
4444// Compute the convention-based GitHub Release tarball URL for a package:
4545// "<repo>/releases/download/v<version>/<name>-<version>.tar.gz"
4646// Returns empty string if `repo` is empty or doesn't look like a https URL.
47+ // `name` is the archive's name: the package's identity (`archive_identity`).
48+ // `tag` empty: `v<version>`.
4749std::string release_tarball_url (std::string_view repo,
4850 std::string_view name,
49- std::string_view version);
51+ std::string_view version,
52+ std::string_view tag = {});
53+
54+ // THE NAMES A PUBLISHED PACKAGE IS FILED UNDER (mcpp#947). Several packages of
55+ // one repository are released under one tag, and two of them may share a short
56+ // name across namespaces (`omui.core`, `hanim.core`): the archive and its
57+ // directory are named by the identity, `<namespace>.<name>`; a package with
58+ // no namespace keeps its name.
59+ std::string archive_identity (std::string_view ns, std::string_view name);
60+ // The descriptor's file in an index: `<name>.lua` in the default namespace,
61+ // `<namespace>.<name>.lua` in another.
62+ std::string descriptor_file_name (std::string_view ns, std::string_view name);
63+ // The tag a release is published under, from a template of `{version}`,
64+ // `{name}` and `{namespace}`; empty template: `v{version}`. An unknown
65+ // placeholder is an error.
66+ std::expected<std::string, std::string> release_tag (std::string_view tmpl, std::string_view ns,
67+ std::string_view name, std::string_view version);
5068
5169// Compute SHA-256 of `file` by shelling out to `sha256sum` (universally
5270// available on Linux). Returns empty string on failure.
@@ -203,14 +221,18 @@ std::string emit_xpkg(const mcpp::manifest::Manifest& manifest,
203221 // carries the "AUTO-GENERATED … do not edit by hand" banner). Emitting the
204222 // FQN here closes the generator half of that loop; `mcpp xpkg parse` closes
205223 // the lint half. Design: 2026-06-26 §4.5 prescribed this and it never landed.
224+ //
225+ // THE NAME IS ONE SEGMENT AND THE NAMESPACE CARRIES THE PATH (SPEC-001
226+ // §3.2; mcpp#947): the shape the index files and its lint asks for. The
227+ // fully-qualified name written here before stays readable.
206228 if (!manifest.package .namespace_ .empty ()) {
207229 auto prefix = manifest.package .namespace_ + " ." ;
208- auto fqn = manifest.package .name .starts_with (prefix)
209- ? manifest.package .name
210- : prefix + manifest.package .name ;
230+ auto shortName = manifest.package .name .starts_with (prefix)
231+ ? manifest.package .name . substr (prefix. size ())
232+ : manifest.package .name ;
211233 out += std::format (" namespace = {},\n " ,
212234 lua_escape (manifest.package .namespace_ ));
213- out += std::format (" name = {},\n " , lua_escape (fqn ));
235+ out += std::format (" name = {},\n " , lua_escape (shortName ));
214236 } else {
215237 out += std::format (" name = {},\n " , lua_escape (manifest.package .name ));
216238 }
@@ -365,17 +387,51 @@ ReleaseInfo placeholder_release(std::string_view version) {
365387 return r;
366388}
367389
390+ std::string archive_identity (std::string_view ns, std::string_view name) {
391+ if (ns.empty () || name.starts_with (std::string (ns) + " ." )) return std::string (name);
392+ return std::format (" {}.{}" , ns, name);
393+ }
394+
395+ std::string descriptor_file_name (std::string_view ns, std::string_view name) {
396+ const auto identity = archive_identity (ns, name);
397+ constexpr std::string_view kDefault = " mcpplibs." ;
398+ return std::format (" {}.lua" , identity.starts_with (kDefault ) && identity.find (' .' , kDefault .size ()) == std::string::npos
399+ ? identity.substr (kDefault .size ()) : identity);
400+ }
401+
402+ std::expected<std::string, std::string> release_tag (std::string_view tmpl, std::string_view ns,
403+ std::string_view name, std::string_view version) {
404+ if (tmpl.empty ()) tmpl = " v{version}" ;
405+ std::string out;
406+ for (std::size_t i = 0 ; i < tmpl.size ();) {
407+ if (tmpl[i] != ' {' ) { out += tmpl[i++]; continue ; }
408+ const auto end = tmpl.find (' }' , i);
409+ const auto word = end == std::string_view::npos ? std::string_view{} : tmpl.substr (i + 1 , end - i - 1 );
410+ if (word == " version" ) out += version;
411+ else if (word == " name" ) out += name;
412+ else if (word == " namespace" ) out += ns;
413+ else return std::unexpected (std::format (
414+ " --tag '{}': '{}' is not a placeholder; a tag names {{version}}, {{name}} and {{namespace}}" ,
415+ tmpl, tmpl.substr (i, end == std::string_view::npos ? std::string_view::npos : end - i + 1 )));
416+ i = end + 1 ;
417+ }
418+ if (out.empty () || out.find_first_of (" \t ~^:?*[\\ " ) != std::string::npos)
419+ return std::unexpected (std::format (" --tag '{}' gives '{}', which is not a tag's name" , tmpl, out));
420+ return out;
421+ }
422+
368423std::string release_tarball_url (std::string_view repo,
369424 std::string_view name,
370- std::string_view version)
425+ std::string_view version,
426+ std::string_view tag)
371427{
372428 // Strip trailing ".git" if present.
373429 std::string r{repo};
374430 if (r.ends_with (" .git" )) r.resize (r.size () - 4 );
375431 if (r.empty ()) return {};
376432 if (!r.starts_with (" https://" ) && !r.starts_with (" http://" )) return {};
377- return std::format (" {}/releases/download/v {}/{}-{}.tar.gz" ,
378- r, version, name, version);
433+ return std::format (" {}/releases/download/{}/{}-{}.tar.gz" ,
434+ r, tag. empty () ? std::format ( " v{} " , version) : std::string (tag) , name, version);
379435}
380436
381437std::string sha256_of_file (const std::filesystem::path& file) {
0 commit comments