return;
}
+ $imagechanges = array();
+
$changes = $this->changes;
foreach ($changes as $change) {
$path = $change->getCurrentPath();
continue;
}
- $change->setOriginalFileData($repository_api->getOriginalFileData($path));
- $change->setCurrentFileData($repository_api->getCurrentFileData($path));
+ $imagechanges[$path] = $change;
+ }
+
+ // Fetch the actual file contents in batches so repositories
+ // that have slow random file accesses (i.e. mercurial) can
+ // optimize the retrieval.
+ $paths = array_keys($imagechanges);
+
+ $filedata = $repository_api->getBulkOriginalFileData($paths);
+ foreach ($filedata as $path => $data) {
+ $imagechanges[$path]->setOriginalFileData($data);
+ }
+
+ $filedata = $repository_api->getBulkCurrentFileData($paths);
+ foreach ($filedata as $path => $data) {
+ $imagechanges[$path]->setCurrentFileData($data);
}
$this->changes = $changes;
$this->getWorkingCopyRevision());
}
+ public function getBulkOriginalFileData($paths) {
+ return $this->getBulkFileDataAtRevision($paths, $this->getBaseCommit());
+ }
+
+ public function getBulkCurrentFileData($paths) {
+ return $this->getBulkFileDataAtRevision(
+ $paths,
+ $this->getWorkingCopyRevision());
+ }
+
+ private function getBulkFileDataAtRevision($paths, $revision) {
+ // Calling 'hg cat' on each file individually is slow (1 second per file
+ // on a large repo) because mercurial has to decompress and parse the
+ // entire manifest every time. Do it in one large batch instead.
+
+ // hg cat will write the file data to files in a temp directory
+ $tmpdir = Filesystem::createTemporaryDirectory();
+
+ // Mercurial doesn't create the directories for us :(
+ foreach ($paths as $path) {
+ $tmppath = $tmpdir.'/'.$path;
+ Filesystem::createDirectory(dirname($tmppath), 0755, true);
+ }
+
+ list($err, $stdout) = $this->execManualLocal(
+ 'cat --rev %s --output %s -- %C',
+ $revision,
+ // %p is the formatter for the repo-relative filepath
+ $tmpdir.'/%p',
+ implode(' ', $paths));
+
+ $filedata = array();
+ foreach ($paths as $path) {
+ $tmppath = $tmpdir.'/'.$path;
+ if (Filesystem::pathExists($tmppath)) {
+ $filedata[$path] = Filesystem::readFile($tmppath);
+ }
+ }
+
+ Filesystem::remove($tmpdir);
+
+ return $filedata;
+ }
+
private function getFileDataAtRevision($path, $revision) {
list($err, $stdout) = $this->execManualLocal(
'cat --rev %s -- %s',
}
}
+ /**
+ * Fetches the original file data for each path provided.
+ *
+ * @return map<string, string> Map from path to file data.
+ */
+ public function getBulkOriginalFileData($paths) {
+ $filedata = array();
+ foreach ($paths as $path) {
+ $filedata[$path] = $this->getOriginalFileData($path);
+ }
+
+ return $filedata;
+ }
+
+ /**
+ * Fetches the current file data for each path provided.
+ *
+ * @return map<string, string> Map from path to file data.
+ */
+ public function getBulkCurrentFileData($paths) {
+ $filedata = array();
+ foreach ($paths as $path) {
+ $filedata[$path] = $this->getCurrentFileData($path);
+ }
+
+ return $filedata;
+ }
/**
* @return Traversable