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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/source/git.dart

Issue 221733002: Don't run "git fetch" multiple times for the same repository. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | « 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 10
11 import '../git.dart' as git; 11 import '../git.dart' as git;
12 import '../io.dart'; 12 import '../io.dart';
13 import '../package.dart'; 13 import '../package.dart';
14 import '../source.dart'; 14 import '../source.dart';
15 import '../utils.dart'; 15 import '../utils.dart';
16 16
17 /// A package source that gets packages from Git repos. 17 /// A package source that gets packages from Git repos.
18 class GitSource extends Source { 18 class GitSource extends Source {
19 final String name = "git"; 19 final String name = "git";
20 20
21 final bool shouldCache = true; 21 final bool shouldCache = true;
22 22
23 /// The paths to the canonical clones of repositories for which "git fetch"
24 /// has already been run during this run of pub.
25 final _updatedRepos = new Set<String>();
26
23 GitSource(); 27 GitSource();
24 28
25 /// Clones a Git repo to the local filesystem. 29 /// Clones a Git repo to the local filesystem.
26 /// 30 ///
27 /// The Git cache directory is a little idiosyncratic. At the top level, it 31 /// The Git cache directory is a little idiosyncratic. At the top level, it
28 /// contains a directory for each commit of each repository, named `<package 32 /// contains a directory for each commit of each repository, named `<package
29 /// name>-<commit hash>`. These are the canonical package directories that are 33 /// name>-<commit hash>`. These are the canonical package directories that are
30 /// linked to from the `packages/` directory. 34 /// linked to from the `packages/` directory.
31 /// 35 ///
32 /// In addition, the Git system cache contains a subdirectory named `cache/` 36 /// In addition, the Git system cache contains a subdirectory named `cache/`
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (error is! GitException) throw error; 148 if (error is! GitException) throw error;
145 return _updateRepoCache(id).then((_) => _revParse(id)); 149 return _updateRepoCache(id).then((_) => _revParse(id));
146 }); 150 });
147 }); 151 });
148 } 152 }
149 153
150 /// Runs "git fetch" in the canonical clone of the repository referred to by 154 /// Runs "git fetch" in the canonical clone of the repository referred to by
151 /// [id]. 155 /// [id].
152 /// 156 ///
153 /// This assumes that the canonical clone already exists. 157 /// This assumes that the canonical clone already exists.
154 Future _updateRepoCache(PackageId id) => 158 Future _updateRepoCache(PackageId id) {
155 git.run(["fetch"], workingDir: _repoCachePath(id)); 159 var path = _repoCachePath(id);
160 if (_updatedRepos.contains(path)) return new Future.value();
161 return git.run(["fetch"], workingDir: path).then((_) {
162 _updatedRepos.add(path);
163 });
164 }
156 165
157 /// Runs "git rev-parse" in the canonical clone of the repository referred to 166 /// Runs "git rev-parse" in the canonical clone of the repository referred to
158 /// by [id] on the effective ref of [id]. 167 /// by [id] on the effective ref of [id].
159 /// 168 ///
160 /// This assumes that the canonical clone already exists. 169 /// This assumes that the canonical clone already exists.
161 Future<String> _revParse(PackageId id) { 170 Future<String> _revParse(PackageId id) {
162 return git.run(["rev-parse", _getEffectiveRef(id)], 171 return git.run(["rev-parse", _getEffectiveRef(id)],
163 workingDir: _repoCachePath(id)).then((result) => result.first); 172 workingDir: _repoCachePath(id)).then((result) => result.first);
164 } 173 }
165 174
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return description['ref']; 238 return description['ref'];
230 } 239 }
231 240
232 /// Returns [description] if it's a description, or [PackageId.description] if 241 /// Returns [description] if it's a description, or [PackageId.description] if
233 /// it's a [PackageId]. 242 /// it's a [PackageId].
234 _getDescription(description) { 243 _getDescription(description) {
235 if (description is PackageId) return description.description; 244 if (description is PackageId) return description.description;
236 return description; 245 return description;
237 } 246 }
238 } 247 }
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