[cache][partial] Compute a partial cache path internally.

Previously Infra passed /path/to/cache/ or /path/to/cache/partial when
init'ing Jiri, however in order to actually land partial clones, we will
need to dynamically decide which repos should use partial clones so Jiri
needs to pick the correct cache internally.

Bug: 34965
Change-Id: Id96166e0f38be1dde665f0699de0ab7d6c8c5ee5
Reviewed-on: https://fuchsia-review.googlesource.com/c/jiri/+/430237
Reviewed-by: Haowei Wu <haowei@google.com>
Commit-Queue: Nathan Mulcahey <nmulcahey@google.com>
diff --git a/project/loader.go b/project/loader.go
index c6d91ed..6ff1563 100644
--- a/project/loader.go
+++ b/project/loader.go
@@ -555,7 +555,7 @@
 		remote.Name = filepath.Join(nextRoot, remote.Name)
 		key := remote.ProjectKey()
 		p, ok := ld.localProjects[key]
-		cacheDirPath, err := cacheDirPathFromRemote(jirix.Cache, remote.Remote)
+		cacheDirPath, err := cacheDirPathFromRemote(jirix, remote.Remote)
 		if err != nil {
 			return err
 		}
diff --git a/project/project.go b/project/project.go
index 8a4a060..8377344 100644
--- a/project/project.go
+++ b/project/project.go
@@ -567,14 +567,17 @@
 	return remote, nil
 }
 
-func cacheDirPathFromRemote(cacheRoot, remote string) (string, error) {
-	if cacheRoot != "" {
+func cacheDirPathFromRemote(jirix *jiri.X, remote string) (string, error) {
+	if jirix.Cache != "" {
 		url, err := url.Parse(remote)
 		if err != nil {
 			return "", err
 		}
 		dirname := url.Host + strings.Replace(strings.Replace(url.Path, "-", "--", -1), "/", "-", -1)
-		referenceDir := filepath.Join(cacheRoot, dirname)
+		referenceDir := filepath.Join(jirix.Cache, dirname)
+		if jirix.Partial {
+			referenceDir = filepath.Join(jirix.Cache, "partial", dirname)
+		}
 		return referenceDir, nil
 	}
 	return "", nil
@@ -583,7 +586,7 @@
 // CacheDirPath returns a generated path to a directory that can be used as a reference repo
 // for the given project.
 func (p *Project) CacheDirPath(jirix *jiri.X) (string, error) {
-	return cacheDirPathFromRemote(jirix.Cache, p.Remote)
+	return cacheDirPathFromRemote(jirix, p.Remote)
 
 }