Skip to content

Commit

Permalink
Show the VCS commit of the release if it is included in the crate
Browse files Browse the repository at this point in the history
Cargo has gained a feature where it records the package-time VCS commit:

* rust-lang/cargo#5886
* rust-lang/cargo#5629
  • Loading branch information
est31 committed Jan 12, 2019
1 parent d6b6c00 commit 607083c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cargo-local-serve/registry_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Crate {
repository :Option<String>,
description :String,
readme_html :Option<String>,
vcs_commit :Option<String>,
authors :Vec<Author>,
license :String,
versions :Vec<Version>,
Expand Down Expand Up @@ -81,6 +82,7 @@ pub fn winapi_crate_data() -> Map<String, Value> {
repository : Some("https://github.com/retep998/winapi-rs".to_string()),
description : "Types and constants for WinAPI bindings. See README for list of crates providing function bindings.".to_string(),
readme_html : None,
vcs_commit : None,
authors : vec![
Author {
name : "Peter Atashian".to_string(),
Expand Down Expand Up @@ -173,6 +175,26 @@ pub fn get_crate_data<C :CrateSource>(name :String, reg :&Registry, st :&mut C,
} else {
None
};

let vcs_commit = if let Some(c) = fh.get_file(
&format!("{}-{}/{}", name, version, ".cargo_vcs_info.json")) {
if let Ok(s) = String::from_utf8(c) {
#[derive(Deserialize)]
struct Git {
sha1 :String,
}
#[derive(Deserialize)]
struct VcsJson {
git :Git,
}
let vcs_json :Option<VcsJson> = serde_json::from_str(&s).ok();
vcs_json.map(|v| v.git.sha1)
} else {
None
}
} else {
None
};
let versions = crate_json.iter()
.map(|v| v.version.clone())
.collect::<Vec<_>>();
Expand All @@ -197,6 +219,7 @@ pub fn get_crate_data<C :CrateSource>(name :String, reg :&Registry, st :&mut C,
repository : info.package.repository,
description : info.package.description,
readme_html : readme_html,
vcs_commit,
authors : info.package.authors.iter()
.map(|s| Author::from_str(&s)).collect(),
license : info.package.license,
Expand Down
3 changes: 3 additions & 0 deletions cargo-local-serve/site/templates/crate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<li><a href="{{c.documentation}}">Documentation</a></li>
{{#if c.repository}}
<li><a href="{{c.repository}}">Repository</a></li>
{{#if c.vcs_commit}}
<li><a href="{{c.repository}}/commit/{{c.vcs_commit}}">Commit link</a></li>
{{/if}}
{{/if}}
<li><a href="/reverse_dependencies/{{c.name}}/">Dependent crates</a></li>
<li><a href="/files/{{c.name}}/{{c.version}}/">Browse files</a></li>
Expand Down

0 comments on commit 607083c

Please sign in to comment.