]> git.proxmox.com Git - cargo.git/commitdiff
Use short IDs in git dependencies checkout path
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 28 Nov 2016 20:41:21 +0000 (21:41 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Mon, 28 Nov 2016 20:57:27 +0000 (21:57 +0100)
… in order to contribute less to the path length limit on Windows:
https://github.com/servo/servo/pull/14397

src/cargo/sources/git/source.rs
src/cargo/sources/git/utils.rs

index 321fe4dfcd0d824c8e4187bd776404e13c1c0a99..0587d185f01421a705dd947c3f730d5e6b347ba8 100644 (file)
@@ -149,8 +149,13 @@ impl<'cfg> Source for GitSource<'cfg> {
             (self.remote.db_at(&db_path)?, actual_rev.unwrap())
         };
 
+        // Don’t use the full hash,
+        // to contribute less to reaching the path length limit on Windows:
+        // https://github.com/servo/servo/pull/14397
+        let short_id = repo.to_short_id(actual_rev.clone()).unwrap();
+
         let checkout_path = lock.parent().join("checkouts")
-            .join(&self.ident).join(actual_rev.to_string());
+            .join(&self.ident).join(short_id.as_str());
 
         // Copy the database to the checkout location. After this we could drop
         // the lock on the database as we no longer needed it, but we leave it
index 7452c1dbbf8e2bb00e91ca90c721ab622140ea77..3b3b005f3a03baec770160f878c838ae947c3f80 100644 (file)
@@ -19,6 +19,14 @@ impl fmt::Display for GitRevision {
     }
 }
 
+pub struct GitShortID(git2::Buf);
+
+impl GitShortID {
+    pub fn as_str(&self) -> &str {
+        self.0.as_str().unwrap()
+    }
+}
+
 /// GitRemote represents a remote repository. It gets cloned into a local
 /// GitDatabase.
 #[derive(PartialEq,Clone,Debug)]
@@ -215,6 +223,11 @@ impl GitDatabase {
         Ok(GitRevision(id))
     }
 
+    pub fn to_short_id(&self, revision: GitRevision) -> CargoResult<GitShortID> {
+        let obj = self.repo.find_object(revision.0, None)?;
+        Ok(GitShortID(obj.short_id()?))
+    }
+
     pub fn has_ref(&self, reference: &str) -> CargoResult<()> {
         self.repo.revparse_single(reference)?;
         Ok(())