Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve lockfile top comment #6181

Merged
merged 5 commits into from
Oct 18, 2018

Conversation

dwijnand
Copy link
Member

Refs #6180

@rust-highfive
Copy link

r? @matklad

(rust_highfive has picked a reviewer for you, use r? to override)

@dwijnand
Copy link
Member Author

r? @alexcrichton

WDYT?

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that was quite easy, thanks!

@@ -43,6 +43,15 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()>

let mut out = String::new();

if let Ok(ref orig) = orig {
if let Some(first_line) = orig.lines().into_iter().next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this perhaps be...

if let Ok(orig) = &orig {
    for line in org.lines().take_while(|line| line.starts_with("#")) {
        out.push_str(line);
        out.push_str("\n");
    }
}

That way we can preserve multiline comments if necessary as well

println!("loaded Cargo.lock contents:\n{}", lockfile2);

let first_line = lockfile2.lines().into_iter().next().unwrap();
assert!(first_line == "# @generated");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just asserting the first line, could this assert that the lock files are byte-for-byte equal the most recent lockfile does indeed contain @generated?

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Oct 18, 2018

📌 Commit 32fbfe3 has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Oct 18, 2018

⌛ Testing commit 32fbfe3 with merge 8522a88...

bors added a commit that referenced this pull request Oct 18, 2018
@bors
Copy link
Collaborator

bors commented Oct 18, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 8522a88 to master...

@bors bors merged commit 32fbfe3 into rust-lang:master Oct 18, 2018
@dwijnand dwijnand deleted the preserve-lockfile-top-comment branch October 18, 2018 15:49
@ehuss ehuss added this to the 1.31.0 milestone Feb 6, 2022
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.

6 participants