Skip to content

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

Open
beer4code wants to merge 3 commits intoCycloneDX:mainfrom
beer4code:vcs-url-from-pkgid-spec
Open

Extract VCS URL from package.id (pkgid spec) instead of package.source#861
beer4code wants to merge 3 commits intoCycloneDX: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

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 requested a review from a team as a code owner March 19, 2026 23:28
@Shnatsel
Copy link
Copy Markdown
Contributor

Thanks for the PR!

Update git_package.json fixture to use the new pkgid format

I'd rather have tests and fixtures for both formats. The old for fallback to source on older versions as described in #854 and the new to extract it from pkgid.

Signed-off-by: beer4code <102912454+beer4code@users.noreply.github.com>
Signed-off-by: beer4code <102912454+beer4code@users.noreply.github.com>
@beer4code
Copy link
Copy Markdown
Author

Would you mind having another look please?

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.

2 participants