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

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

Issue 10913077: Use a bare git repository for the repo cache. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/tests/pub/pub_install_git_test.dart » ('j') | no next file with comments »
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 return ensureDir(join(systemCacheRoot, 'cache')); 47 return ensureDir(join(systemCacheRoot, 'cache'));
48 }).chain((_) => _ensureRepoCache(id)) 48 }).chain((_) => _ensureRepoCache(id))
49 .chain((_) => _revisionCachePath(id)) 49 .chain((_) => _revisionCachePath(id))
50 .chain((path) { 50 .chain((path) {
51 revisionCachePath = path; 51 revisionCachePath = path;
52 return exists(revisionCachePath); 52 return exists(revisionCachePath);
53 }).chain((exists) { 53 }).chain((exists) {
54 if (exists) return new Future.immediate(null); 54 if (exists) return new Future.immediate(null);
55 return _clone(_repoCachePath(id), revisionCachePath); 55 return _clone(_repoCachePath(id), revisionCachePath, mirror: false);
56 }).chain((_) { 56 }).chain((_) {
57 var ref = _getEffectiveRef(id); 57 var ref = _getEffectiveRef(id);
58 if (ref == 'HEAD') return new Future.immediate(null); 58 if (ref == 'HEAD') return new Future.immediate(null);
59 return _checkOut(revisionCachePath, ref); 59 return _checkOut(revisionCachePath, ref);
60 }).chain((_) => Package.load(revisionCachePath, systemCache.sources)); 60 }).chain((_) => Package.load(revisionCachePath, systemCache.sources));
61 } 61 }
62 62
63 /** 63 /**
64 * The package name of a Git repo is the name of the directory into which 64 * The package name of a Git repo is the name of the directory into which
65 * it'll be cloned. 65 * it'll be cloned.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 /** 116 /**
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); 125 if (!exists) return _clone(_getUrl(id), path, mirror: true);
126 126
127 return runProcess("git", ["pull", "--force"], workingDir: path) 127 return runProcess("git", ["fetch"], workingDir: path)
128 .transform((result) { 128 .transform((result) {
129 print(result.stdout);
130 print(result.stderr);
Bob Nystrom 2012/09/05 00:56:04 Remove these.
nweiz 2012/09/05 21:10:42 Done.
129 if (!result.success) throw 'Git failed.'; 131 if (!result.success) throw 'Git failed.';
130 return null; 132 return null;
131 }); 133 });
132 }); 134 });
133 } 135 }
134 136
135 /** 137 /**
136 * Returns a future that completes to the revision hash of [id]. 138 * Returns a future that completes to the revision hash of [id].
137 */ 139 */
138 Future<String> _revisionAt(PackageId id) { 140 Future<String> _revisionAt(PackageId id) {
139 return runProcess("git", ["rev-parse", _getEffectiveRef(id)], 141 return runProcess("git", ["rev-parse", _getEffectiveRef(id)],
140 workingDir: _repoCachePath(id)).transform((result) { 142 workingDir: _repoCachePath(id)).transform((result) {
141 if (!result.success) throw 'Git failed.'; 143 if (!result.success) throw 'Git failed.';
142 return result.stdout[0]; 144 return result.stdout[0];
143 }); 145 });
144 } 146 }
145 147
146 /** 148 /**
147 * Returns the path to the revision-specific cache of [id]. 149 * Returns the path to the revision-specific cache of [id].
148 */ 150 */
149 Future<String> _revisionCachePath(PackageId id) { 151 Future<String> _revisionCachePath(PackageId id) {
150 return _revisionAt(id).transform((rev) { 152 return _revisionAt(id).transform((rev) {
151 var revisionCacheName = '${id.name}-$rev'; 153 var revisionCacheName = '${id.name}-$rev';
152 return join(systemCacheRoot, revisionCacheName); 154 return join(systemCacheRoot, revisionCacheName);
153 }); 155 });
154 } 156 }
155 157
156 /** 158 /**
157 * Clones the repo at the URI [from] to the path [to] on the local filesystem. 159 * Clones the repo at the URI [from] to the path [to] on the local filesystem.
Bob Nystrom 2012/09/05 00:56:04 Can you explain what "mirror" is for here?
nweiz 2012/09/05 21:10:42 Done.
158 */ 160 */
159 Future _clone(String from, String to) { 161 Future _clone(String from, String to, [bool mirror=false]) {
160 return runProcess("git", ["clone", from, to]).transform((result) { 162 var args = ["clone", from, to];
163 if (mirror) args.insertRange(1, 1, "--mirror");
164 return runProcess("git", args).transform((result) {
161 if (!result.success) throw 'Git failed.'; 165 if (!result.success) throw 'Git failed.';
162 return null; 166 return null;
163 }); 167 });
164 } 168 }
165 169
166 /** 170 /**
167 * Checks out the reference [ref] in [repoPath]. 171 * Checks out the reference [ref] in [repoPath].
168 */ 172 */
169 Future _checkOut(String repoPath, String ref) { 173 Future _checkOut(String repoPath, String ref) {
170 return runProcess("git", ["checkout", ref], workingDir: repoPath) 174 return runProcess("git", ["checkout", ref], workingDir: repoPath)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 230
227 /** 231 /**
228 * Returns [description] if it's a description, or [PackageId.description] if 232 * Returns [description] if it's a description, or [PackageId.description] if
229 * it's a [PackageId]. 233 * it's a [PackageId].
230 */ 234 */
231 _getDescription(description) { 235 _getDescription(description) {
232 if (description is PackageId) return description.description; 236 if (description is PackageId) return description.description;
233 return description; 237 return description;
234 } 238 }
235 } 239 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub_install_git_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698