InlineEdit: Don't hide "Edit Message" for change edits

As flagged by reviewers in comments to I4d7046335 the implementation of
commit message manipulation in context of change edit wasn't consistent:

* Go to regular patch set (not change edit)
* Click on "Edit Message" button, edit message popup dialog appears
* Change commit message
* Save commit message
* Change edit is created
* "Edit Message" button is hidden unless the Change edit is published
or deleted.

"Edit Message" button should be visible and work as usual for change
edits as well. This change implements this behaviour. Now commit message
for change edits can be changed in two places: from the file table, by
clicking on commit message or by activating edit message popup dialog by
clicking in "Edit Message" button on change info line.

Change-Id: I1d6e64206fd037760c6dc4a16043071d24ee5a9a
Use PATCH_SET to build PATCH_LIST in rules engine

Loading the PATCH_LIST only requires the ObjectId of the revision.
Creating PATCH_SET_INFO requires parsing the commit object out of
Git to convert from RevCommit to PatchSetInfo, which is unnecessary
overkill for just to get the SHA-1.

This should fix a major performance problem with change search
results and user dashboards on gerrit-review. Each change was
querying the Git repository sequentially, which is not a free
operation in gerrit-review's replicated environment.

Change-Id: Ife16247ed8b5e08ebe204b31b4a8bed64467feb8
File table: Gray out repeating file segments in edit mode

Bug: issue 3075
Change-Id: I3f0a60e40b431ad28defa7b12335b3355a0f22a1
Inline Edit: Fix REST endpoint invocation for restoring files

At some point the input for this REST endpoint was changed from

  String path;
  boolean restore;

to

  String restore_path;

This change wasn't reflected on the client side.

Change-Id: I4d152a519706e15947defed7de55826457fd6c50
Merge "InlineEdit: Don't hide "Edit Message" for change edits"
ChangeUtil: Clarify that findChanges does not check visibility

Fix one caller in CreateChange that was assuming it would only return
zero or one changes. Use the same behavior as ChangesCollection:
return the same not found error whether there are zero or more than
one changes found, or if there was only one but it is not visible.

Change-Id: I17d2f4a497b4c587b2cfa091d9cf462cd83acda2
QueryChanges: Remove unused reverse field

Change-Id: Ic3e157c63f1985ce400be7149f76cbfb63a086a5
Fix limit handling in QueryProcessor

This was a mess, and hasn't been working for a long time. The test for
_more_changes added in this change does not pass prior to this change.

The only way we ever communicated that extra results were present out
of QueryProcessor was by including one more result. But different
pieces of the code were rarely clear on whether they should be
expecting an extra result or not. Moreover, there were three different
limits that were considered, and they were all given unhelpful names
like "limit" and "maxLimit."

Improving this situation substantially requires doing something like
what the end result is from the REST API: including for each list of
results a boolean indicating whether there are more results available.
Do this with a QueryResult class encapsulating these fields. This
class also includes the original query string and rewritten predicate
intermediates, which can help with debugging.

After this change, the semantics of the limits should be more clear.
The limit computation uses more helpful variable names, and enforces
that we always request a limit of n+1 from the secondary index.
However, this extra result never escapes to callers in a QueryResult
from QueryProcessor.

This also required changes to the query rewriter to replace all limit
predicates within the query with a fixed value that is always
different from any limit predicate in the original query. This may
actually make IndexRewriteTest a little easier to understand, as prior
to this change a different limit would appear in the IndexChangedQuery
portions than at the top level.

Change-Id: I4fcf7db0136fd77dbe91b20258ae80a9797a1af9
Add QueryProcessor methods to search by Predicate

Change-Id: I3e524fafc1e471308e9bc9b2d72c11fc75752647
Move stream-based QueryProcessor output to its own class

QueryProcessor now has a much more reasonable scope of just turning
lists of queries into QueryResults.

Change-Id: I306b72264b5d9398a12a22f26d4e5397b0dd8a11
OutputStreamQuery: Optimize formatter allocation

Use Joda's DateTimeFormatter rather than the slow, unsafe JDK
SimpleDateFormat. This is immutable so we can parse the format string
only once.

Don't construct a Gson if we don't need it. Continue constructing one
per request, which is cheap and we already do it for the REST API.

Change-Id: Ibd60893c008f5b0da9d25a0190d16390d138c5ba
Use secondary index for advertising extra haves during push

The current code uses ChangeAccess.byChangesOpenNext to list recent
changes; other indexes on that table don't have a specified sort
order. sortkey is going away, so we can't use that index anymore.
Rather than add another index just for this one query, just use the
normal query system to look up recent changes, which are naturally
ordered by updated time.

This does incur a slight performance penalty, as the query system
checks visibility of changes where the direct database scan did not.
However, this provides a security benefit (admittedly slight): SHA-1s
of patch sets that are not visible are no longer advertised.

Change-Id: I8c73cbf631ce074d6676afd35337579a0b7f5119
Terminate sortkey with prejudice

It has not been used by the search system since 2.8 and all code using
it in a meaningful way in Gerrit has been removed. Now we can remove
it from the database and API classes.

This requires a schema upgrade to delete the column and rebuild some
indexes to use last_updated_on instead of sort_key.

Change-Id: I87660f8e0e44bf11bafd9fa24f990351759df3fb
Add query tests for visibleto predicate

Change-Id: I0c344fd149bd9d970a53f9d0bd7607f91f889e69
QueryProcessor: Don't double-add visibleto predicate

The purpose of ANDing in the predicate early in the process was to
allow the query rewriter to move it around. However, the current set
of basic rewrites plus the index rewriter does not touch this
particular predicate at all.

Simplify the query by ANDing in only at the end.

Change-Id: I53d8ddb3a8c283a8f3ecad58112f7a988b353669
Merge changes from topic 'inline-fixes'

* changes:
  Inline Edit: Fix REST endpoint invocation for restoring files
  File table: Gray out repeating file segments in edit mode
File table: Stop event propagation on restore deleted files

Deleted files in commit can be restored in context of change edits.
The user interface for it is restore icon. Hyperlink is also shown,
so that the rows with restored operations have the same look and feel,
like others rows. However, the navigation to edit screen, as for not
deleted files is not supported.

Stop the event propagation as otherwise onCellSingleClick() callback
is called and in the end Gerrit.display(token) method is invoked for
deleted files on restore operation. The consequence is that edit
screen was instantiated and error was shown, because some REST
endpoints were failing.

Change-Id: I5ffcf5bb8acf97d10e40bc49d98cefcc90870720
Cut off ",edit" suffix before parsing change id

In change edit workflow, ",edit" suffix was added to differentiate
between edit and review contexts, e.g. to pre-activate edit mode.
Parsing of change id wasn't adjusted to respect this suffix. As the
consequence javascript exception happens, during attempt to parse
"change-number,edit" as change id.

Bug: issue 3079
Change-Id: Ia9b418153a9c165cad15a1791627d5a22620191b
InlineEdit: Document how to create empty changes

Change-Id: Ibaac95d84470153fee36c8c52fac62777900928e
Optimize cherry pick operation by not re-reading change

Change-Id: If2c307b43788fe9c2efc008fee009334730c4506