]> git.proxmox.com Git - cargo.git/commitdiff
Preserve multiline top comments
authorDale Wijnand <dale.wijnand@gmail.com>
Thu, 18 Oct 2018 05:44:12 +0000 (06:44 +0100)
committerDale Wijnand <dale.wijnand@gmail.com>
Thu, 18 Oct 2018 05:44:12 +0000 (06:44 +0100)
src/cargo/ops/lockfile.rs
tests/testsuite/update.rs

index 4deb7d116655a0cbd9b73e0e68d69ccc2c92e2b6..10387626481e1ba2e21f51ac82370b52182585be 100644 (file)
@@ -43,12 +43,10 @@ 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() {
-            if first_line.starts_with("#") {
-                out.push_str(first_line);
-                out.push_str("\n");
-            }
+    if let Ok(orig) = &orig {
+        for line in orig.lines().take_while(|line| line.starts_with("#")) {
+            out.push_str(line);
+            out.push_str("\n");
         }
     }
 
index 0b120daa9034e4cbfe4bbd69c75b6e30d2e3a3a4..be527b288dbaccb3a605fe2fb2f11dd4f64d9c55 100644 (file)
@@ -383,6 +383,7 @@ fn preserve_top_comment() {
 
     let mut lockfile = p.read_file("Cargo.lock");
     lockfile.insert_str(0, "# @generated\n");
+    lockfile.insert_str(0, "# some other comment\n");
     println!("saving Cargo.lock contents:\n{}", lockfile);
 
     p.change_file("Cargo.lock", &lockfile);