Chromium Code Reviews

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

Issue 2184303002: Make pub strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « lib/src/source.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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:path/path.dart' as path; 7 import 'package:path/path.dart' as path;
8 import 'package:pub_semver/pub_semver.dart'; 8 import 'package:pub_semver/pub_semver.dart';
9 9
10 import '../git.dart' as git; 10 import '../git.dart' as git;
(...skipping 138 matching lines...)
149 BoundGitSource(this.source, this.systemCache); 149 BoundGitSource(this.source, this.systemCache);
150 150
151 /// The paths to the canonical clones of repositories for which "git fetch" 151 /// The paths to the canonical clones of repositories for which "git fetch"
152 /// has already been run during this run of pub. 152 /// has already been run during this run of pub.
153 final _updatedRepos = new Set<String>(); 153 final _updatedRepos = new Set<String>();
154 154
155 /// Given a Git repo that contains a pub package, gets the name of the pub 155 /// Given a Git repo that contains a pub package, gets the name of the pub
156 /// package. 156 /// package.
157 Future<String> getPackageNameFromRepo(String repo) { 157 Future<String> getPackageNameFromRepo(String repo) {
158 // Clone the repo to a temp directory. 158 // Clone the repo to a temp directory.
159 return withTempDir((tempDir) { 159 return withTempDir((tempDir) async {
160 return _clone(repo, tempDir, shallow: true).then((_) { 160 await _clone(repo, tempDir, shallow: true);
161 var pubspec = new Pubspec.load(tempDir, systemCache.sources); 161 var pubspec = new Pubspec.load(tempDir, systemCache.sources);
162 return pubspec.name; 162 return pubspec.name;
163 });
164 }); 163 });
165 } 164 }
166 165
167 Future<List<PackageId>> doGetVersions(PackageRef ref) async { 166 Future<List<PackageId>> doGetVersions(PackageRef ref) async {
168 await _ensureRepoCache(ref); 167 await _ensureRepoCache(ref);
169 var path = _repoCachePath(ref); 168 var path = _repoCachePath(ref);
170 var revision = await _firstRevision(path, ref.description['ref']); 169 var revision = await _firstRevision(path, ref.description['ref']);
171 var pubspec = await _describeUncached(ref, revision); 170 var pubspec = await _describeUncached(ref, revision);
172 171
173 return [ 172 return [
(...skipping 68 matching lines...)
242 // TODO(keertip): Implement getCachedPackages(). 241 // TODO(keertip): Implement getCachedPackages().
243 throw new UnimplementedError( 242 throw new UnimplementedError(
244 "The git source doesn't support listing its cached packages yet."); 243 "The git source doesn't support listing its cached packages yet.");
245 } 244 }
246 245
247 /// Resets all cached packages back to the pristine state of the Git 246 /// Resets all cached packages back to the pristine state of the Git
248 /// repository at the revision they are pinned to. 247 /// repository at the revision they are pinned to.
249 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages() async { 248 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages() async {
250 if (!dirExists(systemCacheRoot)) return new Pair([], []); 249 if (!dirExists(systemCacheRoot)) return new Pair([], []);
251 250
252 var successes = []; 251 var successes = <PackageId>[];
253 var failures = []; 252 var failures = <PackageId>[];
254 253
255 var packages = listDir(systemCacheRoot) 254 var packages = listDir(systemCacheRoot)
256 .where((entry) => dirExists(path.join(entry, ".git"))) 255 .where((entry) => dirExists(path.join(entry, ".git")))
257 .map((packageDir) => new Package.load( 256 .map((packageDir) => new Package.load(
258 null, packageDir, systemCache.sources)) 257 null, packageDir, systemCache.sources))
259 .toList(); 258 .toList();
260 259
261 // Note that there may be multiple packages with the same name and version 260 // Note that there may be multiple packages with the same name and version
262 // (pinned to different commits). The sort order of those is unspecified. 261 // (pinned to different commits). The sort order of those is unspecified.
263 packages.sort(Package.orderByNameAndVersion); 262 packages.sort(Package.orderByNameAndVersion);
(...skipping 118 matching lines...)
382 (result) => null); 381 (result) => null);
383 } 382 }
384 383
385 /// Returns the path to the canonical clone of the repository referred to by 384 /// Returns the path to the canonical clone of the repository referred to by
386 /// [id] (the one in `<system cache>/git/cache`). 385 /// [id] (the one in `<system cache>/git/cache`).
387 String _repoCachePath(PackageRef ref) { 386 String _repoCachePath(PackageRef ref) {
388 var repoCacheName = '${ref.name}-${sha1(ref.description['url'])}'; 387 var repoCacheName = '${ref.name}-${sha1(ref.description['url'])}';
389 return path.join(systemCacheRoot, 'cache', repoCacheName); 388 return path.join(systemCacheRoot, 'cache', repoCacheName);
390 } 389 }
391 } 390 }
OLDNEW
« no previous file with comments | « lib/src/source.dart ('k') | lib/src/source/hosted.dart » ('j') | no next file with comments »

Powered by Google App Engine