Skip to content

Extract VCS URL from package.id (pkgid spec) instead of package.source - #860

Closed
beer4code wants to merge 1 commit into
CycloneDX:mainfrom
beer4code:vcs-url-from-pkgid-spec
Closed

beer4code wants to merge 1 commit into
CycloneDX:mainfrom
beer4code:vcs-url-from-pkgid-spec

Conversation

@beer4code

Copy link
Copy Markdown

Summary

Replace the use of package.source (opaque/unstable) with package.id (stable) for extracting VCS URLs from git dependencies.

package.source is explicitly documented as opaque and unstable by the cargo_metadata crate. package.id (the pkgid spec) is the stable alternative. On Rust 1.77+ the pkgid format for git deps is:

git+proto://host/path[?query]#name@version

The fragment contains name@version (not a commit hash like package.source does), so the output no longer includes commit hashes.

This PR is supposed to replace #777.

Changes

  • Add extract_git_url_from_id helper in purl.rs that strips the #name@version fragment and ?branch=/?tag=/?rev= query params from the pkgid, returning a clean git+proto://host/path URL
  • Use the helper in get_purl for the PURL vcs_url qualifier, replacing the previous source_to_vcs_url function
  • Use the helper in get_external_references as a fallback when package.repository is absent on git dependencies
  • Update git_package.json fixture to use the new pkgid format

@beer4code
beer4code requested a review from a team as a code owner March 19, 2026 23:19
@beer4code
beer4code force-pushed the vcs-url-from-pkgid-spec branch from ce02abc to 4a67456 Compare March 19, 2026 23:21
Replace the use of package.source (opaque/unstable) with package.id (stable pkgid spec) for extracting VCS URLs from git dependencies.

- Add extract_git_url_from_id helper in purl.rs that strips the #name@version fragment and ?branch=/?tag=/?rev= query params from the pkgid, returning a clean git+proto://host/path URL

- Use the helper in get_purl for the PURL vcs_url qualifier, replacing the previous source_to_vcs_url function

- Use the helper in get_external_references as a fallback when package.repository is absent on git dependencies

- Update git_package.json fixture to use the new pkgid format

package.source is explicitly documented as opaque and unstable by the cargo_metadata crate. package.id (the pkgid spec) is the stable alternative. On Rust 1.77+ the pkgid format for git deps is: git+proto://host/path[?query]#name@version. The fragment contains name@version (not a commit hash like package.source does), so the output no longer includes commit hashes. This was recommended by the maintainer in PR CycloneDX#777.

Signed-off-by: beer4code <102912454+beer4code@users.noreply.github.com>
@beer4code
beer4code force-pushed the vcs-url-from-pkgid-spec branch from 4a67456 to 59b34c2 Compare March 19, 2026 23:22
@beer4code beer4code closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant