Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: lib/src/source/git.dart

Issue 1276673006: Make Source.getDirectory synchronous. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/source/cached.dart ('k') | lib/src/source/hosted.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source/git.dart
diff --git a/lib/src/source/git.dart b/lib/src/source/git.dart
index 8bd75c3d517ed8012970b64fad7b30b94c5c03c2..8211f5ce65828118e6ecfd2f5af2a6287a7e7895 100644
--- a/lib/src/source/git.dart
+++ b/lib/src/source/git.dart
@@ -58,34 +58,33 @@ class GitSource extends CachedSource {
/// `<package name>-<url hash>`. These are used to check out the repository
/// itself; each of the commit-specific directories are clones of a directory
/// in `cache/`.
- Future<Package> downloadToSystemCache(PackageId id) {
- var revisionCachePath;
-
+ Future<Package> downloadToSystemCache(PackageId id) async {
if (!git.isInstalled) {
fail("Cannot get ${id.name} from Git (${_getUrl(id)}).\n"
"Please ensure Git is correctly installed.");
}
ensureDir(path.join(systemCacheRoot, 'cache'));
- return _ensureRevision(id).then((_) => getDirectory(id)).then((path) {
- revisionCachePath = path;
- if (entryExists(revisionCachePath)) return null;
- return _clone(_repoCachePath(id), revisionCachePath, mirror: false);
- }).then((_) {
- var ref = _getEffectiveRef(id);
- if (ref == 'HEAD') return null;
- return _checkOut(revisionCachePath, ref);
- }).then((_) {
- return new Package.load(id.name, revisionCachePath, systemCache.sources);
- });
+ await _ensureRevision(id);
+ var revisionCachePath = getDirectory(await resolveId(id));
+ if (!entryExists(revisionCachePath)) {
+ await _clone(_repoCachePath(id), revisionCachePath, mirror: false);
+ }
+
+ var ref = _getEffectiveRef(id);
+ if (ref != 'HEAD') await _checkOut(revisionCachePath, ref);
+
+ return new Package.load(id.name, revisionCachePath, systemCache.sources);
}
/// Returns the path to the revision-specific cache of [id].
- Future<String> getDirectory(PackageId id) {
- return _ensureRevision(id).then((rev) {
- var revisionCacheName = '${id.name}-$rev';
- return path.join(systemCacheRoot, revisionCacheName);
- });
+ String getDirectory(PackageId id) {
+ if (id.description is! Map || !id.description.containsKey('resolved-ref')) {
+ throw new ArgumentError("Can't get the directory for unresolved id $id.");
+ }
+
+ return path.join(systemCacheRoot,
+ "${id.name}-${id.description['resolved-ref']}");
}
/// Ensures [description] is a Git URL.
« no previous file with comments | « lib/src/source/cached.dart ('k') | lib/src/source/hosted.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698