| 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 'package:pathos/path.dart' as path; | 9 import 'package:pathos/path.dart' as path; |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 }); | 116 }); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // TODO(keertip): Implement getCachedPackages(). | 119 // TODO(keertip): Implement getCachedPackages(). |
| 120 | 120 |
| 121 /// Ensure that the canonical clone of the repository referred to by [id] (the | 121 /// Ensure that the canonical clone of the repository referred to by [id] (the |
| 122 /// one in `<system cache>/git/cache`) exists and is up-to-date. Returns a | 122 /// one in `<system cache>/git/cache`) exists and is up-to-date. Returns a |
| 123 /// future that completes once this is finished and throws an exception if it | 123 /// future that completes once this is finished and throws an exception if it |
| 124 /// fails. | 124 /// fails. |
| 125 Future _ensureRepoCache(PackageId id) { | 125 Future _ensureRepoCache(PackageId id) { |
| 126 return new Future.of(() { | 126 return new Future.sync(() { |
| 127 var path = _repoCachePath(id); | 127 var path = _repoCachePath(id); |
| 128 if (!entryExists(path)) return _clone(_getUrl(id), path, mirror: true); | 128 if (!entryExists(path)) return _clone(_getUrl(id), path, mirror: true); |
| 129 return git.run(["fetch"], workingDir: path).then((result) => null); | 129 return git.run(["fetch"], workingDir: path).then((result) => null); |
| 130 }); | 130 }); |
| 131 } | 131 } |
| 132 | 132 |
| 133 /// Returns a future that completes to the revision hash of [id]. | 133 /// Returns a future that completes to the revision hash of [id]. |
| 134 Future<String> _revisionAt(PackageId id) { | 134 Future<String> _revisionAt(PackageId id) { |
| 135 return git.run(["rev-parse", _getEffectiveRef(id)], | 135 return git.run(["rev-parse", _getEffectiveRef(id)], |
| 136 workingDir: _repoCachePath(id)).then((result) => result[0]); | 136 workingDir: _repoCachePath(id)).then((result) => result[0]); |
| 137 } | 137 } |
| 138 | 138 |
| 139 /// Clones the repo at the URI [from] to the path [to] on the local | 139 /// Clones the repo at the URI [from] to the path [to] on the local |
| 140 /// filesystem. | 140 /// filesystem. |
| 141 /// | 141 /// |
| 142 /// If [mirror] is true, create a bare, mirrored clone. This doesn't check out | 142 /// If [mirror] is true, create a bare, mirrored clone. This doesn't check out |
| 143 /// the working tree, but instead makes the repository a local mirror of the | 143 /// the working tree, but instead makes the repository a local mirror of the |
| 144 /// remote repository. See the manpage for `git clone` for more information. | 144 /// remote repository. See the manpage for `git clone` for more information. |
| 145 Future _clone(String from, String to, {bool mirror: false}) { | 145 Future _clone(String from, String to, {bool mirror: false}) { |
| 146 return new Future.of(() { | 146 return new Future.sync(() { |
| 147 // Git on Windows does not seem to automatically create the destination | 147 // Git on Windows does not seem to automatically create the destination |
| 148 // directory. | 148 // directory. |
| 149 ensureDir(to); | 149 ensureDir(to); |
| 150 var args = ["clone", from, to]; | 150 var args = ["clone", from, to]; |
| 151 if (mirror) args.insert(1, "--mirror"); | 151 if (mirror) args.insert(1, "--mirror"); |
| 152 return git.run(args); | 152 return git.run(args); |
| 153 }).then((result) => null); | 153 }).then((result) => null); |
| 154 } | 154 } |
| 155 | 155 |
| 156 /// Checks out the reference [ref] in [repoPath]. | 156 /// Checks out the reference [ref] in [repoPath]. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return description['ref']; | 202 return description['ref']; |
| 203 } | 203 } |
| 204 | 204 |
| 205 /// Returns [description] if it's a description, or [PackageId.description] if | 205 /// Returns [description] if it's a description, or [PackageId.description] if |
| 206 /// it's a [PackageId]. | 206 /// it's a [PackageId]. |
| 207 _getDescription(description) { | 207 _getDescription(description) { |
| 208 if (description is PackageId) return description.description; | 208 if (description is PackageId) return description.description; |
| 209 return description; | 209 return description; |
| 210 } | 210 } |
| 211 } | 211 } |
| OLD | NEW |