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

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

Issue 12253054: Get rid of join() and encapsulate File and Directory in io.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 years, 10 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 | « utils/pub/entrypoint.dart ('k') | utils/pub/hosted_source.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 'dart:async'; 7 import 'dart:async';
8
9 import '../../pkg/path/lib/path.dart' as path;
10
8 import 'git.dart' as git; 11 import 'git.dart' as git;
9 import 'io.dart'; 12 import 'io.dart';
10 import 'package.dart'; 13 import 'package.dart';
11 import 'source.dart'; 14 import 'source.dart';
12 import 'source_registry.dart'; 15 import 'source_registry.dart';
13 import 'utils.dart'; 16 import 'utils.dart';
14 17
15 /// A package source that installs packages from Git repos. 18 /// A package source that installs packages from Git repos.
16 class GitSource extends Source { 19 class GitSource extends Source {
17 final String name = "git"; 20 final String name = "git";
(...skipping 17 matching lines...) Expand all
35 Future<Package> installToSystemCache(PackageId id) { 38 Future<Package> installToSystemCache(PackageId id) {
36 var revisionCachePath; 39 var revisionCachePath;
37 40
38 return git.isInstalled.then((installed) { 41 return git.isInstalled.then((installed) {
39 if (!installed) { 42 if (!installed) {
40 throw new Exception( 43 throw new Exception(
41 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n" 44 "Cannot install '${id.name}' from Git (${_getUrl(id)}).\n"
42 "Please ensure Git is correctly installed."); 45 "Please ensure Git is correctly installed.");
43 } 46 }
44 47
45 ensureDir(join(systemCacheRoot, 'cache')); 48 ensureDir(path.join(systemCacheRoot, 'cache'));
46 return _ensureRepoCache(id); 49 return _ensureRepoCache(id);
47 }).then((_) => systemCacheDirectory(id)).then((path) { 50 }).then((_) => systemCacheDirectory(id)).then((path) {
48 revisionCachePath = path; 51 revisionCachePath = path;
49 if (entryExists(revisionCachePath)) return; 52 if (entryExists(revisionCachePath)) return;
50 return _clone(_repoCachePath(id), revisionCachePath, mirror: false); 53 return _clone(_repoCachePath(id), revisionCachePath, mirror: false);
51 }).then((_) { 54 }).then((_) {
52 var ref = _getEffectiveRef(id); 55 var ref = _getEffectiveRef(id);
53 if (ref == 'HEAD') return; 56 if (ref == 'HEAD') return;
54 return _checkOut(revisionCachePath, ref); 57 return _checkOut(revisionCachePath, ref);
55 }).then((_) { 58 }).then((_) {
56 return new Package.load(id.name, revisionCachePath, systemCache.sources); 59 return new Package.load(id.name, revisionCachePath, systemCache.sources);
57 }); 60 });
58 } 61 }
59 62
60 /// Returns the path to the revision-specific cache of [id]. 63 /// Returns the path to the revision-specific cache of [id].
61 Future<String> systemCacheDirectory(PackageId id) { 64 Future<String> systemCacheDirectory(PackageId id) {
62 return _revisionAt(id).then((rev) { 65 return _revisionAt(id).then((rev) {
63 var revisionCacheName = '${id.name}-$rev'; 66 var revisionCacheName = '${id.name}-$rev';
64 return join(systemCacheRoot, revisionCacheName); 67 return path.join(systemCacheRoot, revisionCacheName);
65 }); 68 });
66 } 69 }
67 /// Ensures [description] is a Git URL. 70 /// Ensures [description] is a Git URL.
68 void validateDescription(description, {bool fromLockFile: false}) { 71 void validateDescription(description, {bool fromLockFile: false}) {
69 // A single string is assumed to be a Git URL. 72 // A single string is assumed to be a Git URL.
70 if (description is String) return; 73 if (description is String) return;
71 if (description is! Map || !description.containsKey('url')) { 74 if (description is! Map || !description.containsKey('url')) {
72 throw new FormatException("The description must be a Git URL or a map " 75 throw new FormatException("The description must be a Git URL or a map "
73 "with a 'url' key."); 76 "with a 'url' key.");
74 } 77 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 /// Checks out the reference [ref] in [repoPath]. 144 /// Checks out the reference [ref] in [repoPath].
142 Future _checkOut(String repoPath, String ref) { 145 Future _checkOut(String repoPath, String ref) {
143 return git.run(["checkout", ref], workingDir: repoPath).then( 146 return git.run(["checkout", ref], workingDir: repoPath).then(
144 (result) => null); 147 (result) => null);
145 } 148 }
146 149
147 /// Returns the path to the canonical clone of the repository referred to by 150 /// Returns the path to the canonical clone of the repository referred to by
148 /// [id] (the one in `<system cache>/git/cache`). 151 /// [id] (the one in `<system cache>/git/cache`).
149 String _repoCachePath(PackageId id) { 152 String _repoCachePath(PackageId id) {
150 var repoCacheName = '${id.name}-${sha1(_getUrl(id))}'; 153 var repoCacheName = '${id.name}-${sha1(_getUrl(id))}';
151 return join(systemCacheRoot, 'cache', repoCacheName); 154 return path.join(systemCacheRoot, 'cache', repoCacheName);
152 } 155 }
153 156
154 /// Returns the repository URL for [id]. 157 /// Returns the repository URL for [id].
155 /// 158 ///
156 /// [description] may be a description or a [PackageId]. 159 /// [description] may be a description or a [PackageId].
157 String _getUrl(description) { 160 String _getUrl(description) {
158 description = _getDescription(description); 161 description = _getDescription(description);
159 if (description is String) return description; 162 if (description is String) return description;
160 return description['url']; 163 return description['url'];
161 } 164 }
(...skipping 25 matching lines...) Expand all
187 return description['ref']; 190 return description['ref'];
188 } 191 }
189 192
190 /// Returns [description] if it's a description, or [PackageId.description] if 193 /// Returns [description] if it's a description, or [PackageId.description] if
191 /// it's a [PackageId]. 194 /// it's a [PackageId].
192 _getDescription(description) { 195 _getDescription(description) {
193 if (description is PackageId) return description.description; 196 if (description is PackageId) return description.description;
194 return description; 197 return description;
195 } 198 }
196 } 199 }
OLDNEW
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/hosted_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698