Fix inconsistent behaviour when adding reviewers

It was possible to add reviewers to a change when they had no visibility
to said change and/or were not active users. This is inconsistent with
what happens when adding groups. When adding groups, the non-active
users and the users with no visibility to the change would not be added.
Make the behavior of adding single reviewers consistent with adding
groups.

Change-Id: I606d43e6ca5ada88f26d3b14dd6f16c2306f74af
Only create All-Projects ACL once

If refs/meta/config already exists do not overwrite or update it
with default configuration. This protects site administrators who
run `java -war gerrit.war init -d /some/existing/site --batch` and
corrupt ACLs of a live server with default settings.

To really set the default ACLs on an existing site the admin
should remove the refs/meta/config branch so it can be created.

Change-Id: I44a21b0c162812747ebcd50535709e8330dfbef8
Enable scrollbars for "Edit Commit Message" TextArea

Bug: Issue 2890
Change-Id: I5de5179d2c059ddd9ef26ec37dcf9891926e1c8e
Use current time for cherry picked commits

Cherry picking with the submitter time could cause massive clock skew
in the Git commit graph if the server is shutdown before the submit can
finish, and restarted hours later. In such a case Gerrit will write out
new cherry picks using hour-old committer times. This can confuse a Git
revision walker if there are many such badly dated commits, more than
the "slop bucket" the revision walker can tolerate (5-10).

Updating the commit time on each attempt also allows this strategy to
work around bugs elsewhere in Gerrit that does not handle patch sets
with the same commit SHA-1 well. Each new retry will get a new SHA-1,
as the timestamp is updated.

Change-Id: Ia0be365054cdc4692a8f5aa2afc2fb87f2e7888a
Fix exception when clicking on binary file without being signed in

The user preferences are only available if the user is signed in.

Change-Id: I2ec307d34464394cd902218a32de1afdf5314f86
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
ACL: Fix transitions check & a '1' in RefName

In determining which access pattern has precedence, the 1st check is
which pattern is closer via Levenshtein distance.  The 2nd criteria is
if they differ on finite vs inifite.  The 3rd criteria is based on
number of transitions in the pattern, where it is supposed to be the
pattern with the  greatest number of transitions having precedence.  The
check of using the number of transitions had the check reversed.  This
caused the pattern with the fewest number of transitions to have
precedence.

When determining the Levenshtein distance of a glob style pattern the
trailing '*' would be changed to a '1'.  The issue with doing this is
that it could cause a different access pattern to take precedence if a
RefName contained a '1' character as that would cause the Levenshtein
distance to become decreased by one.

Change-Id: Ibdcd483c303d24565ef43001b3831f6463c2ed8f
Signed-off-by: John L. Villalovos <john.l.villalovos@intel.com>
Honor expireAfterWrite in the H2CacheImpl

The H2CacheImpl didn't honor the expireAfterWrite. This had an effect
that persisted entries never expired. For example, the web_sessions
cache entries didn't expire after their maxAge was reached.

Change-Id: I3a7c754ee05fe9ac92d96652db4b862bb597eba1
Signed-off-by: Saša Živkov <sasa.zivkov@sap.com>
Signed-off-by: Adrian Görler <adrian.goerler@sap.com>
Include all command arguments in SSH log entry

Previously the SSH log only included the first argument. This
prevented the repository name from being logged when
'git receive-pack' was executed instead of 'git-receive-pack'.

Now the SSH log includes all command arguments in the log ensuring
that the repository name is always logged. This is desirable behavior
for anyone looking to monitor repository access via the SSH log.

Change-Id: Idff950e5480a122a2cb366a443d25aa9e0a8f5c8
(cherry picked from commit a56057f97620ae7b958c338149853d605d8d3604)
ChangeData: Handle null PatchSet in isMergeable

Change-Id: I439dfc2cd94206d14bf871674549665b8d2dafdc
Embed consistency check results in ChangeInfo result

We would like to provide a way for bulk consistency checks, which
wouldn't fit very well with a single CheckResult entity, as we need to
associate each change with its list of problem messages. A cleaner way
to achieve this is to embed the problems in the change itself.

Change-Id: Idf3f39ce2423816b974643c71ab28d2075408e81
Clarify behaviour of the 'Remove Reviewer' permission for change owners

Without having the 'Remove Reviewer' permission, change owners can only
remove reviewers that have given a zero or positive score.  I.e. they
cannot remove reviewers that have given negative scores.

Clarify this in the documentation.

Change-Id: Ic1c5a292607f64337f82596553066cdbcd04eda2
Don't show 'Add Me' button for change owner or existing reviewers

Change-Id: Ib79bd18d863b7b62e90be7179d85465f25cc7759
Merge branch 'stable-2.10'

* stable-2.10:
  Don't show 'Add Me' button for change owner or existing reviewers
  Clarify behaviour of the 'Remove Reviewer' permission for change owners
  Include all command arguments in SSH log entry
  Honor expireAfterWrite in the H2CacheImpl
  ACL: Fix transitions check & a '1' in RefName
  Fix exception when clicking on binary file without being signed in
  Use current time for cherry picked commits
  Enable scrollbars for "Edit Commit Message" TextArea
  Only create All-Projects ACL once
  Fix inconsistent behaviour when adding reviewers

Conflicts:
	gerrit-cache-h2/src/main/java/com/google/gerrit/server/cache/h2/H2CacheFactory.java
	gerrit-gwtui/src/main/java/com/google/gerrit/client/change/Reviewers.java
	gerrit-server/src/main/java/com/google/gerrit/server/change/PostReviewers.java

Change-Id: I120ce5cc0ac117673c36d96cad301c4ac0982915
Merge "Merge branch 'stable-2.10'"
RestApiServlet: Give more useful errors to users

REST API handlers actually try pretty hard to give readable error
messages in their Gerrit-specific REST exception instances, even in
generic cases like ResourceNotFoundException. RestApiServlet was doing
the end user no favors by swallowing those, so stop.

For non-Gerrit-specific exception classes, which may be generated in
code not under our control, we continue to assume that the exception
message should not be shown to the user.

Change-Id: Ice3484e21c76019846874a8c39820672ad9bd2f0
Improve consistency of RestApiServlet catch blocks

Use consistent capitalization, as this seems to be what RFC2616 does.
Reorder catch blocks by numeric error code.

Change-Id: I096b6c199b4c92cc8dc2f13ad710b007934596fe
Detecting Trivial Rebases fails unnecessarily early

When label.Label-Name.copyAllScoresOnTrivialRebase
is enabled, the detection of Trivial Rebases fails
unnecessarily early if useContentMerge is disabled
in the project settings.

According to the code comments, a Rebase is Trivial
if the Old PatchSet, cherry picked ontop of Parent
of the New PS, yields the exact same tree as the
New PS.

There is no reason to fail this detection due to
a path conflict regardless of the circumstances.
A Trivial Rebase is always a Trivial Rebase if the
code delta is unchanged.

This fix makes the Trivial Rebase detection ignore
the useContentMerge settings.

Change-Id: I7ef9bda0db3acce0d19bc6888084e57e55cb4b32
Check consistency with a ListChangesOption

This allows for bulk consistency checking using the normal change
query interface. We already know how to detect and omit corrupt
changes; when consistency checking is enabled, we can do something
more useful.

One subtlety is that depending on the call path, we might fail to even
resolve a Change.Id to a Change. Teach ConsistencyChecker how to
handle this case by returning a single problem for this error, and
encapsulating the problem list in a Result containing the change as
well. We need to return the change in this way because the failure to
look up the change might have been transient; it would be confusing to
return "Error looking up change" and also return the change info
because the second lookup to populate the ChangeInfo succeeded.

Check can now be a thin wrapper around GetChange, at least for the GET
path.

Change-Id: I2b2e2b64d6c4e294e28640df271a9bd64a2f0b5f
Add API method for checking changes

Change-Id: Ie5aafdb408c835d135950f56876a28cac901b38c
Support fixing corrupt changes in ConsistencyChecker

To fix changes, pass an appropriate input to the checker; for now this
is empty, but may include things like a strategy to choose when there
are multiple options. (For example, if multiple patch sets have the
same SHA-1, we could delete all but the newest, or all but the
oldest.)

Change-Id: I016a94e27b8f6b63b3662b46271c01ed86110ec3