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

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

Issue 1555133002: Don't choke on SSH Git URLs. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | 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 import 'package:pub_semver/pub_semver.dart'; 10 import 'package:pub_semver/pub_semver.dart';
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (description is! Map) { 128 if (description is! Map) {
129 throw new FormatException("The description must be a Git URL or a map " 129 throw new FormatException("The description must be a Git URL or a map "
130 "with a 'url' key."); 130 "with a 'url' key.");
131 } 131 }
132 132
133 if (description["url"] is! String) { 133 if (description["url"] is! String) {
134 throw new FormatException("The 'url' field of the description must be a " 134 throw new FormatException("The 'url' field of the description must be a "
135 "string."); 135 "string.");
136 } 136 }
137 137
138 // Ensure that it's a valid URL. 138 _validateUrl(description["url"]);
139 Uri.parse(description["url"]);
140 139
141 var ref = description["ref"]; 140 var ref = description["ref"];
142 if (ref != null && ref is! String) { 141 if (ref != null && ref is! String) {
143 throw new FormatException("The 'ref' field of the description must be a " 142 throw new FormatException("The 'ref' field of the description must be a "
144 "string."); 143 "string.");
145 } 144 }
146 145
147 return new PackageRef(name, this.name, { 146 return new PackageRef(name, this.name, {
148 "url": description["url"], 147 "url": description["url"],
149 "ref": description["ref"] ?? "HEAD" 148 "ref": description["ref"] ?? "HEAD"
150 }); 149 });
151 } 150 }
152 151
153 PackageId parseId(String name, Version version, description) { 152 PackageId parseId(String name, Version version, description) {
154 if (description is! Map) { 153 if (description is! Map) {
155 throw new FormatException("The description must be a map with a 'url' " 154 throw new FormatException("The description must be a map with a 'url' "
156 "key."); 155 "key.");
157 } 156 }
158 157
159 if (description["url"] is! String) { 158 if (description["url"] is! String) {
160 throw new FormatException("The 'url' field of the description must be a " 159 throw new FormatException("The 'url' field of the description must be a "
161 "string."); 160 "string.");
162 } 161 }
163 162
164 // Ensure that it's a valid URL. 163 _validateUrl(description["url"]);
165 Uri.parse(description["url"]);
166 164
167 var ref = description["ref"]; 165 var ref = description["ref"];
168 if (ref != null && ref is! String) { 166 if (ref != null && ref is! String) {
169 throw new FormatException("The 'ref' field of the description must be a " 167 throw new FormatException("The 'ref' field of the description must be a "
170 "string."); 168 "string.");
171 } 169 }
172 170
173 if (description["resolved-ref"] is! String) { 171 if (description["resolved-ref"] is! String) {
174 throw new FormatException("The 'resolved-ref' field of the description " 172 throw new FormatException("The 'resolved-ref' field of the description "
175 "must be a string."); 173 "must be a string.");
176 } 174 }
177 175
178 return new PackageId(name, this.name, version, { 176 return new PackageId(name, this.name, version, {
179 "url": description["url"], 177 "url": description["url"],
180 "ref": description["ref"] ?? "HEAD", 178 "ref": description["ref"] ?? "HEAD",
181 "resolved-ref": description["resolved-ref"] 179 "resolved-ref": description["resolved-ref"]
182 }); 180 });
183 } 181 }
184 182
183 /// Throws a [FormatException] if [url] isn't a valid Git URL.
184 void _validateUrl(String url) {
185 // If the URL contains an @, it's probably an SSH hostname, which we don't
186 // know how to validate.
187 if (url.contains("@")) return;
188
189 // Otherwise, we use Dart's URL parser to validate the URL.
190 Uri.parse(url);
191 }
192
185 /// If [description] has a resolved ref, print it out in short-form. 193 /// If [description] has a resolved ref, print it out in short-form.
186 /// 194 ///
187 /// This helps distinguish different git commits with the same pubspec 195 /// This helps distinguish different git commits with the same pubspec
188 /// version. 196 /// version.
189 String formatDescription(String containingPath, description) { 197 String formatDescription(String containingPath, description) {
190 if (description is Map && description.containsKey('resolved-ref')) { 198 if (description is Map && description.containsKey('resolved-ref')) {
191 return "${description['url']} at " 199 return "${description['url']} at "
192 "${description['resolved-ref'].substring(0, 6)}"; 200 "${description['resolved-ref'].substring(0, 6)}";
193 } else { 201 } else {
194 return super.formatDescription(containingPath, description); 202 return super.formatDescription(containingPath, description);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 (result) => null); 364 (result) => null);
357 } 365 }
358 366
359 /// Returns the path to the canonical clone of the repository referred to by 367 /// Returns the path to the canonical clone of the repository referred to by
360 /// [id] (the one in `<system cache>/git/cache`). 368 /// [id] (the one in `<system cache>/git/cache`).
361 String _repoCachePath(PackageRef ref) { 369 String _repoCachePath(PackageRef ref) {
362 var repoCacheName = '${ref.name}-${sha1(ref.description['url'])}'; 370 var repoCacheName = '${ref.name}-${sha1(ref.description['url'])}';
363 return path.join(systemCacheRoot, 'cache', repoCacheName); 371 return path.join(systemCacheRoot, 'cache', repoCacheName);
364 } 372 }
365 } 373 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698