Index: sdk/lib/_internal/pub_generated/lib/src/source/git.dart |
diff --git a/sdk/lib/_internal/pub/lib/src/source/git.dart b/sdk/lib/_internal/pub_generated/lib/src/source/git.dart |
similarity index 71% |
copy from sdk/lib/_internal/pub/lib/src/source/git.dart |
copy to sdk/lib/_internal/pub_generated/lib/src/source/git.dart |
index dc4c8b3e8a413a209474dc8b1b1431f851735885..7edaac24f42dda9026088b8112d8a8933fe8d2c4 100644 |
--- a/sdk/lib/_internal/pub/lib/src/source/git.dart |
+++ b/sdk/lib/_internal/pub_generated/lib/src/source/git.dart |
@@ -62,8 +62,9 @@ class GitSource extends CachedSource { |
var revisionCachePath; |
if (!git.isInstalled) { |
- fail("Cannot get ${id.name} from Git (${_getUrl(id)}).\n" |
- "Please ensure Git is correctly installed."); |
+ fail( |
+ "Cannot get ${id.name} from Git (${_getUrl(id)}).\n" |
+ "Please ensure Git is correctly installed."); |
} |
ensureDir(path.join(systemCacheRoot, 'cache')); |
@@ -90,7 +91,7 @@ class GitSource extends CachedSource { |
/// Ensures [description] is a Git URL. |
dynamic parseDescription(String containingPath, description, |
- {bool fromLockFile: false}) { |
+ {bool fromLockFile: false}) { |
// TODO(rnystrom): Handle git URLs that are relative file paths (#8570). |
// TODO(rnystrom): Now that this function can modify the description, it |
// may as well canonicalize it to a map so that other code in the source |
@@ -98,8 +99,8 @@ class GitSource extends CachedSource { |
// A single string is assumed to be a Git URL. |
if (description is String) return description; |
if (description is! Map || !description.containsKey('url')) { |
- throw new FormatException("The description must be a Git URL or a map " |
- "with a 'url' key."); |
+ throw new FormatException( |
+ "The description must be a Git URL or a map " "with a 'url' key."); |
} |
var parsed = new Map.from(description); |
@@ -138,8 +139,10 @@ class GitSource extends CachedSource { |
if (_getUrl(description1) != _getUrl(description2)) return false; |
if (_getRef(description1) != _getRef(description2)) return false; |
- if (description1 is Map && description1.containsKey('resolved-ref') && |
- description2 is Map && description2.containsKey('resolved-ref')) { |
+ if (description1 is Map && |
+ description1.containsKey('resolved-ref') && |
+ description2 is Map && |
+ description2.containsKey('resolved-ref')) { |
return description1['resolved-ref'] == description2['resolved-ref']; |
} |
@@ -149,7 +152,10 @@ class GitSource extends CachedSource { |
/// Attaches a specific commit to [id] to disambiguate it. |
Future<PackageId> resolveId(PackageId id) { |
return _ensureRevision(id).then((revision) { |
- var description = {'url': _getUrl(id), 'ref': _getRef(id)}; |
+ var description = { |
+ 'url': _getUrl(id), |
+ 'ref': _getRef(id) |
+ }; |
description['resolved-ref'] = revision; |
return new PackageId(id.name, name, id.version, description); |
}); |
@@ -163,46 +169,99 @@ class GitSource extends CachedSource { |
/// Resets all cached packages back to the pristine state of the Git |
/// repository at the revision they are pinned to. |
- Future<Pair<int, int>> repairCachedPackages() async { |
- if (!dirExists(systemCacheRoot)) return new Pair(0, 0); |
- |
- var successes = 0; |
- var failures = 0; |
- |
- var packages = listDir(systemCacheRoot) |
- .where((entry) => dirExists(path.join(entry, ".git"))) |
- .map((packageDir) => new Package.load(null, packageDir, |
- systemCache.sources)) |
- .toList(); |
- |
- // Note that there may be multiple packages with the same name and version |
- // (pinned to different commits). The sort order of those is unspecified. |
- packages.sort(Package.orderByNameAndVersion); |
- |
- for (var package in packages) { |
- log.message("Resetting Git repository for " |
- "${log.bold(package.name)} ${package.version}..."); |
- |
+ Future<Pair<int, int>> repairCachedPackages() { |
+ final completer0 = new Completer(); |
+ scheduleMicrotask(() { |
try { |
- // Remove all untracked files. |
- await git.run(["clean", "-d", "--force", "-x"], |
- workingDir: package.dir); |
- |
- // Discard all changes to tracked files. |
- await git.run(["reset", "--hard", "HEAD"], workingDir: package.dir); |
- |
- successes++; |
- } on git.GitException catch (error, stackTrace) { |
- log.error("Failed to reset ${log.bold(package.name)} " |
- "${package.version}. Error:\n$error"); |
- log.fine(stackTrace); |
- failures++; |
- |
- tryDeleteEntry(package.dir); |
+ join0() { |
+ var successes = 0; |
+ var failures = 0; |
+ var packages = listDir(systemCacheRoot).where(((entry) { |
+ return dirExists(path.join(entry, ".git")); |
+ })).map(((packageDir) { |
+ return new Package.load(null, packageDir, systemCache.sources); |
+ })).toList(); |
+ packages.sort(Package.orderByNameAndVersion); |
+ var it0 = packages.iterator; |
+ break0() { |
+ completer0.complete(new Pair(successes, failures)); |
+ } |
+ var trampoline0; |
+ continue0() { |
+ trampoline0 = null; |
+ if (it0.moveNext()) { |
+ var package = it0.current; |
+ log.message( |
+ "Resetting Git repository for " |
+ "${log.bold(package.name)} ${package.version}..."); |
+ join1() { |
+ trampoline0 = continue0; |
+ do trampoline0(); while (trampoline0 != null); |
+ } |
+ catch0(error, stackTrace) { |
+ try { |
+ if (error is git.GitException) { |
+ log.error( |
+ "Failed to reset ${log.bold(package.name)} " |
+ "${package.version}. Error:\n${error}"); |
+ log.fine(stackTrace); |
+ failures++; |
+ tryDeleteEntry(package.dir); |
+ join1(); |
+ } else { |
+ throw error; |
+ } |
+ } catch (error, stackTrace) { |
+ completer0.completeError(error, stackTrace); |
+ } |
+ } |
+ try { |
+ new Future.value( |
+ git.run(["clean", "-d", "--force", "-x"], workingDir: package.dir)).then((x0) { |
+ trampoline0 = () { |
+ trampoline0 = null; |
+ try { |
+ x0; |
+ new Future.value( |
+ git.run(["reset", "--hard", "HEAD"], workingDir: package.dir)).then((x1) { |
+ trampoline0 = () { |
+ trampoline0 = null; |
+ try { |
+ x1; |
+ successes++; |
+ join1(); |
+ } catch (e0, s0) { |
+ catch0(e0, s0); |
+ } |
+ }; |
+ do trampoline0(); while (trampoline0 != null); |
+ }, onError: catch0); |
+ } catch (e1, s1) { |
+ catch0(e1, s1); |
+ } |
+ }; |
+ do trampoline0(); while (trampoline0 != null); |
+ }, onError: catch0); |
+ } catch (e2, s2) { |
+ catch0(e2, s2); |
+ } |
+ } else { |
+ break0(); |
+ } |
+ } |
+ trampoline0 = continue0; |
+ do trampoline0(); while (trampoline0 != null); |
+ } |
+ if (!dirExists(systemCacheRoot)) { |
+ completer0.complete(new Pair(0, 0)); |
+ } else { |
+ join0(); |
+ } |
+ } catch (e, s) { |
+ completer0.completeError(e, s); |
} |
- } |
- |
- return new Pair(successes, failures); |
+ }); |
+ return completer0.future; |
} |
/// Ensure that the canonical clone of the repository referred to by [id] (the |
@@ -215,8 +274,7 @@ class GitSource extends CachedSource { |
return new Future.sync(() { |
var path = _repoCachePath(id); |
if (!entryExists(path)) { |
- return _clone(_getUrl(id), path, mirror: true) |
- .then((_) => _getRev(id)); |
+ return _clone(_getUrl(id), path, mirror: true).then((_) => _getRev(id)); |
} |
// If [id] didn't come from a lockfile, it may be using a symbolic |
@@ -253,7 +311,8 @@ class GitSource extends CachedSource { |
/// |
/// This assumes that the canonical clone already exists. |
Future<String> _getRev(PackageId id) { |
- return git.run(["rev-list", "--max-count=1", _getEffectiveRef(id)], |
+ return git.run( |
+ ["rev-list", "--max-count=1", _getEffectiveRef(id)], |
workingDir: _repoCachePath(id)).then((result) => result.first); |
} |
@@ -267,8 +326,8 @@ class GitSource extends CachedSource { |
/// |
/// If [shallow] is true, creates a shallow clone that contains no history |
/// for the repository. |
- Future _clone(String from, String to, {bool mirror: false, |
- bool shallow: false}) { |
+ Future _clone(String from, String to, {bool mirror: false, bool shallow: |
+ false}) { |
return new Future.sync(() { |
// Git on Windows does not seem to automatically create the destination |
// directory. |
@@ -284,8 +343,9 @@ class GitSource extends CachedSource { |
/// Checks out the reference [ref] in [repoPath]. |
Future _checkOut(String repoPath, String ref) { |
- return git.run(["checkout", ref], workingDir: repoPath).then( |
- (result) => null); |
+ return git.run( |
+ ["checkout", ref], |
+ workingDir: repoPath).then((result) => null); |
} |
/// Returns the path to the canonical clone of the repository referred to by |