| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 * Ensure that the canonical clone of the repository referred to by [id] (the | 115 * Ensure that the canonical clone of the repository referred to by [id] (the |
| 116 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a | 116 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a |
| 117 * future that completes once this is finished and throws an exception if it | 117 * future that completes once this is finished and throws an exception if it |
| 118 * fails. | 118 * fails. |
| 119 */ | 119 */ |
| 120 Future _ensureRepoCache(PackageId id) { | 120 Future _ensureRepoCache(PackageId id) { |
| 121 var path = _repoCachePath(id); | 121 var path = _repoCachePath(id); |
| 122 return exists(path).chain((exists) { | 122 return exists(path).chain((exists) { |
| 123 if (!exists) return _clone(_getUrl(id), path); | 123 if (!exists) return _clone(_getUrl(id), path); |
| 124 | 124 |
| 125 return runProcess("git", ["pull", "--force"], workingDir: path, | 125 return runProcess("git", ["pull", "--force"], workingDir: path) |
| 126 pipeStdout: true, pipeStderr: true).transform((result) { | 126 .transform((result) { |
| 127 if (!result.success) throw 'Git failed.'; | 127 if (!result.success) throw 'Git failed.'; |
| 128 return null; | 128 return null; |
| 129 }); | 129 }); |
| 130 }); | 130 }); |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Returns a future that completes to the revision hash of [id]. | 134 * Returns a future that completes to the revision hash of [id]. |
| 135 */ | 135 */ |
| 136 Future<String> _revisionAt(PackageId id) { | 136 Future<String> _revisionAt(PackageId id) { |
| 137 return runProcess("git", ["rev-parse", _getEffectiveRef(id)], | 137 return runProcess("git", ["rev-parse", _getEffectiveRef(id)], |
| 138 workingDir: _repoCachePath(id), pipeStderr: true).transform((result) { | 138 workingDir: _repoCachePath(id)).transform((result) { |
| 139 if (!result.success) throw 'Git failed.'; | 139 if (!result.success) throw 'Git failed.'; |
| 140 return result.stdout[0]; | 140 return result.stdout[0]; |
| 141 }); | 141 }); |
| 142 } | 142 } |
| 143 | 143 |
| 144 /** | 144 /** |
| 145 * Returns the path to the revision-specific cache of [id]. | 145 * Returns the path to the revision-specific cache of [id]. |
| 146 */ | 146 */ |
| 147 Future<String> _revisionCachePath(PackageId id) { | 147 Future<String> _revisionCachePath(PackageId id) { |
| 148 return _revisionAt(id).transform((rev) { | 148 return _revisionAt(id).transform((rev) { |
| 149 var revisionCacheName = '${id.name}-$rev'; | 149 var revisionCacheName = '${id.name}-$rev'; |
| 150 return join(systemCacheRoot, revisionCacheName); | 150 return join(systemCacheRoot, revisionCacheName); |
| 151 }); | 151 }); |
| 152 } | 152 } |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * Clones the repo at the URI [from] to the path [to] on the local filesystem. | 155 * Clones the repo at the URI [from] to the path [to] on the local filesystem. |
| 156 */ | 156 */ |
| 157 Future _clone(String from, String to) { | 157 Future _clone(String from, String to) { |
| 158 return runProcess("git", ["clone", from, to], pipeStdout: true, | 158 return runProcess("git", ["clone", from, to]).transform((result) { |
| 159 pipeStderr: true).transform((result) { | |
| 160 if (!result.success) throw 'Git failed.'; | 159 if (!result.success) throw 'Git failed.'; |
| 161 return null; | 160 return null; |
| 162 }); | 161 }); |
| 163 } | 162 } |
| 164 | 163 |
| 165 /** | 164 /** |
| 166 * Checks out the reference [ref] in [repoPath]. | 165 * Checks out the reference [ref] in [repoPath]. |
| 167 */ | 166 */ |
| 168 Future _checkOut(String repoPath, String ref) { | 167 Future _checkOut(String repoPath, String ref) { |
| 169 return runProcess("git", ["checkout", ref], pipeStdout: true, | 168 return runProcess("git", ["checkout", ref], workingDir: repoPath) |
| 170 pipeStderr: true, workingDir: repoPath).transform((result) { | 169 .transform((result) { |
| 171 if (!result.success) throw 'Git failed.'; | 170 if (!result.success) throw 'Git failed.'; |
| 172 return null; | 171 return null; |
| 173 }); | 172 }); |
| 174 } | 173 } |
| 175 | 174 |
| 176 /** | 175 /** |
| 177 * Returns the path to the canonical clone of the repository referred to by | 176 * Returns the path to the canonical clone of the repository referred to by |
| 178 * [id] (the one in `<system cache>/git/cache`). | 177 * [id] (the one in `<system cache>/git/cache`). |
| 179 */ | 178 */ |
| 180 String _repoCachePath(PackageId id) { | 179 String _repoCachePath(PackageId id) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 224 |
| 226 /** | 225 /** |
| 227 * Returns [description] if it's a description, or [PackageId.description] if | 226 * Returns [description] if it's a description, or [PackageId.description] if |
| 228 * it's a [PackageId]. | 227 * it's a [PackageId]. |
| 229 */ | 228 */ |
| 230 _getDescription(description) { | 229 _getDescription(description) { |
| 231 if (description is PackageId) return description.description; | 230 if (description is PackageId) return description.description; |
| 232 return description; | 231 return description; |
| 233 } | 232 } |
| 234 } | 233 } |
| OLD | NEW |