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

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

Issue 10905202: Look for git.cmd on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 8 years, 3 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
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 * Ensure that the canonical clone of the repository referred to by [id] (the 117 * Ensure that the canonical clone of the repository referred to by [id] (the
118 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a 118 * one in `<system cache>/git/cache`) exists and is up-to-date. Returns a
119 * future that completes once this is finished and throws an exception if it 119 * future that completes once this is finished and throws an exception if it
120 * fails. 120 * fails.
121 */ 121 */
122 Future _ensureRepoCache(PackageId id) { 122 Future _ensureRepoCache(PackageId id) {
123 var path = _repoCachePath(id); 123 var path = _repoCachePath(id);
124 return exists(path).chain((exists) { 124 return exists(path).chain((exists) {
125 if (!exists) return _clone(_getUrl(id), path, mirror: true); 125 if (!exists) return _clone(_getUrl(id), path, mirror: true);
126 126
127 return runProcess("git", ["fetch"], workingDir: path) 127 return runGit(["fetch"], workingDir: path).transform((result) {
128 .transform((result) {
129 if (!result.success) throw 'Git failed.'; 128 if (!result.success) throw 'Git failed.';
130 return null; 129 return null;
131 }); 130 });
132 }); 131 });
133 } 132 }
134 133
135 /** 134 /**
136 * Returns a future that completes to the revision hash of [id]. 135 * Returns a future that completes to the revision hash of [id].
137 */ 136 */
138 Future<String> _revisionAt(PackageId id) { 137 Future<String> _revisionAt(PackageId id) {
139 return runProcess("git", ["rev-parse", _getEffectiveRef(id)], 138 return runGit(["rev-parse", _getEffectiveRef(id)],
140 workingDir: _repoCachePath(id)).transform((result) { 139 workingDir: _repoCachePath(id)).transform((result) {
141 if (!result.success) throw 'Git failed.'; 140 if (!result.success) throw 'Git failed.';
142 return result.stdout[0]; 141 return result.stdout[0];
143 }); 142 });
144 } 143 }
145 144
146 /** 145 /**
147 * Returns the path to the revision-specific cache of [id]. 146 * Returns the path to the revision-specific cache of [id].
148 */ 147 */
149 Future<String> _revisionCachePath(PackageId id) { 148 Future<String> _revisionCachePath(PackageId id) {
150 return _revisionAt(id).transform((rev) { 149 return _revisionAt(id).transform((rev) {
151 var revisionCacheName = '${id.name}-$rev'; 150 var revisionCacheName = '${id.name}-$rev';
152 return join(systemCacheRoot, revisionCacheName); 151 return join(systemCacheRoot, revisionCacheName);
153 }); 152 });
154 } 153 }
155 154
156 /** 155 /**
157 * Clones the repo at the URI [from] to the path [to] on the local filesystem. 156 * Clones the repo at the URI [from] to the path [to] on the local filesystem.
158 * 157 *
159 * If [mirror] is true, create a bare, mirrored clone. This doesn't check out 158 * If [mirror] is true, create a bare, mirrored clone. This doesn't check out
160 * the working tree, but instead makes the repository a local mirror of the 159 * the working tree, but instead makes the repository a local mirror of the
161 * remote repository. See the manpage for `git clone` for more information. 160 * remote repository. See the manpage for `git clone` for more information.
162 */ 161 */
163 Future _clone(String from, String to, [bool mirror=false]) { 162 Future _clone(String from, String to, [bool mirror=false]) {
164 var args = ["clone", from, to]; 163 var args = ["clone", from, to];
165 if (mirror) args.insertRange(1, 1, "--mirror"); 164 if (mirror) args.insertRange(1, 1, "--mirror");
166 return runProcess("git", args).transform((result) { 165 return runGit(args).transform((result) {
167 if (!result.success) throw 'Git failed.'; 166 if (!result.success) throw 'Git failed.';
168 return null; 167 return null;
169 }); 168 });
170 } 169 }
171 170
172 /** 171 /**
173 * Checks out the reference [ref] in [repoPath]. 172 * Checks out the reference [ref] in [repoPath].
174 */ 173 */
175 Future _checkOut(String repoPath, String ref) { 174 Future _checkOut(String repoPath, String ref) {
176 return runProcess("git", ["checkout", ref], workingDir: repoPath) 175 return runGit(["checkout", ref], workingDir: repoPath).transform((result) {
177 .transform((result) {
178 if (!result.success) throw 'Git failed.'; 176 if (!result.success) throw 'Git failed.';
179 return null; 177 return null;
180 }); 178 });
181 } 179 }
182 180
183 /** 181 /**
184 * Returns the path to the canonical clone of the repository referred to by 182 * Returns the path to the canonical clone of the repository referred to by
185 * [id] (the one in `<system cache>/git/cache`). 183 * [id] (the one in `<system cache>/git/cache`).
186 */ 184 */
187 String _repoCachePath(PackageId id) { 185 String _repoCachePath(PackageId id) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 230
233 /** 231 /**
234 * Returns [description] if it's a description, or [PackageId.description] if 232 * Returns [description] if it's a description, or [PackageId.description] if
235 * it's a [PackageId]. 233 * it's a [PackageId].
236 */ 234 */
237 _getDescription(description) { 235 _getDescription(description) {
238 if (description is PackageId) return description.description; 236 if (description is PackageId) return description.description;
239 return description; 237 return description;
240 } 238 }
241 } 239 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698