Chromium Code Reviews| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../../pkg/path/lib/path.dart' as path; | 9 import '../../pkg/path/lib/path.dart' as path; |
| 10 | 10 |
| 11 import 'git.dart' as git; | 11 import 'git.dart' as git; |
| 12 import 'io.dart'; | 12 import 'io.dart'; |
| 13 import 'log.dart' as log; | |
| 13 import 'package.dart'; | 14 import 'package.dart'; |
| 14 import 'source.dart'; | 15 import 'source.dart'; |
| 15 import 'source_registry.dart'; | 16 import 'source_registry.dart'; |
| 16 import 'utils.dart'; | 17 import 'utils.dart'; |
| 17 | 18 |
| 18 /// A package source that installs packages from Git repos. | 19 /// A package source that installs packages from Git repos. |
| 19 class GitSource extends Source { | 20 class GitSource extends Source { |
| 20 final String name = "git"; | 21 final String name = "git"; |
| 21 | 22 |
| 22 final bool shouldCache = true; | 23 final bool shouldCache = true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 }); | 61 }); |
| 61 } | 62 } |
| 62 | 63 |
| 63 /// Returns the path to the revision-specific cache of [id]. | 64 /// Returns the path to the revision-specific cache of [id]. |
| 64 Future<String> systemCacheDirectory(PackageId id) { | 65 Future<String> systemCacheDirectory(PackageId id) { |
| 65 return _revisionAt(id).then((rev) { | 66 return _revisionAt(id).then((rev) { |
| 66 var revisionCacheName = '${id.name}-$rev'; | 67 var revisionCacheName = '${id.name}-$rev'; |
| 67 return path.join(systemCacheRoot, revisionCacheName); | 68 return path.join(systemCacheRoot, revisionCacheName); |
| 68 }); | 69 }); |
| 69 } | 70 } |
| 71 | |
| 70 /// Ensures [description] is a Git URL. | 72 /// Ensures [description] is a Git URL. |
| 71 void validateDescription(description, {bool fromLockFile: false}) { | 73 dynamic parseDescription(String containingPath, description, |
| 74 {bool fromLockFile: false}) { | |
| 75 // TODO(rnystrom): Handle git URLs that are relative file paths. | |
|
nweiz
2013/02/15 23:09:24
Add a bug number. Also, it would be nice if we cou
Bob Nystrom
2013/02/16 00:09:57
Added a bug. I don't want to add any code here unl
| |
| 72 // A single string is assumed to be a Git URL. | 76 // A single string is assumed to be a Git URL. |
| 73 if (description is String) return; | 77 if (description is String) return description; |
|
nweiz
2013/02/15 23:09:24
It would make other code nicer if we canonicalized
Bob Nystrom
2013/02/16 00:09:57
Added a TODO.
| |
| 74 if (description is! Map || !description.containsKey('url')) { | 78 if (description is! Map || !description.containsKey('url')) { |
| 75 throw new FormatException("The description must be a Git URL or a map " | 79 throw new FormatException("The description must be a Git URL or a map " |
| 76 "with a 'url' key."); | 80 "with a 'url' key."); |
| 77 } | 81 } |
| 78 description = new Map.from(description); | |
| 79 description.remove('url'); | |
| 80 description.remove('ref'); | |
| 81 if (fromLockFile) description.remove('resolved-ref'); | |
| 82 | 82 |
| 83 if (!description.isEmpty) { | 83 var parsed = new Map.from(description); |
| 84 var plural = description.length > 1; | 84 parsed.remove('url'); |
| 85 var keys = description.keys.join(', '); | 85 parsed.remove('ref'); |
| 86 if (fromLockFile) parsed.remove('resolved-ref'); | |
| 87 | |
| 88 if (!parsed.isEmpty) { | |
| 89 var plural = parsed.length > 1; | |
| 90 var keys = parsed.keys.join(', '); | |
| 86 throw new FormatException("Invalid key${plural ? 's' : ''}: $keys."); | 91 throw new FormatException("Invalid key${plural ? 's' : ''}: $keys."); |
| 87 } | 92 } |
| 93 | |
| 94 return description; | |
| 88 } | 95 } |
| 89 | 96 |
| 90 /// Two Git descriptions are equal if both their URLs and their refs are | 97 /// Two Git descriptions are equal if both their URLs and their refs are |
| 91 /// equal. | 98 /// equal. |
| 92 bool descriptionsEqual(description1, description2) { | 99 bool descriptionsEqual(description1, description2) { |
| 93 // TODO(nweiz): Do we really want to throw an error if you have two | 100 // TODO(nweiz): Do we really want to throw an error if you have two |
| 94 // dependencies on some repo, one of which specifies a ref and one of which | 101 // dependencies on some repo, one of which specifies a ref and one of which |
| 95 // doesn't? If not, how do we handle that case in the version solver? | 102 // doesn't? If not, how do we handle that case in the version solver? |
| 96 return _getUrl(description1) == _getUrl(description2) && | 103 return _getUrl(description1) == _getUrl(description2) && |
| 97 _getRef(description1) == _getRef(description2); | 104 _getRef(description1) == _getRef(description2); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 return description['ref']; | 197 return description['ref']; |
| 191 } | 198 } |
| 192 | 199 |
| 193 /// Returns [description] if it's a description, or [PackageId.description] if | 200 /// Returns [description] if it's a description, or [PackageId.description] if |
| 194 /// it's a [PackageId]. | 201 /// it's a [PackageId]. |
| 195 _getDescription(description) { | 202 _getDescription(description) { |
| 196 if (description is PackageId) return description.description; | 203 if (description is PackageId) return description.description; |
| 197 return description; | 204 return description; |
| 198 } | 205 } |
| 199 } | 206 } |
| OLD | NEW |