Add PhutilGitURI for parsing scp-style Git URIs

Summary:
See T1529.

We currently convert "scp-style" URIs into normal URIs in Phabricator:

  git@host:path -> ssh://git@host/path

This isn't correct; paths in the scp-style URIs are resolved relatively, while paths in the normal-style URIs are resolved absolutely.

Since we can't do this transformation any more, add a real parser so we can replace the transformation code in Phabricator with something sensible.

Test Plan: Unit test coverage.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1529

Differential Revision: https://secure.phabricator.com/D3033
Remove "remote_hooks_installed" from libphutil/.arcconfig

Summary: See D967.

Test Plan: Looked.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3049
Move AphrontWriteGuard to libphutil

Summary: Toward a queryfx() in libphutil and general separation of Aphront from Phabricator.

Test Plan: Loaded some pages which use write guard.

Reviewers: btrahan, vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3051
Move AphrontConnection to libphutil

Summary: Move AphrontConnection and related classes to libphutil so we can move queryfx() here.

Test Plan: lint / loaded pages.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3055
Move querfyx() to libphutil

Summary: See recent diffs.

Test Plan: Loaded site.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3057
Fix an issue where closed connections are retained in a zombie state by PHP

Summary:
Argh, this took me like 4 hours to figure out.

After D3035, daemons on secure.phabricator.com are dying after a while with "too many open files". These aren't live MySQL connections (`SHOW FULL PROCESSLIST` shows nothing) but fds that haven't been completely disposed of (TCP connections in CLOSE_WAIT or unix sockets not doing much of anything). This repro'd on OSX and Ubuntu across many different versions of PHP, which I spent hours building since I'm dumb and made a mistake early on which led me to believe that I wasn't seeing it on OSX.

In fact, these connections don't close because we're still holding a reference to the result set (if we've executed any queries on the connection). Throw the result set away when we close a connection.

I missed this in D3035 originally because I inspected `SHOW FULL PROCESSLIST` but didn't consider to inspect `lsof`.

Test Plan: Built a script that does 300 connects, SELECT 1, and then does "lsof | grep getmypid() | wc -l". With the assignment commented out, it reports ~300 file descriptors. With the assignment there, it reports ~0 file descriptors.

Reviewers: btrahan, vrana, nh, dschleimer

Reviewed By: dschleimer

CC: aran

Maniphest Tasks: T1470

Differential Revision: https://secure.phabricator.com/D3071
Move qsprintf() test cases back to phabricator

Summary: We could add stub tests based on an Isolated connection, but Lisk has no clue how to get a real connection in order for mysql_real_escape_string() to work so these tests need to go back to Phabricator.

Test Plan: Liberate / Lint.

Reviewers: nh, btrahan, vrana

Reviewed By: nh

CC: aran

Maniphest Tasks: T1283

Differential Revision: https://secure.phabricator.com/D3073
Add PhutilBufferedIterator

Summary: I'm planning to build object iterators for the ETL pipeline, but we can share most of the code between them and LiskMigrationIterator by creating a primitive.

Test Plan: Unit tests.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1562

Differential Revision: https://secure.phabricator.com/D3075
Highlight LESS and SCSS as CSS, because it's better than nothing.

Summary:
LESS and SCSS are two stylesheet languages similar in syntax to CSS.
Pygments doesn't directly support them, but I don't think it's unreasonable to
highlight them as CSS by default. They're close enough to CSS that it doesn't
look terrible, and I think they're becoming used enough that it makes sense
to do this by default.

Test Plan:
Viewed a .less, and .scss file under the CSS parser to see if they looked
reasonable.

See P473 (scss) and P474 (less) for samples of them highlighted with css.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3086
Merge pull request #13 from CodeBlock/master

D3086
Fix warning when selecting descendants of a class with no descendants

Summary: If you try to select the descendants of a class that has no children, we currently raise a warning. Handle this condition properly.

Test Plan: Selected descendants of a childless class.

Reviewers: vrana, btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D3097
Send daemon heartbeat, exit status

Summary:
Send a heartbeat via conduit (if possible) for daemons, and when they exit
cleanly, set the status to exited. This is the libphutil part of D3126.

Test Plan: See test plan for D3126.

Reviewers: epriestley, vrana

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3127
Fix an XSS hole in Remarkup link handling, see T1601

Auditors: nh
Document %Ls in `csprintf()`

Test Plan: Read.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3156
Fix an issue where messages may not be processed by PhutilConsoleServer after the client exits

Summary:
When we call update(), it may move messages into the read() buffer but we won't process them right now. Process messages after update().

Also improve the correctness of the flush() implementation.

See D2841.

Test Plan: Ran test script with 4-second linter child, got 4 messages on stdout.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D3152
Don't use stream_socket_shutdown() in socket channel

Summary: I'm not sure if `fclose()` does everything we need in Zend PHP but this solves all my troubles.

Test Plan:
  $ ./lint_mock.php # with 4 both with and without questions

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3157
Fix an issue where PHP_EOL_COMMENT tokens were discarded on EOF

Summary:
There was no token production rule from state <PHP_EOL_COMMENT> on <<EOF>>.

NOTE: I didn't bump the xhpast version since this is such a minor edge case that it didn't seem worth the trouble.

Test Plan: Unit test now passes with a clean xhpast build.

Reviewers: nh

Reviewed By: nh

CC: aran

Maniphest Tasks: T1599

Differential Revision: https://secure.phabricator.com/D3154
Provide a function for validating translations

Summary:
Based on discussion at T1139#32, we will not provide context to translators.
Thus we should limit the translations to have the same special characters.

This disallows some originals: e.g. 'print <filename>' in text context - one should use 'print <%s>' with `pht('filename')`.
And some translations: e.g. 'me & you' translated as 'me and you'.

We should call this from linter but I don't know how.
We can easily call it from `addTranslations()` in runtime but I'm not sure it's worth the overhead.

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D3164
Provide prompt for console server

Test Plan: Used it in `arc diff`.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D3167