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

Side by Side Diff: lib/src/source/git.dart

Issue 1239623005: "pub cache repair" prints a more detailed summary. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « lib/src/source/cached.dart ('k') | lib/src/source/hosted.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 pub.source.git; 5 library pub.source.git;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 157
158 List<Package> getCachedPackages() { 158 List<Package> getCachedPackages() {
159 // TODO(keertip): Implement getCachedPackages(). 159 // TODO(keertip): Implement getCachedPackages().
160 throw new UnimplementedError( 160 throw new UnimplementedError(
161 "The git source doesn't support listing its cached packages yet."); 161 "The git source doesn't support listing its cached packages yet.");
162 } 162 }
163 163
164 /// Resets all cached packages back to the pristine state of the Git 164 /// Resets all cached packages back to the pristine state of the Git
165 /// repository at the revision they are pinned to. 165 /// repository at the revision they are pinned to.
166 Future<Pair<int, int>> repairCachedPackages() async { 166 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages() async {
167 if (!dirExists(systemCacheRoot)) return new Pair(0, 0); 167 if (!dirExists(systemCacheRoot)) return new Pair([], []);
168 168
169 var successes = 0; 169 var successes = [];
170 var failures = 0; 170 var failures = [];
171 171
172 var packages = listDir(systemCacheRoot) 172 var packages = listDir(systemCacheRoot)
173 .where((entry) => dirExists(path.join(entry, ".git"))) 173 .where((entry) => dirExists(path.join(entry, ".git")))
174 .map((packageDir) => new Package.load(null, packageDir, 174 .map((packageDir) => new Package.load(null, packageDir,
175 systemCache.sources)) 175 systemCache.sources))
176 .toList(); 176 .toList();
177 177
178 // Note that there may be multiple packages with the same name and version 178 // Note that there may be multiple packages with the same name and version
179 // (pinned to different commits). The sort order of those is unspecified. 179 // (pinned to different commits). The sort order of those is unspecified.
180 packages.sort(Package.orderByNameAndVersion); 180 packages.sort(Package.orderByNameAndVersion);
181 181
182 for (var package in packages) { 182 for (var package in packages) {
183 var id = new PackageId(package.name, this.name, package.version, null);
184
183 log.message("Resetting Git repository for " 185 log.message("Resetting Git repository for "
184 "${log.bold(package.name)} ${package.version}..."); 186 "${log.bold(package.name)} ${package.version}...");
185 187
186 try { 188 try {
187 // Remove all untracked files. 189 // Remove all untracked files.
188 await git.run(["clean", "-d", "--force", "-x"], 190 await git.run(["clean", "-d", "--force", "-x"],
189 workingDir: package.dir); 191 workingDir: package.dir);
190 192
191 // Discard all changes to tracked files. 193 // Discard all changes to tracked files.
192 await git.run(["reset", "--hard", "HEAD"], workingDir: package.dir); 194 await git.run(["reset", "--hard", "HEAD"], workingDir: package.dir);
193 195
194 successes++; 196 successes.add(id);
195 } on git.GitException catch (error, stackTrace) { 197 } on git.GitException catch (error, stackTrace) {
196 log.error("Failed to reset ${log.bold(package.name)} " 198 log.error("Failed to reset ${log.bold(package.name)} "
197 "${package.version}. Error:\n$error"); 199 "${package.version}. Error:\n$error");
198 log.fine(stackTrace); 200 log.fine(stackTrace);
199 failures++; 201 failures.add(id);
200 202
201 tryDeleteEntry(package.dir); 203 tryDeleteEntry(package.dir);
202 } 204 }
203 } 205 }
204 206
205 return new Pair(successes, failures); 207 return new Pair(successes, failures);
206 } 208 }
207 209
208 /// Ensure that the canonical clone of the repository referred to by [id] (the 210 /// Ensure that the canonical clone of the repository referred to by [id] (the
209 /// one in `<system cache>/git/cache`) exists and contains the revision 211 /// one in `<system cache>/git/cache`) exists and contains the revision
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return description['ref']; 333 return description['ref'];
332 } 334 }
333 335
334 /// Returns [description] if it's a description, or [PackageId.description] if 336 /// Returns [description] if it's a description, or [PackageId.description] if
335 /// it's a [PackageId]. 337 /// it's a [PackageId].
336 _getDescription(description) { 338 _getDescription(description) {
337 if (description is PackageId) return description.description; 339 if (description is PackageId) return description.description;
338 return description; 340 return description;
339 } 341 }
340 } 342 }
OLDNEW
« no previous file with comments | « lib/src/source/cached.dart ('k') | lib/src/source/hosted.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698