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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/src/source/cached.dart ('k') | lib/src/source/hosted.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub.source.git; 5 library pub.source.git;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 /// The Git cache directory is a little idiosyncratic. At the top level, it 51 /// The Git cache directory is a little idiosyncratic. At the top level, it
52 /// contains a directory for each commit of each repository, named `<package 52 /// contains a directory for each commit of each repository, named `<package
53 /// name>-<commit hash>`. These are the canonical package directories that are 53 /// name>-<commit hash>`. These are the canonical package directories that are
54 /// linked to from the `packages/` directory. 54 /// linked to from the `packages/` directory.
55 /// 55 ///
56 /// In addition, the Git system cache contains a subdirectory named `cache/` 56 /// In addition, the Git system cache contains a subdirectory named `cache/`
57 /// which contains a directory for each separate repository URL, named 57 /// which contains a directory for each separate repository URL, named
58 /// `<package name>-<url hash>`. These are used to check out the repository 58 /// `<package name>-<url hash>`. These are used to check out the repository
59 /// itself; each of the commit-specific directories are clones of a directory 59 /// itself; each of the commit-specific directories are clones of a directory
60 /// in `cache/`. 60 /// in `cache/`.
61 Future<Package> downloadToSystemCache(PackageId id) { 61 Future<Package> downloadToSystemCache(PackageId id) async {
62 var revisionCachePath;
63
64 if (!git.isInstalled) { 62 if (!git.isInstalled) {
65 fail("Cannot get ${id.name} from Git (${_getUrl(id)}).\n" 63 fail("Cannot get ${id.name} from Git (${_getUrl(id)}).\n"
66 "Please ensure Git is correctly installed."); 64 "Please ensure Git is correctly installed.");
67 } 65 }
68 66
69 ensureDir(path.join(systemCacheRoot, 'cache')); 67 ensureDir(path.join(systemCacheRoot, 'cache'));
70 return _ensureRevision(id).then((_) => getDirectory(id)).then((path) { 68 await _ensureRevision(id);
71 revisionCachePath = path; 69 var revisionCachePath = getDirectory(await resolveId(id));
72 if (entryExists(revisionCachePath)) return null; 70 if (!entryExists(revisionCachePath)) {
73 return _clone(_repoCachePath(id), revisionCachePath, mirror: false); 71 await _clone(_repoCachePath(id), revisionCachePath, mirror: false);
74 }).then((_) { 72 }
75 var ref = _getEffectiveRef(id); 73
76 if (ref == 'HEAD') return null; 74 var ref = _getEffectiveRef(id);
77 return _checkOut(revisionCachePath, ref); 75 if (ref != 'HEAD') await _checkOut(revisionCachePath, ref);
78 }).then((_) { 76
79 return new Package.load(id.name, revisionCachePath, systemCache.sources); 77 return new Package.load(id.name, revisionCachePath, systemCache.sources);
80 });
81 } 78 }
82 79
83 /// Returns the path to the revision-specific cache of [id]. 80 /// Returns the path to the revision-specific cache of [id].
84 Future<String> getDirectory(PackageId id) { 81 String getDirectory(PackageId id) {
85 return _ensureRevision(id).then((rev) { 82 if (id.description is! Map || !id.description.containsKey('resolved-ref')) {
86 var revisionCacheName = '${id.name}-$rev'; 83 throw new ArgumentError("Can't get the directory for unresolved id $id.");
87 return path.join(systemCacheRoot, revisionCacheName); 84 }
88 }); 85
86 return path.join(systemCacheRoot,
87 "${id.name}-${id.description['resolved-ref']}");
89 } 88 }
90 89
91 /// Ensures [description] is a Git URL. 90 /// Ensures [description] is a Git URL.
92 dynamic parseDescription(String containingPath, description, 91 dynamic parseDescription(String containingPath, description,
93 {bool fromLockFile: false}) { 92 {bool fromLockFile: false}) {
94 // TODO(rnystrom): Handle git URLs that are relative file paths (#8570). 93 // TODO(rnystrom): Handle git URLs that are relative file paths (#8570).
95 // TODO(rnystrom): Now that this function can modify the description, it 94 // TODO(rnystrom): Now that this function can modify the description, it
96 // may as well canonicalize it to a map so that other code in the source 95 // may as well canonicalize it to a map so that other code in the source
97 // can assume that. 96 // can assume that.
98 // A single string is assumed to be a Git URL. 97 // A single string is assumed to be a Git URL.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return description['ref']; 332 return description['ref'];
334 } 333 }
335 334
336 /// Returns [description] if it's a description, or [PackageId.description] if 335 /// Returns [description] if it's a description, or [PackageId.description] if
337 /// it's a [PackageId]. 336 /// it's a [PackageId].
338 _getDescription(description) { 337 _getDescription(description) {
339 if (description is PackageId) return description.description; 338 if (description is PackageId) return description.description;
340 return description; 339 return description;
341 } 340 }
342 } 341 }
OLDNEW
« 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