| 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('git.dart', prefix: 'git'); |
| 7 #import('io.dart'); | 8 #import('io.dart'); |
| 8 #import('package.dart'); | 9 #import('package.dart'); |
| 9 #import('source.dart'); | 10 #import('source.dart'); |
| 10 #import('source_registry.dart'); | 11 #import('source_registry.dart'); |
| 11 #import('utils.dart'); | 12 #import('utils.dart'); |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * A package source that installs packages from Git repos. | 15 * A package source that installs packages from Git repos. |
| 15 */ | 16 */ |
| 16 class GitSource extends Source { | 17 class GitSource extends Source { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 * | 31 * |
| 31 * In addition, the Git system cache contains a subdirectory named `cache/` | 32 * In addition, the Git system cache contains a subdirectory named `cache/` |
| 32 * which contains a directory for each separate repository URL, named | 33 * which contains a directory for each separate repository URL, named |
| 33 * `<package name>-<url hash>`. These are used to check out the repository | 34 * `<package name>-<url hash>`. These are used to check out the repository |
| 34 * itself; each of the commit-specific directories are clones of a directory | 35 * itself; each of the commit-specific directories are clones of a directory |
| 35 * in `cache/`. | 36 * in `cache/`. |
| 36 */ | 37 */ |
| 37 Future<Package> installToSystemCache(PackageId id) { | 38 Future<Package> installToSystemCache(PackageId id) { |
| 38 var revisionCachePath; | 39 var revisionCachePath; |
| 39 | 40 |
| 40 return isGitInstalled.chain((installed) { | 41 return git.isInstalled.chain((installed) { |
| 41 if (!installed) { | 42 if (!installed) { |
| 42 throw new Exception( | 43 throw new Exception( |
| 43 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n" | 44 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n" |
| 44 "Please ensure Git is correctly installed."); | 45 "Please ensure Git is correctly installed."); |
| 45 } | 46 } |
| 46 | 47 |
| 47 return ensureDir(join(systemCacheRoot, 'cache')); | 48 return ensureDir(join(systemCacheRoot, 'cache')); |
| 48 }).chain((_) => _ensureRepoCache(id)) | 49 }).chain((_) => _ensureRepoCache(id)) |
| 49 .chain((_) => _revisionCachePath(id)) | 50 .chain((_) => _revisionCachePath(id)) |
| 50 .chain((path) { | 51 .chain((path) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 * Ensure that the canonical clone of the repository referred to by [id] (the | 111 * Ensure that the canonical clone of the repository referred to by [id] (the |
| 111 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a | 112 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a |
| 112 * future that completes once this is finished and throws an exception if it | 113 * future that completes once this is finished and throws an exception if it |
| 113 * fails. | 114 * fails. |
| 114 */ | 115 */ |
| 115 Future _ensureRepoCache(PackageId id) { | 116 Future _ensureRepoCache(PackageId id) { |
| 116 var path = _repoCachePath(id); | 117 var path = _repoCachePath(id); |
| 117 return exists(path).chain((exists) { | 118 return exists(path).chain((exists) { |
| 118 if (!exists) return _clone(_getUrl(id), path, mirror: true); | 119 if (!exists) return _clone(_getUrl(id), path, mirror: true); |
| 119 | 120 |
| 120 return runGit(["fetch"], workingDir: path).transform((result) { | 121 return git.run(["fetch"], workingDir: path).transform((result) => null); |
| 121 if (!result.success) throw 'Git failed.'; | |
| 122 return null; | |
| 123 }); | |
| 124 }); | 122 }); |
| 125 } | 123 } |
| 126 | 124 |
| 127 /** | 125 /** |
| 128 * Returns a future that completes to the revision hash of [id]. | 126 * Returns a future that completes to the revision hash of [id]. |
| 129 */ | 127 */ |
| 130 Future<String> _revisionAt(PackageId id) { | 128 Future<String> _revisionAt(PackageId id) { |
| 131 return runGit(["rev-parse", _getEffectiveRef(id)], | 129 return git.run(["rev-parse", _getEffectiveRef(id)], |
| 132 workingDir: _repoCachePath(id)).transform((result) { | 130 workingDir: _repoCachePath(id)).transform((result) => result[0]); |
| 133 if (!result.success) throw 'Git failed.'; | |
| 134 return result.stdout[0]; | |
| 135 }); | |
| 136 } | 131 } |
| 137 | 132 |
| 138 /** | 133 /** |
| 139 * Returns the path to the revision-specific cache of [id]. | 134 * Returns the path to the revision-specific cache of [id]. |
| 140 */ | 135 */ |
| 141 Future<String> _revisionCachePath(PackageId id) { | 136 Future<String> _revisionCachePath(PackageId id) { |
| 142 return _revisionAt(id).transform((rev) { | 137 return _revisionAt(id).transform((rev) { |
| 143 var revisionCacheName = '${id.name}-$rev'; | 138 var revisionCacheName = '${id.name}-$rev'; |
| 144 return join(systemCacheRoot, revisionCacheName); | 139 return join(systemCacheRoot, revisionCacheName); |
| 145 }); | 140 }); |
| 146 } | 141 } |
| 147 | 142 |
| 148 /** | 143 /** |
| 149 * Clones the repo at the URI [from] to the path [to] on the local filesystem. | 144 * Clones the repo at the URI [from] to the path [to] on the local filesystem. |
| 150 * | 145 * |
| 151 * If [mirror] is true, create a bare, mirrored clone. This doesn't check out | 146 * If [mirror] is true, create a bare, mirrored clone. This doesn't check out |
| 152 * the working tree, but instead makes the repository a local mirror of the | 147 * the working tree, but instead makes the repository a local mirror of the |
| 153 * remote repository. See the manpage for `git clone` for more information. | 148 * remote repository. See the manpage for `git clone` for more information. |
| 154 */ | 149 */ |
| 155 Future _clone(String from, String to, [bool mirror=false]) { | 150 Future _clone(String from, String to, [bool mirror=false]) { |
| 156 // Git on Windows does not seem to automatically create the destination | 151 // Git on Windows does not seem to automatically create the destination |
| 157 // directory. | 152 // directory. |
| 158 return ensureDir(to).chain((_) { | 153 return ensureDir(to).chain((_) { |
| 159 var args = ["clone", from, to]; | 154 var args = ["clone", from, to]; |
| 160 if (mirror) args.insertRange(1, 1, "--mirror"); | 155 if (mirror) args.insertRange(1, 1, "--mirror"); |
| 161 return runGit(args); | 156 return git.run(args); |
| 162 }).transform((result) { | 157 }).transform((result) => null); |
| 163 if (!result.success) throw 'Git failed.'; | |
| 164 return null; | |
| 165 }); | |
| 166 } | 158 } |
| 167 | 159 |
| 168 /** | 160 /** |
| 169 * Checks out the reference [ref] in [repoPath]. | 161 * Checks out the reference [ref] in [repoPath]. |
| 170 */ | 162 */ |
| 171 Future _checkOut(String repoPath, String ref) { | 163 Future _checkOut(String repoPath, String ref) { |
| 172 return runGit(["checkout", ref], workingDir: repoPath).transform((result) { | 164 return git.run(["checkout", ref], workingDir: repoPath).transform( |
| 173 if (!result.success) throw 'Git failed.'; | 165 (result) => null); |
| 174 return null; | |
| 175 }); | |
| 176 } | 166 } |
| 177 | 167 |
| 178 /** | 168 /** |
| 179 * Returns the path to the canonical clone of the repository referred to by | 169 * Returns the path to the canonical clone of the repository referred to by |
| 180 * [id] (the one in `<system cache>/git/cache`). | 170 * [id] (the one in `<system cache>/git/cache`). |
| 181 */ | 171 */ |
| 182 String _repoCachePath(PackageId id) { | 172 String _repoCachePath(PackageId id) { |
| 183 var repoCacheName = '${id.name}-${sha1(_getUrl(id))}'; | 173 var repoCacheName = '${id.name}-${sha1(_getUrl(id))}'; |
| 184 return join(systemCacheRoot, 'cache', repoCacheName); | 174 return join(systemCacheRoot, 'cache', repoCacheName); |
| 185 } | 175 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 | 217 |
| 228 /** | 218 /** |
| 229 * Returns [description] if it's a description, or [PackageId.description] if | 219 * Returns [description] if it's a description, or [PackageId.description] if |
| 230 * it's a [PackageId]. | 220 * it's a [PackageId]. |
| 231 */ | 221 */ |
| 232 _getDescription(description) { | 222 _getDescription(description) { |
| 233 if (description is PackageId) return description.description; | 223 if (description is PackageId) return description.description; |
| 234 return description; | 224 return description; |
| 235 } | 225 } |
| 236 } | 226 } |
| OLD | NEW |