Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15388307
D12608.id30272.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
21 KB
Referenced Files
None
Subscribers
None
D12608.id30272.diff
View Options
diff --git a/resources/sql/autopatches/20150429.repositorysymbols.sql b/resources/sql/autopatches/20150429.repositorysymbols.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150429.repositorysymbols.sql
@@ -0,0 +1,3 @@
+ALTER TABLE {$NAMESPACE}_repository.repository_symbol
+ DROP COLUMN arcanistProjectID,
+ ADD repositoryPHID varbinary(64) NOT NULL;
diff --git a/scripts/symbols/clear_project_symbols.php b/scripts/symbols/clear_project_symbols.php
--- a/scripts/symbols/clear_project_symbols.php
+++ b/scripts/symbols/clear_project_symbols.php
@@ -4,16 +4,18 @@
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
-$project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
- 'name = %s', $argv[1]);
-if (!$project) {
- throw new Exception('No such arcanist project.');
+$repository = id(new PhabricatorRepository())->loadOneWhere(
+ 'callsign = %s',
+ $argv[1]);
+
+if (!$repository) {
+ throw new Exception(pht('No such repository.'));
}
$input = file_get_contents('php://stdin');
$normalized = array();
foreach (explode("\n", trim($input)) as $path) {
- // emulate the behavior of the symbol generation scripts
+ // Emulate the behavior of the symbol generation scripts.
$normalized[] = '/'.ltrim($path, './');
}
$paths = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(
@@ -25,8 +27,8 @@
foreach (array_chunk(array_values($paths), 128) as $chunk) {
queryfx(
$conn_w,
- 'DELETE FROM %T WHERE arcanistProjectID = %d AND pathID IN (%Ld)',
+ 'DELETE FROM %T WHERE repositoryPHID = %s AND pathID IN (%Ld)',
$symbol->getTableName(),
- $project->getID(),
+ $repository->getPHID(),
$chunk);
}
diff --git a/scripts/symbols/generate_ctags_symbols.php b/scripts/symbols/generate_ctags_symbols.php
--- a/scripts/symbols/generate_ctags_symbols.php
+++ b/scripts/symbols/generate_ctags_symbols.php
@@ -90,8 +90,7 @@
}
function ctags_get_parser_future($file_path) {
- $future = new ExecFuture('ctags -n --fields=Kls -o - %s',
- $file_path);
+ $future = new ExecFuture('ctags -n --fields=Kls -o - %s', $file_path);
return $future;
}
diff --git a/scripts/symbols/generate_php_symbols.php b/scripts/symbols/generate_php_symbols.php
--- a/scripts/symbols/generate_php_symbols.php
+++ b/scripts/symbols/generate_php_symbols.php
@@ -100,7 +100,7 @@
}
}
-function print_symbol($file, $type, $token, $context = null) {
+function print_symbol($file, $type, XHPASTToken $token, $context = null) {
$parts = array(
$context ? $context->getConcreteString() : '',
// variable tokens are `$name`, not just `name`, so strip the $ off of
diff --git a/scripts/symbols/import_project_symbols.php b/scripts/symbols/import_project_symbols.php
--- a/scripts/symbols/import_project_symbols.php
+++ b/scripts/symbols/import_project_symbols.php
@@ -7,9 +7,9 @@
$args = new PhutilArgumentParser($argv);
$args->setSynopsis(<<<EOSYNOPSIS
-**import_project_symbols.php** [__options__] __project_name__ < symbols
+**import_repository_symbols.php** [__options__] __callsign__ < symbols
- Import project symbols (symbols are read from stdin).
+ Import repository symbols (symbols are read from stdin).
EOSYNOPSIS
);
$args->parseStandardArguments();
@@ -17,20 +17,23 @@
array(
array(
'name' => 'no-purge',
- 'help' => 'Do not clear all symbols for this project before '.
- 'uploading new symbols. Useful for incremental updating.',
+ 'help' => pht(
+ 'Do not clear all symbols for this repository before '.
+ 'uploading new symbols. Useful for incremental updating.'),
),
array(
'name' => 'ignore-errors',
- 'help' => 'If a line can\'t be parsed, ignore that line and '.
- 'continue instead of exiting.',
+ 'help' => pht(
+ "If a line can't be parsed, ignore that line and ".
+ "continue instead of exiting."),
),
array(
'name' => 'max-transaction',
'param' => 'num-syms',
- 'default' => '100000',
- 'help' => 'Maximum number of symbols that should '.
- 'be part of a single transaction',
+ 'default' => '100000',
+ 'help' => pht(
+ 'Maximum number of symbols that should '.
+ 'be part of a single transaction.'),
),
array(
'name' => 'more',
@@ -43,81 +46,92 @@
$args->printHelpAndExit();
}
-$project_name = head($more);
-$project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere(
- 'name = %s',
- $project_name);
+$callsign = head($more);
+$repository = id(new PhabricatorRepository())->loadOneWhere(
+ 'callsign = %s',
+ $callsign);
-if (!$project) {
- // TODO: Provide a less silly way to do this explicitly, or just do it right
- // here.
- echo "Project '{$project_name}' is unknown. Upload a diff to implicitly ".
- "create it.\n";
+if (!$repository) {
+ echo pht("Repository '%s' does not exist.", $callsign);
exit(1);
}
-echo "Parsing input from stdin...\n";
+echo pht('Parsing input from stdin...'), "\n";
$input = file_get_contents('php://stdin');
$input = trim($input);
$input = explode("\n", $input);
-function commit_symbols ($syms, $project, $no_purge) {
- echo "Looking up path IDs...\n";
+function commit_symbols(
+ array $syms,
+ PhabricatorRepository $repository,
+ $no_purge) {
+
+ echo pht('Looking up path IDs...'), "\n";
$path_map =
PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(
- ipull($syms, 'path'));
+ ipull($syms, 'path'));
$symbol = new PhabricatorRepositorySymbol();
$conn_w = $symbol->establishConnection('w');
- echo "Preparing queries...\n";
+ echo pht('Preparing queries...'), "\n";
$sql = array();
foreach ($syms as $dict) {
$sql[] = qsprintf(
- $conn_w,
- '(%d, %s, %s, %s, %s, %d, %d)',
- $project->getID(),
- $dict['ctxt'],
- $dict['name'],
- $dict['type'],
- $dict['lang'],
- $dict['line'],
- $path_map[$dict['path']]);
+ $conn_w,
+ '(%s, %s, %s, %s, %s, %d, %d)',
+ $repository->getPHID(),
+ $dict['ctxt'],
+ $dict['name'],
+ $dict['type'],
+ $dict['lang'],
+ $dict['line'],
+ $path_map[$dict['path']]);
}
if (!$no_purge) {
- echo "Purging old syms...\n";
- queryfx($conn_w,
- 'DELETE FROM %T WHERE arcanistProjectID = %d',
- $symbol->getTableName(),
- $project->getID());
+ echo pht('Purging old symbols...'), "\n";
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T WHERE repositoryPHID = %s',
+ $symbol->getTableName(),
+ $repository->getPHID());
}
- echo "Loading ".number_format(count($sql))." syms...\n";
+ echo pht('Loading %d symbols...', number_format(count($sql))), "\n";
foreach (array_chunk($sql, 128) as $chunk) {
- queryfx($conn_w,
- 'INSERT INTO %T
- (arcanistProjectID, symbolContext, symbolName, symbolType,
+ queryfx(
+ $conn_w,
+ 'INSERT INTO %T
+ (repositoryPHID, symbolContext, symbolName, symbolType,
symbolLanguage, lineNumber, pathID) VALUES %Q',
- $symbol->getTableName(),
- implode(', ', $chunk));
+ $symbol->getTableName(),
+ implode(', ', $chunk));
}
-
}
function check_string_value($value, $field_name, $line_no, $max_length) {
if (strlen($value) > $max_length) {
throw new Exception(
- "{$field_name} '{$value}' defined on line #{$line_no} is too long, ".
- "maximum {$field_name} length is {$max_length} characters.");
+ pht(
+ "%s '%s' defined on line #%d is too long, ".
+ "maximum %s length is %d characters.",
+ $field_name,
+ $value,
+ $line_no,
+ $field_name,
+ $max_length));
}
if (!phutil_is_utf8_with_only_bmp_characters($value)) {
throw new Exception(
- "{$field_name} '{$value}' defined on line #{$line_no} is not a valid ".
- "UTF-8 string, ".
- "it should contain only UTF-8 characters.");
+ pht(
+ "{%s '%s' defined on line #%d is not a valid ".
+ "UTF-8 string, it should contain only UTF-8 characters.",
+ $field_name,
+ $value,
+ $line_no));
}
}
@@ -134,13 +148,14 @@
$matches);
if (!$ok) {
throw new Exception(
- "Line #{$line_no} of input is invalid. Expected five or six ".
- "space-delimited fields: maybe symbol context, symbol name, symbol ".
- "type, symbol language, line number, path. ".
- "For example:\n\n".
- "idx function php 13 /path/to/some/file.php\n\n".
- "Actual line was:\n\n".
- "{$line}");
+ pht(
+ "Line #%d of input is invalid. Expected five or six space-delimited ".
+ "fields: maybe symbol context, symbol name, symbol type, symbol ".
+ "language, line number, path. For example:\n\n%s\n\n".
+ "Actual line was:\n\n%s",
+ $line_no,
+ 'idx function php 13 /path/to/some/file.php',
+ $line));
}
if (empty($matches['context'])) {
$matches['context'] = '';
@@ -160,9 +175,13 @@
if (!strlen($path) || $path[0] != '/') {
throw new Exception(
- "Path '{$path}' defined on line #{$line_no} is invalid. Paths should ".
- "begin with '/' and specify a path from the root of the project, like ".
- "'/src/utils/utils.php'.");
+ pht(
+ "Path '%s' defined on line #%d is invalid. Paths should begin with ".
+ "'%s' and specify a path from the root of the project, like '%s'.",
+ $path,
+ $line_no,
+ '/',
+ '/src/utils/utils.php'));
}
$symbols[] = array(
@@ -182,24 +201,26 @@
}
if (count ($symbols) >= $args->getArg('max-transaction')) {
- try {
- echo "Committing {$args->getArg('max-transaction')} symbols....\n";
- commit_symbols($symbols, $project, $no_purge);
- $no_purge = true;
- unset($symbols);
- $symbols = array();
- } catch (Exception $e) {
- if ($args->getArg('ignore-errors')) {
- continue;
- } else {
- throw $e;
- }
+ try {
+ echo
+ pht('Committing %d symbols....', $args->getArg('max-transaction')),
+ "\n";
+ commit_symbols($symbols, $repository, $no_purge);
+ $no_purge = true;
+ unset($symbols);
+ $symbols = array();
+ } catch (Exception $e) {
+ if ($args->getArg('ignore-errors')) {
+ continue;
+ } else {
+ throw $e;
}
+ }
}
}
if (count($symbols)) {
- commit_symbols($symbols, $project, $no_purge);
+ commit_symbols($symbols, $repository, $no_purge);
}
-echo "Done.\n";
+echo pht('Done.'), "\n";
diff --git a/src/applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php
--- a/src/applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php
+++ b/src/applications/diffusion/conduit/DiffusionFindSymbolsConduitAPIMethod.php
@@ -8,7 +8,7 @@
}
public function getMethodDescription() {
- return 'Retrieve Diffusion symbol information.';
+ return pht('Retrieve Diffusion symbol information.');
}
protected function defineParamTypes() {
@@ -51,7 +51,6 @@
}
$query->needPaths(true);
- $query->needArcanistProjects(true);
$query->needRepositories(true);
$results = $query->execute();
diff --git a/src/applications/diffusion/controller/DiffusionSymbolController.php b/src/applications/diffusion/controller/DiffusionSymbolController.php
--- a/src/applications/diffusion/controller/DiffusionSymbolController.php
+++ b/src/applications/diffusion/controller/DiffusionSymbolController.php
@@ -24,25 +24,23 @@
$query->setLanguage($request->getStr('lang'));
}
- if ($request->getStr('projects')) {
- $phids = $request->getStr('projects');
+ if ($request->getStr('repositories')) {
+ $phids = $request->getStr('repositories');
$phids = explode(',', $phids);
$phids = array_filter($phids);
if ($phids) {
- $projects = id(new PhabricatorRepositoryArcanistProject())
- ->loadAllWhere(
- 'phid IN (%Ls)',
- $phids);
- $projects = mpull($projects, 'getID');
- if ($projects) {
- $query->setProjectIDs($projects);
+ $repositories = id(new PhabricatorRepository())->loadAllWhere(
+ 'phid IN (%Ls)',
+ $phids);
+ $repositories = mpull($repositories, 'getPHID');
+ if ($repositories) {
+ $query->setRepositoryPHIDs($repositories);
}
}
}
$query->needPaths(true);
- $query->needArcanistProjects(true);
$query->needRepositories(true);
$symbols = $query->execute();
@@ -73,13 +71,6 @@
$rows = array();
foreach ($symbols as $symbol) {
- $project = $symbol->getArcanistProject();
- if ($project) {
- $project_name = $project->getName();
- } else {
- $project_name = '-';
- }
-
$file = $symbol->getPath();
$line = $symbol->getLineNumber();
@@ -110,7 +101,7 @@
$symbol->getSymbolContext(),
$symbol->getSymbolName(),
$symbol->getSymbolLanguage(),
- $project_name,
+ $repo->getCallsign(),
$location,
);
}
@@ -122,7 +113,7 @@
pht('Context'),
pht('Name'),
pht('Language'),
- pht('Project'),
+ pht('Repository'),
pht('File'),
));
$table->setColumnClasses(
diff --git a/src/applications/diffusion/query/DiffusionSymbolQuery.php b/src/applications/diffusion/query/DiffusionSymbolQuery.php
--- a/src/applications/diffusion/query/DiffusionSymbolQuery.php
+++ b/src/applications/diffusion/query/DiffusionSymbolQuery.php
@@ -16,12 +16,11 @@
private $namePrefix;
private $name;
- private $projectIDs;
+ private $repositoryPHIDs;
private $language;
private $type;
private $needPaths;
- private $needArcanistProject;
private $needRepositories;
@@ -72,8 +71,8 @@
/**
* @task config
*/
- public function setProjectIDs(array $project_ids) {
- $this->projectIDs = $project_ids;
+ public function setRepositoryPHIDs(array $repository_phids) {
+ $this->repositoryPHIDs = $repository_phids;
return $this;
}
@@ -108,15 +107,6 @@
/**
* @task config
*/
- public function needArcanistProjects($need_arcanist_projects) {
- $this->needArcanistProjects = $need_arcanist_projects;
- return $this;
- }
-
-
- /**
- * @task config
- */
public function needRepositories($need_repositories) {
$this->needRepositories = $need_repositories;
return $this;
@@ -132,10 +122,10 @@
public function execute() {
if ($this->name && $this->namePrefix) {
throw new Exception(
- 'You can not set both a name and a name prefix!');
+ pht('You can not set both a name and a name prefix!'));
} else if (!$this->name && !$this->namePrefix) {
throw new Exception(
- 'You must set a name or a name prefix!');
+ pht('You must set a name or a name prefix!'));
}
$symbol = new PhabricatorRepositorySymbol();
@@ -155,9 +145,6 @@
if ($this->needPaths) {
$this->loadPaths($symbols);
}
- if ($this->needArcanistProjects || $this->needRepositories) {
- $this->loadArcanistProjects($symbols);
- }
if ($this->needRepositories) {
$this->loadRepositories($symbols);
}
@@ -208,11 +195,11 @@
$this->namePrefix);
}
- if ($this->projectIDs) {
+ if ($this->repositoryPHIDs) {
$where[] = qsprintf(
$conn_r,
- 'arcanistProjectID IN (%Ld)',
- $this->projectIDs);
+ 'repositoryPHID IN (%Ls)',
+ $this->repositoryPHIDs);
}
if ($this->language) {
@@ -253,46 +240,15 @@
/**
* @task internal
*/
- private function loadArcanistProjects(array $symbols) {
- assert_instances_of($symbols, 'PhabricatorRepositorySymbol');
- $projects = id(new PhabricatorRepositoryArcanistProject())->loadAllWhere(
- 'id IN (%Ld)',
- mpull($symbols, 'getArcanistProjectID'));
- foreach ($symbols as $symbol) {
- $project = idx($projects, $symbol->getArcanistProjectID());
- $symbol->attachArcanistProject($project);
- }
- }
-
-
- /**
- * @task internal
- */
private function loadRepositories(array $symbols) {
assert_instances_of($symbols, 'PhabricatorRepositorySymbol');
- $projects = mpull($symbols, 'getArcanistProject');
- $projects = array_filter($projects);
-
- $repo_ids = mpull($projects, 'getRepositoryID');
- $repo_ids = array_filter($repo_ids);
-
- if ($repo_ids) {
- $repos = id(new PhabricatorRepositoryQuery())
- ->setViewer($this->getViewer())
- ->withIDs($repo_ids)
- ->execute();
- } else {
- $repos = array();
- }
-
+ $repositories = id(new PhabricatorRepository())->loadAllWhere(
+ 'phid IN (%Ls)',
+ mpull($symbols, 'getRepositoryPHID'));
foreach ($symbols as $symbol) {
- $proj = $symbol->getArcanistProject();
- if ($proj) {
- $symbol->attachRepository(idx($repos, $proj->getRepositoryID()));
- } else {
- $symbol->attachRepository(null);
- }
+ $repository = idx($repositories, $symbol->getRepositoryPHID());
+ $symbol->attachRepository($repository);
}
}
diff --git a/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php b/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php
--- a/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php
+++ b/src/applications/diffusion/typeahead/DiffusionSymbolDatasource.php
@@ -32,7 +32,6 @@
->setViewer($viewer)
->setNamePrefix($raw_query)
->setLimit(15)
- ->needArcanistProjects(true)
->needRepositories(true)
->needPaths(true)
->execute();
@@ -40,14 +39,14 @@
$lang = $symbol->getSymbolLanguage();
$name = $symbol->getSymbolName();
$type = $symbol->getSymbolType();
- $proj = $symbol->getArcanistProject()->getName();
+ $repo = $symbol->getRepository()->getName();
$results[] = id(new PhabricatorTypeaheadResult())
->setName($name)
->setURI($symbol->getURI())
->setPHID(md5($symbol->getURI())) // Just needs to be unique.
->setDisplayName($name)
- ->setDisplayType(strtoupper($lang).' '.ucwords($type).' ('.$proj.')')
+ ->setDisplayType(strtoupper($lang).' '.ucwords($type).' ('.$repo.')')
->setPriorityType('symb');
}
}
diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php
--- a/src/applications/repository/storage/PhabricatorRepository.php
+++ b/src/applications/repository/storage/PhabricatorRepository.php
@@ -1163,10 +1163,15 @@
$projects = id(new PhabricatorRepositoryArcanistProject())
->loadAllWhere('repositoryID = %d', $this->getID());
foreach ($projects as $project) {
- // note each project deletes its PhabricatorRepositorySymbols
$project->delete();
}
+ $symbols = id(new PhabricatorRepositorySymbol())
+ ->loadAllWhere('repositoryPHID = %s', $this->getPHID());
+ foreach ($symbols as $symbol) {
+ $symbol->delete();
+ }
+
$commits = id(new PhabricatorRepositoryCommit())
->loadAllWhere('repositoryID = %d', $this->getID());
foreach ($commits as $commit) {
diff --git a/src/applications/repository/storage/PhabricatorRepositoryArcanistProject.php b/src/applications/repository/storage/PhabricatorRepositoryArcanistProject.php
--- a/src/applications/repository/storage/PhabricatorRepositoryArcanistProject.php
+++ b/src/applications/repository/storage/PhabricatorRepositoryArcanistProject.php
@@ -45,20 +45,6 @@
PhabricatorRepositoryArcanistProjectPHIDType::TYPECONST);
}
- public function delete() {
- $this->openTransaction();
-
- queryfx(
- $this->establishConnection('w'),
- 'DELETE FROM %T WHERE arcanistProjectID = %d',
- id(new PhabricatorRepositorySymbol())->getTableName(),
- $this->getID());
-
- $result = parent::delete();
- $this->saveTransaction();
- return $result;
- }
-
public function getRepository() {
return $this->assertAttached($this->repository);
}
diff --git a/src/applications/repository/storage/PhabricatorRepositorySymbol.php b/src/applications/repository/storage/PhabricatorRepositorySymbol.php
--- a/src/applications/repository/storage/PhabricatorRepositorySymbol.php
+++ b/src/applications/repository/storage/PhabricatorRepositorySymbol.php
@@ -8,7 +8,6 @@
*/
final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO {
- protected $arcanistProjectID;
protected $symbolContext;
protected $symbolName;
protected $symbolType;
@@ -17,7 +16,6 @@
protected $lineNumber;
private $path = self::ATTACHABLE;
- private $arcanistProject = self::ATTACHABLE;
private $repository = self::ATTACHABLE;
protected function getConfiguration() {
@@ -42,13 +40,6 @@
}
public function getURI() {
- if (!$this->repository) {
- // This symbol is in the index, but we don't know which Repository it's
- // part of. Usually this means the Arcanist Project hasn't been linked
- // to a Repository. We can't generate a URI, so just fail.
- return null;
- }
-
$request = DiffusionRequest::newFromDictionary(
array(
'user' => PhabricatorUser::getOmnipotentUser(),
@@ -80,13 +71,4 @@
return $this;
}
- public function getArcanistProject() {
- return $this->assertAttached($this->arcanistProject);
- }
-
- public function attachArcanistProject($project) {
- $this->arcanistProject = $project;
- return $this;
- }
-
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 3:37 AM (6 d, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7679248
Default Alt Text
D12608.id30272.diff (21 KB)
Attached To
Mode
D12608: Move symbols to be repository-based
Attached
Detach File
Event Timeline
Log In to Comment