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

Side by Side Diff: utils/pub/git_source.dart

Issue 12171002: Tweak SDK constraint checking a bit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 git_source; 5 library git_source;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'git.dart' as git; 8 import 'git.dart' as git;
9 import 'io.dart'; 9 import 'io.dart';
10 import 'package.dart'; 10 import 'package.dart';
(...skipping 26 matching lines...) Expand all
37 37
38 return git.isInstalled.then((installed) { 38 return git.isInstalled.then((installed) {
39 if (!installed) { 39 if (!installed) {
40 throw new Exception( 40 throw new Exception(
41 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n" 41 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n"
42 "Please ensure Git is correctly installed."); 42 "Please ensure Git is correctly installed.");
43 } 43 }
44 44
45 return ensureDir(join(systemCacheRoot, 'cache')); 45 return ensureDir(join(systemCacheRoot, 'cache'));
46 }).then((_) => _ensureRepoCache(id)) 46 }).then((_) => _ensureRepoCache(id))
47 .then((_) => _revisionCachePath(id)) 47 .then((_) => systemCacheDirectory(id))
48 .then((path) { 48 .then((path) {
49 revisionCachePath = path; 49 revisionCachePath = path;
50 return exists(revisionCachePath); 50 return exists(revisionCachePath);
51 }).then((exists) { 51 }).then((exists) {
52 if (exists) return; 52 if (exists) return;
53 return _clone(_repoCachePath(id), revisionCachePath, mirror: false); 53 return _clone(_repoCachePath(id), revisionCachePath, mirror: false);
54 }).then((_) { 54 }).then((_) {
55 var ref = _getEffectiveRef(id); 55 var ref = _getEffectiveRef(id);
56 if (ref == 'HEAD') return; 56 if (ref == 'HEAD') return;
57 return _checkOut(revisionCachePath, ref); 57 return _checkOut(revisionCachePath, ref);
58 }).then((_) { 58 }).then((_) {
59 return Package.load(id.name, revisionCachePath, systemCache.sources); 59 return Package.load(id.name, revisionCachePath, systemCache.sources);
60 }); 60 });
61 } 61 }
62 62
63 Future<String> systemCacheDirectory(PackageId id) => _revisionCachePath(id); 63 /// Returns the path to the revision-specific cache of [id].
64 64 Future<String> systemCacheDirectory(PackageId id) {
65 return _revisionAt(id).then((rev) {
66 var revisionCacheName = '${id.name}-$rev';
67 return join(systemCacheRoot, revisionCacheName);
68 });
69 }
nweiz 2013/02/02 00:15:29 Style nit: extra line needed below here
65 /// Ensures [description] is a Git URL. 70 /// Ensures [description] is a Git URL.
66 void validateDescription(description, {bool fromLockFile: false}) { 71 void validateDescription(description, {bool fromLockFile: false}) {
67 // A single string is assumed to be a Git URL. 72 // A single string is assumed to be a Git URL.
68 if (description is String) return; 73 if (description is String) return;
69 if (description is! Map || !description.containsKey('url')) { 74 if (description is! Map || !description.containsKey('url')) {
70 throw new FormatException("The description must be a Git URL or a map " 75 throw new FormatException("The description must be a Git URL or a map "
71 "with a 'url' key."); 76 "with a 'url' key.");
72 } 77 }
73 description = new Map.from(description); 78 description = new Map.from(description);
74 description.remove('url'); 79 description.remove('url');
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return git.run(["fetch"], workingDir: path).then((result) => null); 118 return git.run(["fetch"], workingDir: path).then((result) => null);
114 }); 119 });
115 } 120 }
116 121
117 /// Returns a future that completes to the revision hash of [id]. 122 /// Returns a future that completes to the revision hash of [id].
118 Future<String> _revisionAt(PackageId id) { 123 Future<String> _revisionAt(PackageId id) {
119 return git.run(["rev-parse", _getEffectiveRef(id)], 124 return git.run(["rev-parse", _getEffectiveRef(id)],
120 workingDir: _repoCachePath(id)).then((result) => result[0]); 125 workingDir: _repoCachePath(id)).then((result) => result[0]);
121 } 126 }
122 127
123 /// Returns the path to the revision-specific cache of [id].
124 Future<String> _revisionCachePath(PackageId id) {
125 return _revisionAt(id).then((rev) {
126 var revisionCacheName = '${id.name}-$rev';
127 return join(systemCacheRoot, revisionCacheName);
128 });
129 }
130
131 /// Clones the repo at the URI [from] to the path [to] on the local 128 /// Clones the repo at the URI [from] to the path [to] on the local
132 /// filesystem. 129 /// filesystem.
133 /// 130 ///
134 /// If [mirror] is true, create a bare, mirrored clone. This doesn't check out 131 /// If [mirror] is true, create a bare, mirrored clone. This doesn't check out
135 /// the working tree, but instead makes the repository a local mirror of the 132 /// the working tree, but instead makes the repository a local mirror of the
136 /// remote repository. See the manpage for `git clone` for more information. 133 /// remote repository. See the manpage for `git clone` for more information.
137 Future _clone(String from, String to, {bool mirror: false}) { 134 Future _clone(String from, String to, {bool mirror: false}) {
138 // Git on Windows does not seem to automatically create the destination 135 // Git on Windows does not seem to automatically create the destination
139 // directory. 136 // directory.
140 return ensureDir(to).then((_) { 137 return ensureDir(to).then((_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return description['ref']; 190 return description['ref'];
194 } 191 }
195 192
196 /// Returns [description] if it's a description, or [PackageId.description] if 193 /// Returns [description] if it's a description, or [PackageId.description] if
197 /// it's a [PackageId]. 194 /// it's a [PackageId].
198 _getDescription(description) { 195 _getDescription(description) {
199 if (description is PackageId) return description.description; 196 if (description is PackageId) return description.description;
200 return description; 197 return description;
201 } 198 }
202 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698