OLD | NEW |
---|---|
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.package; | 5 library pub.package; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 | 101 |
102 return p.join(dir, readmes.reduce((readme1, readme2) { | 102 return p.join(dir, readmes.reduce((readme1, readme2) { |
103 var extensions1 = ".".allMatches(readme1).length; | 103 var extensions1 = ".".allMatches(readme1).length; |
104 var extensions2 = ".".allMatches(readme2).length; | 104 var extensions2 = ".".allMatches(readme2).length; |
105 var comparison = extensions1.compareTo(extensions2); | 105 var comparison = extensions1.compareTo(extensions2); |
106 if (comparison == 0) comparison = readme1.compareTo(readme2); | 106 if (comparison == 0) comparison = readme1.compareTo(readme2); |
107 return (comparison <= 0) ? readme1 : readme2; | 107 return (comparison <= 0) ? readme1 : readme2; |
108 })); | 108 })); |
109 } | 109 } |
110 | 110 |
111 /// Returns whether or not this package is in a Git repo. | |
112 bool get _usesGit { | |
Bob Nystrom
2015/07/10 00:34:34
"uses" is kind of weird. How about "_inGitRepo"?
nweiz
2015/07/10 21:44:10
Done.
| |
113 if (_usesGitCache != null) return _usesGitCache; | |
114 | |
115 if (dir == null || !git.isInstalled) { | |
116 _usesGitCache = false; | |
117 } else { | |
118 try { | |
119 git.runSync(['rev-parse'], workingDir: dir); | |
120 _usesGitCache = true; | |
121 } on git.GitException catch (_) { | |
122 _usesGitCache = false; | |
123 } | |
124 } | |
125 | |
126 return _usesGitCache; | |
127 } | |
128 bool _usesGitCache; | |
129 | |
111 /// Loads the package whose root directory is [packageDir]. | 130 /// Loads the package whose root directory is [packageDir]. |
112 /// | 131 /// |
113 /// [name] is the expected name of that package (e.g. the name given in the | 132 /// [name] is the expected name of that package (e.g. the name given in the |
114 /// dependency), or `null` if the package being loaded is the entrypoint | 133 /// dependency), or `null` if the package being loaded is the entrypoint |
115 /// package. | 134 /// package. |
116 Package.load(String name, String packageDir, SourceRegistry sources) | 135 Package.load(String name, String packageDir, SourceRegistry sources) |
117 : dir = packageDir, | 136 : dir = packageDir, |
118 pubspec = new Pubspec.load(packageDir, sources, expectedName: name); | 137 pubspec = new Pubspec.load(packageDir, sources, expectedName: name); |
119 | 138 |
120 /// Constructs a package with the given pubspec. | 139 /// Constructs a package with the given pubspec. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 } | 219 } |
201 | 220 |
202 if (!dirExists(beneath)) return []; | 221 if (!dirExists(beneath)) return []; |
203 | 222 |
204 // This is used in some performance-sensitive paths and can list many, many | 223 // This is used in some performance-sensitive paths and can list many, many |
205 // files. As such, it leans more havily towards optimization as opposed to | 224 // files. As such, it leans more havily towards optimization as opposed to |
206 // readability than most code in pub. In particular, it avoids using the | 225 // readability than most code in pub. In particular, it avoids using the |
207 // path package, since re-parsing a path is very expensive relative to | 226 // path package, since re-parsing a path is very expensive relative to |
208 // string operations. | 227 // string operations. |
209 var files; | 228 var files; |
210 if (useGitIgnore && git.isInstalled && dirExists(path('.git'))) { | 229 if (useGitIgnore && git.isInstalled && _usesGit) { |
Bob Nystrom
2015/07/10 00:34:34
You can remove the git.isInstalled check here now.
nweiz
2015/07/10 21:44:10
Done.
| |
211 // Later versions of git do not allow a path for ls-files that appears to | 230 // Later versions of git do not allow a path for ls-files that appears to |
212 // be outside of the repo, so make sure we give it a relative path. | 231 // be outside of the repo, so make sure we give it a relative path. |
213 var relativeBeneath = p.relative(beneath, from: dir); | 232 var relativeBeneath = p.relative(beneath, from: dir); |
214 | 233 |
215 // List all files that aren't gitignored, including those not checked in | 234 // List all files that aren't gitignored, including those not checked in |
216 // to Git. | 235 // to Git. |
217 files = git.runSync( | 236 files = git.runSync( |
218 ["ls-files", "--cached", "--others", "--exclude-standard", | 237 ["ls-files", "--cached", "--others", "--exclude-standard", |
219 relativeBeneath], | 238 relativeBeneath], |
220 workingDir: dir); | 239 workingDir: dir); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 | 435 |
417 bool operator ==(other) { | 436 bool operator ==(other) { |
418 // TODO(rnystrom): We're assuming here that we don't need to delve into the | 437 // TODO(rnystrom): We're assuming here that we don't need to delve into the |
419 // description. | 438 // description. |
420 return other is PackageDep && | 439 return other is PackageDep && |
421 other.name == name && | 440 other.name == name && |
422 other.source == source && | 441 other.source == source && |
423 other.constraint == constraint; | 442 other.constraint == constraint; |
424 } | 443 } |
425 } | 444 } |
OLD | NEW |