OLD | NEW |
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('git_source'); | 5 #library('git_source'); |
6 | 6 |
7 #import('io.dart'); | 7 #import('io.dart'); |
8 #import('package.dart'); | 8 #import('package.dart'); |
9 #import('source.dart'); | 9 #import('source.dart'); |
10 #import('source_registry.dart'); | 10 #import('source_registry.dart'); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 .chain((path) { | 50 .chain((path) { |
51 revisionCachePath = path; | 51 revisionCachePath = path; |
52 return exists(revisionCachePath); | 52 return exists(revisionCachePath); |
53 }).chain((exists) { | 53 }).chain((exists) { |
54 if (exists) return new Future.immediate(null); | 54 if (exists) return new Future.immediate(null); |
55 return _clone(_repoCachePath(id), revisionCachePath, mirror: false); | 55 return _clone(_repoCachePath(id), revisionCachePath, mirror: false); |
56 }).chain((_) { | 56 }).chain((_) { |
57 var ref = _getEffectiveRef(id); | 57 var ref = _getEffectiveRef(id); |
58 if (ref == 'HEAD') return new Future.immediate(null); | 58 if (ref == 'HEAD') return new Future.immediate(null); |
59 return _checkOut(revisionCachePath, ref); | 59 return _checkOut(revisionCachePath, ref); |
60 }).chain((_) => Package.load(revisionCachePath, systemCache.sources)); | 60 }).chain((_) { |
| 61 return Package.load(id.name, revisionCachePath, systemCache.sources); |
| 62 }); |
61 } | 63 } |
62 | 64 |
63 /** | 65 /** |
64 * The package name of a Git repo is the name of the directory into which | |
65 * it'll be cloned. | |
66 */ | |
67 String packageName(description) { | |
68 return basename(_getUrl(description) | |
69 .replaceFirst(const RegExp(@"(\.git)?/?$"), "")); | |
70 } | |
71 | |
72 /** | |
73 * Ensures [description] is a Git URL. | 66 * Ensures [description] is a Git URL. |
74 */ | 67 */ |
75 void validateDescription(description, [bool fromLockFile = false]) { | 68 void validateDescription(description, [bool fromLockFile = false]) { |
76 // A single string is assumed to be a Git URL. | 69 // A single string is assumed to be a Git URL. |
77 if (description is String) return; | 70 if (description is String) return; |
78 if (description is! Map || !description.containsKey('url')) { | 71 if (description is! Map || !description.containsKey('url')) { |
79 throw new FormatException("The description must be a Git URL or a map " | 72 throw new FormatException("The description must be a Git URL or a map " |
80 "with a 'url' key."); | 73 "with a 'url' key."); |
81 } | 74 } |
82 description = new Map.from(description); | 75 description = new Map.from(description); |
(...skipping 19 matching lines...) Expand all Loading... |
102 _getRef(description1) == _getRef(description2); | 95 _getRef(description1) == _getRef(description2); |
103 } | 96 } |
104 | 97 |
105 /** | 98 /** |
106 * Attaches a specific commit to [id] to disambiguate it. | 99 * Attaches a specific commit to [id] to disambiguate it. |
107 */ | 100 */ |
108 Future<PackageId> resolveId(PackageId id) { | 101 Future<PackageId> resolveId(PackageId id) { |
109 return _revisionAt(id).transform((revision) { | 102 return _revisionAt(id).transform((revision) { |
110 var description = {'url': _getUrl(id), 'ref': _getRef(id)}; | 103 var description = {'url': _getUrl(id), 'ref': _getRef(id)}; |
111 description['resolved-ref'] = revision; | 104 description['resolved-ref'] = revision; |
112 return new PackageId(this, id.version, description); | 105 return new PackageId(id.name, this, id.version, description); |
113 }); | 106 }); |
114 } | 107 } |
115 | 108 |
116 /** | 109 /** |
117 * Ensure that the canonical clone of the repository referred to by [id] (the | 110 * Ensure that the canonical clone of the repository referred to by [id] (the |
118 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a | 111 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a |
119 * future that completes once this is finished and throws an exception if it | 112 * future that completes once this is finished and throws an exception if it |
120 * fails. | 113 * fails. |
121 */ | 114 */ |
122 Future _ensureRepoCache(PackageId id) { | 115 Future _ensureRepoCache(PackageId id) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 223 |
231 /** | 224 /** |
232 * Returns [description] if it's a description, or [PackageId.description] if | 225 * Returns [description] if it's a description, or [PackageId.description] if |
233 * it's a [PackageId]. | 226 * it's a [PackageId]. |
234 */ | 227 */ |
235 _getDescription(description) { | 228 _getDescription(description) { |
236 if (description is PackageId) return description.description; | 229 if (description is PackageId) return description.description; |
237 return description; | 230 return description; |
238 } | 231 } |
239 } | 232 } |
OLD | NEW |