|
30 | 30 | $args->parseStandardArguments();
|
31 | 31 | $args->parse(
|
32 | 32 | array(
|
33 |
| - array( |
34 |
| - 'name' => 'ignore-duplicates', |
35 |
| - 'help' => 'Ignore duplicate symbols, choosing one at random. By '. |
36 |
| - 'default, this script throws if given duplicate '. |
37 |
| - 'symbols.', |
38 |
| - ), |
39 | 33 | array(
|
40 | 34 | 'name' => 'more',
|
41 | 35 | 'wildcard' => true,
|
42 | 36 | ),
|
43 | 37 | ));
|
44 | 38 |
|
45 |
| -$ignore_duplicates = $args->getArg('ignore-duplicates'); |
46 | 39 | $more = $args->getArg('more');
|
47 | 40 | if (count($more) !== 1) {
|
48 | 41 | $args->printHelpAndExit();
|
|
66 | 59 | $input = trim($input);
|
67 | 60 | $input = explode("\n", $input);
|
68 | 61 |
|
69 |
| -$map = array(); |
70 | 62 | $symbols = array();
|
71 | 63 | foreach ($input as $key => $line) {
|
72 | 64 | $line_no = $key + 1;
|
73 | 65 | $matches = null;
|
74 |
| - $ok = preg_match('/^([^ ]+) ([^ ]+) ([^ ]+) (\d+) (.*)$/', $line, $matches); |
| 66 | + $ok = preg_match( |
| 67 | + '/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '. |
| 68 | + '(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/', |
| 69 | + $line, |
| 70 | + $matches); |
75 | 71 | if (!$ok) {
|
76 | 72 | throw new Exception(
|
77 |
| - "Line #{$line_no} of input is invalid. Expected five space-delimited ". |
78 |
| - "fields: symbol name, symbol type, symbol language, line number, path. ". |
| 73 | + "Line #{$line_no} of input is invalid. Expected five or six ". |
| 74 | + "space-delimited fields: maybe symbol context, symbol name, symbol ". |
| 75 | + "type, symbol language, line number, path. ". |
79 | 76 | "For example:\n\n".
|
80 | 77 | "idx function php 13 /path/to/some/file.php\n\n".
|
81 | 78 | "Actual line was:\n\n".
|
82 | 79 | "{$line}");
|
83 | 80 | }
|
84 |
| - list($all, $name, $type, $lang, $line_number, $path) = $matches; |
85 |
| - |
86 |
| - if (isset($map[$name][$type][$lang])) { |
87 |
| - if ($ignore_duplicates) { |
88 |
| - echo "Ignoring duplicate definition of '{$name}' on line {$line_no}.\n"; |
89 |
| - } else { |
90 |
| - $previous = $map[$name][$type][$lang] + 1; |
91 |
| - throw new Exception( |
92 |
| - "Line #{$line_no} of input is invalid. It specifies a duplicate ". |
93 |
| - "symbol (same name, language, and type) which has already been ". |
94 |
| - "defined elsewhere. You must preprocess the symbol list to remove ". |
95 |
| - "duplicates and choose exactly one master definition for each ". |
96 |
| - "symbol, or specify --ignore-duplicates. This symbol was previously ". |
97 |
| - "defined on line #{$previous}.\n\n". |
98 |
| - "Line #{$line_no}:\n". |
99 |
| - $line."\n\n". |
100 |
| - "Line #{$previous}:\n". |
101 |
| - $input[$previous - 1]); |
102 |
| - } |
103 |
| - } else { |
104 |
| - $map[$name][$type][$lang] = $key; |
| 81 | + if (empty($matches['context'])) { |
| 82 | + $matches['context'] = ''; |
| 83 | + } |
| 84 | + $context = $matches['context']; |
| 85 | + $name = $matches['name']; |
| 86 | + $type = $matches['type']; |
| 87 | + $lang = $matches['lang']; |
| 88 | + $line_number = $matches['line']; |
| 89 | + $path = $matches['path']; |
| 90 | + |
| 91 | + if (strlen($context) > 128) { |
| 92 | + throw new Exception( |
| 93 | + "Symbol context '{$context}' defined on line #{$line_no} is too long, ". |
| 94 | + "maximum symbol context length is 128 characters."); |
105 | 95 | }
|
106 | 96 |
|
107 | 97 | if (strlen($name) > 128) {
|
|
130 | 120 | }
|
131 | 121 |
|
132 | 122 | $symbols[] = array(
|
| 123 | + 'ctxt' => $context, |
133 | 124 | 'name' => $name,
|
134 | 125 | 'type' => $type,
|
135 | 126 | 'lang' => $lang,
|
|
150 | 141 | foreach ($symbols as $dict) {
|
151 | 142 | $sql[] = qsprintf(
|
152 | 143 | $conn_w,
|
153 |
| - '(%d, %s, %s, %s, %d, %d)', |
| 144 | + '(%d, %s, %s, %s, %s, %d, %d)', |
154 | 145 | $project->getID(),
|
| 146 | + $dict['ctxt'], |
155 | 147 | $dict['name'],
|
156 | 148 | $dict['type'],
|
157 | 149 | $dict['lang'],
|
|
171 | 163 | queryfx(
|
172 | 164 | $conn_w,
|
173 | 165 | 'INSERT INTO %T
|
174 |
| - (arcanistProjectID, symbolName, symbolType, symbolLanguage, lineNumber, |
175 |
| - pathID) VALUES %Q', |
| 166 | + (arcanistProjectID, symbolContext, symbolName, symbolType, |
| 167 | + symbolLanguage, lineNumber, pathID) VALUES %Q', |
176 | 168 | $symbol->getTableName(),
|
177 | 169 | implode(', ', $chunk));
|
178 | 170 | }
|
|
0 commit comments