GitSource delegates to PathSource for path ops
authorCarl Lerche <me@carllerche.com>
Tue, 24 Jun 2014 00:03:13 +0000 (17:03 -0700)
committerCarl Lerche <me@carllerche.com>
Tue, 24 Jun 2014 00:03:39 +0000 (17:03 -0700)
src/bin/cargo-read-manifest.rs
src/cargo/sources/git/source.rs
src/cargo/sources/path.rs

index b8125bf843aaa120937116534d9930816805fb79..4e98f1850f9716e9823e583f5341f8102610a442 100644 (file)
@@ -8,7 +8,7 @@ extern crate serialize;
 extern crate hammer;
 
 use cargo::{execute_main_without_stdin};
-use cargo::core::{MultiShell, Package, Source, SourceId};
+use cargo::core::{MultiShell, Package, Source};
 use cargo::util::{CliResult, CliError};
 use cargo::sources::{PathSource};
 
index 724be4f416338fe50779d3705a8d0a0068ee13fb..3894183b9aab2b953b63252e238ef8355498eb52 100644 (file)
@@ -7,20 +7,20 @@ use serialize::hex::ToHex;
 use url;
 use url::Url;
 
-use ops;
 use core::source::{Source,SourceId,GitKind};
 use core::{Package,PackageId,Summary};
 use util::{CargoResult,Config};
+use sources::PathSource;
 use sources::git::utils::{GitReference,GitRemote,Master,Other};
 
 /* TODO: Refactor GitSource to delegate to a PathSource
  */
 pub struct GitSource<'a, 'b> {
-    id: SourceId,
     remote: GitRemote,
     reference: GitReference,
     db_path: Path,
     checkout_path: Path,
+    path_source: PathSource,
     config: &'a mut Config<'b>
 }
 
@@ -42,12 +42,14 @@ impl<'a, 'b> GitSource<'a, 'b> {
         let checkout_path = config.git_checkout_path()
             .join(ident.as_slice()).join(reference.as_slice());
 
+        let path_source = PathSource::new(&checkout_path, source_id);
+
         GitSource {
-            id: source_id.clone(),
             remote: remote,
             reference: GitReference::for_str(reference.as_slice()),
             db_path: db_path,
             checkout_path: checkout_path,
+            path_source: path_source,
             config: config
         }
     }
@@ -55,10 +57,6 @@ impl<'a, 'b> GitSource<'a, 'b> {
     pub fn get_namespace<'a>(&'a self) -> &'a url::Url {
         self.remote.get_url()
     }
-
-    fn packages(&self) -> CargoResult<Vec<Package>> {
-        ops::read_packages(&self.checkout_path, &self.id)
-    }
 }
 
 fn ident(url: &Url) -> String {
@@ -101,30 +99,21 @@ impl<'a, 'b> Source for GitSource<'a, 'b> {
         let repo = try!(self.remote.checkout(&self.db_path));
         try!(repo.copy_to(self.reference.as_slice(), &self.checkout_path));
 
-        Ok(())
+        self.path_source.update()
     }
 
     fn list(&self) -> CargoResult<Vec<Summary>> {
-        log!(5, "listing summaries in git source `{}`", self.remote);
-        let pkgs = try!(self.packages());
-        Ok(pkgs.iter().map(|p| p.get_summary().clone()).collect())
+        self.path_source.list()
     }
 
     fn download(&self, _: &[PackageId]) -> CargoResult<()> {
+        // TODO: assert! that the PackageId is contained by the source
         Ok(())
     }
 
     fn get(&self, ids: &[PackageId]) -> CargoResult<Vec<Package>> {
-        log!(5, "getting packages for package ids `{}` from `{}`", ids,
-             self.remote);
-
-        // TODO: Support multiple manifests per repo
-        let pkgs = try!(self.packages());
-
-        Ok(pkgs.iter()
-           .filter(|pkg| ids.iter().any(|id| pkg.get_package_id() == id))
-           .map(|pkg| pkg.clone())
-           .collect())
+        log!(5, "getting packages for package ids `{}` from `{}`", ids, self.remote);
+        self.path_source.get(ids)
     }
 
     fn fingerprint(&self) -> CargoResult<String> {
index c5dc5444c2c3fef6855efef363cb3270e49acc45..225b35c0247da3d556778248c5bcbe2744f12862 100644 (file)
@@ -27,7 +27,6 @@ impl PathSource {
     /// in the directory structure reachable by the root manifest.
     pub fn new(path: &Path, id: &SourceId) -> PathSource {
         log!(5, "new; id={}", id);
-        assert!(id.is_path(), "does not represent a path source; id={}", id);
 
         PathSource {
             id: id.clone(),