Merge branch 'stable-3.7' into stable-3.8
* stable-3.7:
Add metrics for git/upload-pack/*bitmap* misses
Add timer for git/upload-pack/phase_searching_for_*
Fix: CommentTimestampAdapter can't parse some old comments
Add timer for git/upload-pack/phase_negotiating
H2CacheImpl: Lower logging level for no pruning
Release-Notes: skip
Change-Id: I13c3d2502d347409682f4c355a73847dbb410cde
diff --git a/.bazelrc b/.bazelrc
index 407b005..cf5403d 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -37,6 +37,6 @@
build --announce_rc
test --build_tests_only
-test --test_output=all
+test --test_output=errors
import %workspace%/tools/remote-bazelrc
diff --git a/.gitignore b/.gitignore
index 53bc9f6..0bbcaba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,8 @@
/infer-out
/local.properties
/node_modules/
+/polygerrit-ui/node_modules/
+/polygerrit-ui/app/node_modules/
/package-lock.json
/plugins/*
/polygerrit-ui/coverage/
diff --git a/Documentation/access-control.txt b/Documentation/access-control.txt
index 3da69df..cf89982 100644
--- a/Documentation/access-control.txt
+++ b/Documentation/access-control.txt
@@ -782,7 +782,7 @@
=== Rebase
This category permits users to rebase changes via the web UI by pushing
-the `Rebase Change` button.
+the `REBASE` button.
The change owner and submitters can always rebase changes in the web UI
(even without having the `Rebase` access right assigned).
@@ -800,6 +800,22 @@
Users without this access right who are able to upload changes can
still do the revert locally and upload the revert commit as a new change.
+[[category_remove_label]]
+=== Remove Label (Remove Vote)
+
+For every configured label `My-Name` in the project, there is a
+corresponding permission `removeLabel-My-Name` with a range corresponding to
+the defined values. For these values, the users are permitted to remove
+other users' votes from a change.
+
+Change owners can always remove zero or positive votes (even without
+having the `Remove Vote` access right assigned).
+
+Project owners and site administrators can always remove any vote (even
+without having the `Remove Vote` access right assigned).
+
+Users without this access right can still remove their own votes.
+
[[category_remove_reviewer]]
=== Remove Reviewer
@@ -890,6 +906,9 @@
the Work In Progress bit of the change (even without having the
`Toggle Work In Progress state` access right assigned).
+Must be assigned on the target branch ref (i.e. on 'refs/heads/*', not on
+'refs/for/*').
+
[[category_delete_own_changes]]
=== Delete Own Changes
@@ -932,15 +951,6 @@
can always edit or remove hashtags (even without having the `Edit Hashtags`
access right assigned).
-[[category_edit_assigned_to]]
-=== Edit Assignee
-
-This category permits users to set who is assigned to a change that is
-uploaded for review.
-
-The change owner, ref owners, and the user currently assigned to a change
-can always change the assignee.
-
[[example_roles]]
== Examples of typical roles in a project
@@ -1143,7 +1153,7 @@
use 'BLOCK' rules to enforce site-wide restrictions.
For example, if a user in the 'Foo Users' group tries to push to
-'refs/heads/mater' with the permissions below, that user will be blocked
+'refs/heads/master' with the permissions below, that user will be blocked
[options="header"]
|=========================================================================
@@ -1351,10 +1361,11 @@
[[capability_createProject]]
=== Create Project
-Allow project creation. This capability allows the granted group to
-either link:cmd-create-project.html[create new git projects via ssh]
-or via the web UI.
+Allow project creation.
+This capability allows the granted group to create projects via the web UI, via
+link:rest-api-projects.html#create-project][REST] and via
+link:cmd-create-project.html[SSH].
[[capability_emailReviewers]]
=== Email Reviewers
@@ -1406,8 +1417,8 @@
Allow to link:cmd-set-account.html[modify accounts over the ssh prompt].
This capability allows the granted group members to modify any user account
-setting. In addition this capability is required to view secondary emails
-of other accounts.
+setting. In addition this capability allows to view secondary emails of other
+accounts.
[[capability_priority]]
=== Priority
@@ -1509,7 +1520,8 @@
This capability allows to view all accounts but not all account data.
E.g. secondary emails of all accounts can only be viewed with the
-link:#capability_modifyAccount[Modify Account] capability.
+link:#capability_viewSecondaryEmails[View Secondary Emails] capability
+or the link:#capability_modifyAccount[Modify Account] capability.
[[capability_viewCaches]]
@@ -1542,6 +1554,15 @@
link:cmd-show-queue.html[look at the Gerrit task queue via ssh].
+[[capability_viewSecondaryEmails]]
+=== View Secondary Emails
+
+Allows viewing secondary emails of other accounts.
+
+Users with the link:#capability_modifyAccount[Modify Account] capability have
+this capbility implicitly.
+
+
[[reference]]
== Permission evaluation reference
diff --git a/Documentation/cmd-create-project.txt b/Documentation/cmd-create-project.txt
index 358324d..87f3851 100644
--- a/Documentation/cmd-create-project.txt
+++ b/Documentation/cmd-create-project.txt
@@ -108,6 +108,7 @@
Action used by Gerrit to submit an approved change to its
destination branch. Supported options are:
+
+* INHERIT: inherits the submit-type from the parent project.
* FAST_FORWARD_ONLY: produces a strictly linear history.
* MERGE_IF_NECESSARY: create a merge commit when required.
* REBASE_IF_NECESSARY: rebase the commit when required.
@@ -116,7 +117,7 @@
* CHERRY_PICK: always cherry-pick the commit.
+
-Defaults to MERGE_IF_NECESSARY unless
+Defaults to INHERIT unless
link:config-gerrit.html#repository.name.defaultSubmitType[
repository.<name>.defaultSubmitType] is set to a different value.
For more details see link:config-project-config.html#submit-type[
diff --git a/Documentation/cmd-stream-events.txt b/Documentation/cmd-stream-events.txt
index 5fd0bfc..2456662 100644
--- a/Documentation/cmd-stream-events.txt
+++ b/Documentation/cmd-stream-events.txt
@@ -58,21 +58,6 @@
[[events]]
== EVENTS
-=== Assignee Changed
-
-Sent when the assignee of a change has been modified.
-
-type:: "assignee-changed"
-
-change:: link:json.html#change[change attribute]
-
-changer:: link:json.html#account[account attribute]
-
-oldAssignee:: Assignee before it was changed.
-
-eventCreatedOn:: Time in seconds since the UNIX epoch when this event was
-created.
-
=== Change Abandoned
Sent when a change has been abandoned.
diff --git a/Documentation/concept-changes.txt b/Documentation/concept-changes.txt
index 6e76a8a..323b32a 100644
--- a/Documentation/concept-changes.txt
+++ b/Documentation/concept-changes.txt
@@ -39,10 +39,6 @@
`git push` command, or the user that triggered the patch set creation through
an action in the UI).
-|Assignee
-|The contributor responsible for the change. Often used when a change has
-mulitple reviewers to identify the individual responsible for final approval.
-
|Reviewers
|A list of one or more contributors responsible for reviewing the change.
diff --git a/Documentation/config-accounts.txt b/Documentation/config-accounts.txt
index 716fa2f..f46c821 100644
--- a/Documentation/config-accounts.txt
+++ b/Documentation/config-accounts.txt
@@ -380,6 +380,14 @@
log in to Gerrit, then Gerrit will update the external ID record with
the new email address.
+=== Transition from LDAP to Google OAuth
+
+When authentication is changed from LDAP to Google Oauth gerrit will automatically
+adjust the external IDs in the `refs/meta/external-ids` branch. Gerrit will re-use
+the same account ID that was used by the LDAP account. Transition to other OAuth
+mechanisms will fail and require manual changes to the `refs/meta/external-ids` branch.
+The LDAP e-mail and Google OAuth e-mail must be the same.
+
[[starred-changes]]
== Starred Changes
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 6a25259..23455b2 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -562,7 +562,8 @@
+
To enable the actual usage of contributor agreement the project
specific config option in the `project.config` must be set:
-link:config-project-config.html[receive.requireContributorAgreement].
+link:config-project-config.html#receive.requireContributorAgreement[
+receive.requireContributorAgreement].
[[auth.trustContainerAuth]]auth.trustContainerAuth::
+
@@ -1429,20 +1430,6 @@
+
The default is false.
-[[change.enableAttentionSet]]change.enableAttentionSet::
-+
-If set to true, then all UI features for using and interacting with the
-attention set are enabled.
-+
-The default is true.
-
-[[change.enableAssignee]]change.enableAssignee::
-+
-If set to true, then all UI features for using and interacting with the
-assignee are enabled.
-+
-The default is false.
-
[[change.maxComments]]change.maxComments::
+
Maximum number of comments (regular plus robot) allowed per change. Additional
@@ -1551,6 +1538,13 @@
+
By default true.
+[[change.enableRobotComments]]change.enableRobotComments::
++
+Are robot comments enabled in the Gerrit UI? This setting allows phasing out
+robot comments.
++
+By default true.
+
[[change.robotCommentSizeLimit]]change.robotCommentSizeLimit::
+
Maximum allowed size in characters of a robot comment. Robot comments which
@@ -1756,9 +1750,7 @@
will match typical Gerrit Change-Id values and create a hyperlink
to changes which reference it. The second configuration 'bugzilla'
will hyperlink terms such as 'bug 42' to an external bug tracker,
-supplying the argument record number '42' for display. The third
-configuration 'tracker' uses raw HTML to more precisely control
-how the replacement is displayed to the user.
+supplying the argument record number '42' for display.
commentlinks supports link:#reloadConfig[configuration reloads]. Though a
link:cmd-flush-caches.html[flush-caches] of "projects" is needed for the
@@ -1775,16 +1767,10 @@
prefix = $1
suffix = $4
text = $2$3
-
-[commentlink "tracker"]
- match = ([Bb]ug:\\s+)(\\d+)
- html = $1<a href=\"http://trak.example.com/$2\">$2</a>
----
Comment links can also be specified in `project.config` and sections in
-children override those in parents. The only restriction is that to
-avoid injecting arbitrary user-supplied HTML in the page, comment links
-defined in `project.config` may only supply `link`, not `html`.
+children override those in parents.
[[commentlink.name.match]]commentlink.<name>.match::
+
@@ -1818,38 +1804,23 @@
+
The URL to direct the user to whenever the regular expression is
matched. Groups in the match expression may be accessed as `$'n'`.
-+
-The link property is used only when the html property is not present.
[[commentlink.name.prefix]]commentlink.<name>.prefix::
+
The text inserted before the link. Groups in the match expression may be
accessed as `$'n'`.
-+
-The link property is used only when the html property is not present.
[[commentlink.name.suffix]]commentlink.<name>.suffix::
+
The text inserted after the link. Groups in the match expression may be
accessed as `$'n'`.
-+
-The link property is used only when the html property is not present.
[[commentlink.name.text]]commentlink.<name>.text::
+
The text content of the link. Groups in the match expression may be
accessed as `$'n'`.
+
-The link property is used only when the html property is not present.
-
-[[commentlink.name.html]]commentlink.<name>.html::
-+
-HTML to replace the entire matched string with. If present,
-this property overrides the link property above. Groups in the
-match expression may be accessed as `$'n'`.
-+
-The configuration file eats double quotes, so escaping them as
-`\"` is necessary to protect them from the parser.
+If not specified defaults to `$&` (the matched text).
[[commentlink.name.enabled]]commentlink.<name>.enabled::
+
@@ -1857,11 +1828,6 @@
section in a parent or the site-wide config that is disabled by
specifying `enabled = true`.
+
-Disabling sections in `gerrit.config` can be used by site administrators
-to create a library of comment links with `html` set that are not
-user-supplied and thus can be verified to be XSS-free, but are only
-enabled for a subset of projects.
-+
By default, true.
+
Note that the names and contents of disabled sections are visible even
@@ -2116,6 +2082,16 @@
+
Default is 1 hour.
+[[core.usePerRequestRefCache]]core.usePerRequestRefCache::
++
+Use a per request (currently per request thread) ref cache. The ref
+cache uses JGit's SnapshottingRefDirectory to ensure that packed
+refs are checked and potentially read at least once per request
+(lazily) if needed. This helps reduce the overhead of checking if
+the packed-refs file is outdated.
++
+Default is true.
+
[[dashboard]]
=== Section dashboard
@@ -2815,6 +2791,39 @@
when this parameter is removed and the system group uses the default
name again.
+[[groups.relevantGroup]]groups.relevantGroup::
++
+UUID of an external group that should always be considered as relevant
+when checking whether an account is visible.
++
+This setting is only relevant for external group backends and only if
+the link:#accounts.visibility[account visibility] is set to
+`SAME_GROUP` or `VISIBLE_GROUP`.
++
+If the link:#accounts.visibility[account visibility] is set to
+`SAME_GROUP` or `VISIBLE_GROUP` users should see all accounts that are
+a member of a group that contains themselves or that is visible to
+them. Checking this would require getting all groups of the current
+user and all groups of the accounts for which the visibility is being
+checked, but since getting all groups that a user is a member of is
+expensive for external group backends Gerrit doesn't query these groups
+but instead guesses the relevant groups. Guessing relevant groups
+limits the inspected groups to all groups that are mentioned in the
+ACLs of the projects that are currently cached (i.e. all groups that
+are listed in the link:config-project-config.html#file-groups[groups]
+files of the cached projects). This is not very reliable since it
+depends on which groups are mentioned in the ACLs and which projects
+are currently cached. To make this more reliable this configuration
+parameter allows to configure external groups that should always be
+considered as relevant.
++
+As said this setting is only relevant for external group backends. In
+Gerrit core this is only the LDAP backend, but it may apply to further
+group backends that are added by plugins.
++
+This parameter may be added multiple times to specify multiple relevant
+groups.
+
[[has-operand-alias]]
=== Section has operand alias
@@ -4363,6 +4372,14 @@
+
Default is 5 seconds. Negative values will be converted to 0.
+[[plugins.transitionalPushOptions]]plugins.transitionalPushOptions::
++
+Additional push options which should be accepted by gerrit as valid
+options even if they are not registered by any plugin(e.g. "myplugin~foo").
++
+This config can be used when gerrit migrates from a deprecated plugin to the new one. The new plugin
+can (temporary) accept push options of the old plugin without registering such options.
+
[[receive]]
=== Section receive
diff --git a/Documentation/config-labels.txt b/Documentation/config-labels.txt
index e4eee10..ce63295 100644
--- a/Documentation/config-labels.txt
+++ b/Documentation/config-labels.txt
@@ -200,9 +200,9 @@
properties in the child project's configuration; all properties from
the parent definition must be redefined in the child.
-To remove a label in a child project, add an empty label with the same
-name as in the parent. This will override the parent label with
-a label containing the defaults (`function = MaxWithBlock`,
+To remove a label in a child project, add an empty label with a single "0"
+value, with the same name as in the parent. This will override the parent label
+with a label containing the defaults (`function = NoBlock`,
`defaultValue = 0` and no further allowed values)
[[label_layout]]
diff --git a/Documentation/config-mail.txt b/Documentation/config-mail.txt
index 8bd5dc7..4f11ca8 100644
--- a/Documentation/config-mail.txt
+++ b/Documentation/config-mail.txt
@@ -139,12 +139,6 @@
change being reverted. It is a `ChangeEmail`: see `ChangeSubject.soy` and
ChangeFooter.
-=== SetAssignee.soy and SetAssigneeHtml.soy
-
-The SetAssignee templates will determine the contents of the email related to a
-user being assigned to a change. It is a `ChangeEmail`: see `ChangeSubject.soy`
-and ChangeFooter.
-
== Mail Variables and Methods
diff --git a/Documentation/config-project-config.txt b/Documentation/config-project-config.txt
index 781b458..25fe9f3 100644
--- a/Documentation/config-project-config.txt
+++ b/Documentation/config-project-config.txt
@@ -458,11 +458,6 @@
NOTE: Rebasing merge commits is not supported. If a change with a merge commit
is submitted the link:#merge_if_necessary[merge if necessary] submit action is
applied.
-+
-When rebasing the patchset, Gerrit automatically appends onto the end of the
-commit message a short summary of the change's approvals, and a URL link back
-to the change in the web UI (see link:#submit-footers[below]). If a fast-forward
-is done no footers are added.
[[rebase_always]]
* 'rebase always':
@@ -737,6 +732,15 @@
the parent project. If the property is not set in any parent project, the
default value is `FALSE`.
+[[reviewer.skipAddingAuthorAndCommitterAsReviewers]]reviewer.skipAddingAuthorAndCommitterAsReviewers::
++
+Whether to skip adding the Git commit author and committer as reviewers for
+a new change.
++
+Default is `INHERIT`, which means that this property is inherited from
+the parent project. If the property is not set in any parent project, the
+default value is `FALSE`.
+
[[file-groups]]
== The file +groups+
diff --git a/Documentation/config-submit-requirements.txt b/Documentation/config-submit-requirements.txt
index 8298be3..fb12ff3 100644
--- a/Documentation/config-submit-requirements.txt
+++ b/Documentation/config-submit-requirements.txt
@@ -160,6 +160,22 @@
link:http://www.brics.dk/automaton/[dk.brics.automaton library,role=external,window=_blank]
is used for the evaluation of such patterns.
+[[operator_committeremail]]
+committeremail:'EMAIL_PATTERN'::
++
+An operator that returns true if the change committer's email address matches a
+specific regular expression pattern. The
+link:http://www.brics.dk/automaton/[dk.brics.automaton library,role=external,window=_blank]
+is used for the evaluation of such patterns.
+
+[[operator_uploaderemail]]
+uploaderemail:'EMAIL_PATTERN'::
++
+An operator that returns true if the change uploader's primary email address
+matches a specific regular expression pattern. The
+link:http://www.brics.dk/automaton/[dk.brics.automaton library,role=external,window=_blank]
+is used for the evaluation of such patterns.
+
[[operator_distinctvoters]]
distinctvoters:'[Label1,Label2,...,LabelN],value=MAX,count>1'::
+
@@ -187,11 +203,57 @@
redefine a submit requirement in a child project and make the submit requirement
always non-applicable.
+[[operator_has_submodule_update]]
+has:submodule-update::
++
+An operator that returns true if the diff of the latest patchset against the
+default parent has a submodule modified file, that is, a ".gitmodules" or a
+git link file.
++
+The optional `base` parameter can also be supplied for merge commits like
+`has:submodule-update,base=1`, or `has:submodule-update,base=2`. In these cases,
+the operator returns true if the diff of the latest patchset against parent
+number identified by `base` has a submodule modified file. Note that the
+operator will return false if the base parameter is greater than the number of
+parents for the latest patchset for the change.
+
[[operator_file]]
file:"'<filePattern>',withDiffContaining='<contentPattern>'"::
+
An operator that returns true if the latest patchset contained a modified file
matching `<filePattern>` with a modified region matching `<contentPattern>`.
++
+Both `<filePattern>` and `<contentPattern>` support regular expressions if they
+start with the '^' character. Regular expressions are matched with the
+`java.util.regex` engine. When using regular expressions, special characters
+should be double escaped because the config is parsed twice when the server
+reads the `project.config` file and when the submit-requirement expressions
+are parsed as a predicate tree. For example, to match against modified files
+that end with ".cc" or ".cpp" the following `applicableIf` expression can be
+used:
++
+----
+ applicableIf = file:\"^.*\\\\.(cc|cpp)$\"
+----
++
+Below is another example that uses both `<filePattern>` and `<contentPattern>`:
++
+----
+ applicableIf = file:\"'^.*\\\\.(cc|cpp)$',withDiffContaining='^.*th[rR]ee$'\"
+----
++
+If no regular expression is used, the text is matched by checking that the file
+name contains the file pattern, or the edits of the file diff contain the edit
+pattern.
+
+[[operator_label]]
+label:labelName=+1,user=non_contributor::
++
+Submit requirements support an additional `user=non_contributor` argument for
+labels that returns true if the change has a label vote matching the specified
+value and the vote is applied from a gerrit account that's not the uploader,
+author or committer of the latest patchset. See the documentation for the labels
+operator in the link:user-search.html[user search] page.
[[unsupported_operators]]
=== Unsupported Operators
@@ -268,6 +330,34 @@
canOverrideInChildProjects = true
----
+Branch configuration supports regular expressions as well, e.g. to exempt 'refs/heads/release/*' pattern,
+when migrating from the label Submit-Rule:
+
+----
+[label "Verified"]
+ branch = refs/heads/release/*
+----
+
+The following SR can be configured:
+
+----
+[submit-requirement "Verified"]
+ submittableIf = label:Verified=MAX AND -label:Verified=MIN
+ applicableIf = branch:^refs/heads/release/.*
+----
+
+[[require-footer-example]]
+=== Require a footer Example
+
+It's possible to use a submit requirement to require a footer to be present in
+the commit message.
+
+----
+[submit-requirement "Bug-Footer"]
+ description = Changes must include a 'Bug' footer
+ applicableIf = -branch:refs/meta/config AND -hasfooter:\"Bug\"
+ submittableIf = hasfooter:\"Bug\"
+----
[[test-submit-requirements]]
== Testing Submit Requirements
diff --git a/Documentation/config-validation.txt b/Documentation/config-validation.txt
index 56c9ecd..b0149fe 100644
--- a/Documentation/config-validation.txt
+++ b/Documentation/config-validation.txt
@@ -100,13 +100,6 @@
E.g. a plugin could use this to enforce a certain name scheme for
group names.
-[[assignee-validation]]
-== Assignee validation
-
-
-Plugins implementing the `AssigneeValidationListener` interface can perform
-validation of assignees before they are assigned to a change.
-
[[hashtag-validation]]
== Hashtag validation
diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt
index a2bd6fc..1c3fd78 100644
--- a/Documentation/dev-bazel.txt
+++ b/Documentation/dev-bazel.txt
@@ -365,7 +365,7 @@
----
Now attach with a debugger to the port `5005`. For example use "Remote Java Application" launch
-configuration in Eclipe and specify the port `5005`.
+configuration in Eclipse and specify the port `5005`.
[[logging]]
=== Controlling logging level
@@ -564,7 +564,7 @@
----
Update the `polygerrit-ui/app/node_modules_licenses/licenses.ts` file. You should add licenses
-for the package itself and for all transitive depndencies. If you forgot to add a license, the
+for the package itself and for all transitive dependencies. If you forgot to add a license, the
`Documentation:check_licenses` test will fail.
After the update, commit all changes to the repository (including `yarn.lock`).
diff --git a/Documentation/dev-crafting-changes.txt b/Documentation/dev-crafting-changes.txt
index ac0780d..6150c20 100644
--- a/Documentation/dev-crafting-changes.txt
+++ b/Documentation/dev-crafting-changes.txt
@@ -28,7 +28,7 @@
might take a while until you could benefit from it. In that case,
implement the feature on master and, if you really need it on an
earlier `stable-*` branch, cherry-pick the change and build
- Gerrit on your own environent.
+ Gerrit in your own environment.
* Bug-fixes should generally at least cover the oldest affected and
still supported version. If you're affected and run an even older
version, you're welcome to upload to that older version, even if
diff --git a/Documentation/dev-design.txt b/Documentation/dev-design.txt
index 5636dfd..176b53f 100644
--- a/Documentation/dev-design.txt
+++ b/Documentation/dev-design.txt
@@ -98,7 +98,7 @@
User authentication is handled by identity realms. Gerrit supports the
following types of authentication:
-* OpenId (see link:http://openid.net/developers/specs/[OpenID Specifications,role=external,window=_blank])
+* OpenID (see link:http://openid.net/developers/specs/[OpenID Specifications,role=external,window=_blank])
* OAuth2
* LDAP
* Google accounts (on googlesource.com)
@@ -373,7 +373,7 @@
and one for SSH).
The git wire protocol does a client/server negotiation to avoid
-sending too much data. This negotation occupies a CPU, so the number
+sending too much data. This negotiation occupies a CPU, so the number
of concurrent push/fetch operations should be capped by the number of
CPUs.
diff --git a/Documentation/dev-eclipse.txt b/Documentation/dev-eclipse.txt
index afd2825..f4238d1 100644
--- a/Documentation/dev-eclipse.txt
+++ b/Documentation/dev-eclipse.txt
@@ -61,9 +61,10 @@
startup --output_user_root=/Users/johndoe/.cache/bazel
----
-==== Increase the treshold for the cleanup of temporary files
-The default treshold for the cleanup can be overriden by creating a configuration file under
-`/etc/periodic.conf` and setting a larger value for the `daily_clean_tmps_days`.
+==== Increase the threshold for the cleanup of temporary files
+The default threshold for the cleanup can be overridden by creating a configuration
+file under `/etc/periodic.conf` and setting a larger value for the
+`daily_clean_tmps_days`.
An example `/etc/periodic.conf` file:
diff --git a/Documentation/dev-intellij.txt b/Documentation/dev-intellij.txt
index ab2082f..be4196c 100644
--- a/Documentation/dev-intellij.txt
+++ b/Documentation/dev-intellij.txt
@@ -31,13 +31,13 @@
=== Installation of IntelliJ IDEA
Please refer to the
-link:https://www.jetbrains.com/help/idea/installation-guide.html[installation guide provided by Jetbrains,role=external,window=_blank]
+link:https://www.jetbrains.com/help/idea/installation-guide.html[installation guide provided by JetBrains,role=external,window=_blank]
to install it on your platform. Make sure to install a version compatible with
the Bazel plugin as mentioned above.
== Installation of the Bazel plugin
-The plugin is usually installed using the Jetbrains plugin repository as shown
+The plugin is usually installed using the JetBrains plugin repository as shown
in the steps below, but it's also possible to
link:https://github.com/bazelbuild/intellij[build it from source].
diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt
index 11f85dd..3c4e9ea 100644
--- a/Documentation/dev-plugins.txt
+++ b/Documentation/dev-plugins.txt
@@ -533,6 +533,24 @@
Certain operations in Gerrit can be validated by plugins by
implementing the corresponding link:config-validation.html[listeners].
+[[taskListeners]]
+== WorkQueue.TaskListeners
+
+It is possible for plugins to listen to
+`com.google.gerrit.server.git.WorkQueue$Task`s directly before they run, and
+directly after they complete. This may be used to delay task executions based
+on custom criteria by blocking, likely on a lock or semaphore, inside
+onStart(), and a lock/semaphore release in onStop(). Plugins may listen to
+tasks by implementing a `com.google.gerrit.server.git.WorkQueue$TaskListener`
+and registering the new listener like this:
+
+[source,java]
+----
+bind(TaskListener.class)
+ .annotatedWith(Exports.named("MyListener"))
+ .to(MyListener.class);
+----
+
[[change-message-modifier]]
== Change Message Modifier
@@ -945,7 +963,7 @@
When calling command options not provided by your plugin, there is always
a risk that the options may not exist, perhaps because the options being
called are to be provided by another plugin, and said plugin is not
-currently installed. To protect againt this situation, it is possible to
+currently installed. To protect against this situation, it is possible to
define an option as being dependent on other options using the
@RequiresOptions() annotation. If the required options are not all not
currently present, then the dependent option will not be available or
@@ -981,7 +999,7 @@
@RequiresOptions("--format")
@Option(
name = "--special",
- usage = "ouptut results using json",
+ usage = "output results using json",
handler = JsonOutputOptionHandler.class
)
boolean json;
@@ -2191,7 +2209,6 @@
----
import com.google.gerrit.extensions.annotations.Listen;
import com.google.gerrit.extensions.webui.PatchSetWebLink;;
-import com.google.gerrit.extensions.webui.WebLinkTarget;
@Listen
public class MyWeblinkPlugin implements PatchSetWebLink {
@@ -2204,8 +2221,7 @@
String commitMessage, String branchName) {
return new WebLinkInfo(name,
imageUrl,
- String.format(placeHolderUrlProjectCommit, project, commit),
- WebLinkTarget.BLANK);
+ String.format(placeHolderUrlProjectCommit, project, commit));
}
}
----
@@ -2725,7 +2741,7 @@
Plugins are expected to support rules inheritance themselves, providing ways
to configure it and handling the logic behind it.
Please note that no inheritance is sometimes better than badly handled
-inheritance: mis-communication and strange behaviors caused by inheritance
+inheritance: miscommunication and strange behaviors caused by inheritance
may and will confuse the users. Each plugins is responsible for handling the
project hierarchy and taking wise actions. Gerrit does not enforce it.
diff --git a/Documentation/dev-readme.txt b/Documentation/dev-readme.txt
index 6ff064c..70f41af 100644
--- a/Documentation/dev-readme.txt
+++ b/Documentation/dev-readme.txt
@@ -178,7 +178,7 @@
NOTE: To learn why using `java -jar` isn't sufficient, see
<<special_bazel_java_version,this explanation>>.
-NOTE: When launching the daemong this way, the settings from the `[container]` section from the
+NOTE: When launching the daemon this way, the settings from the `[container]` section from the
`$GERRIT_SITE/etc/gerrit.config` are not honored.
To debug the Gerrit server of this test site:
diff --git a/Documentation/dev-release.txt b/Documentation/dev-release.txt
index 85337c2..85371100 100644
--- a/Documentation/dev-release.txt
+++ b/Documentation/dev-release.txt
@@ -368,6 +368,22 @@
Submit any previously uploaded notes change on the homepage project.
+[[update-supported-releases]]
+=== Update list of supported releases
+
+If you created a new stable release update the list of supported releases
+in the link:https://www.gerritcodereview.com/support.html[support page].
+
+Gerrit releases are also listed on the
+link:https://endoflife.date/gerrit[endoflife website].
+Push a PR to
+link:https://github.com/endoflife-date/endoflife.date.git[endoflife.date repository]
+to update supported releases in `products/gerrit.md`. New release tags
+should be updated automatically by the site's automation job which uses
+Dependabot to
+link:https://github.com/endoflife-date/endoflife.date/wiki/Automation[auto-create PRs]
+for new release tags.
+
[[announce]]
==== Announce on Mailing List
diff --git a/Documentation/images/browser-notification-example.png b/Documentation/images/browser-notification-example.png
new file mode 100644
index 0000000..2b60054
--- /dev/null
+++ b/Documentation/images/browser-notification-example.png
Binary files differ
diff --git a/Documentation/images/browser-notification-preference.png b/Documentation/images/browser-notification-preference.png
new file mode 100644
index 0000000..57d5fd6
--- /dev/null
+++ b/Documentation/images/browser-notification-preference.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-apply-fix.png b/Documentation/images/user-review-ui-apply-fix.png
new file mode 100644
index 0000000..d838d48
--- /dev/null
+++ b/Documentation/images/user-review-ui-apply-fix.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-metadata.png b/Documentation/images/user-review-ui-change-metadata.png
new file mode 100644
index 0000000..23abc07
--- /dev/null
+++ b/Documentation/images/user-review-ui-change-metadata.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-annotated.png b/Documentation/images/user-review-ui-change-screen-annotated.png
index 5c3f80a..4e12c96 100644
--- a/Documentation/images/user-review-ui-change-screen-annotated.png
+++ b/Documentation/images/user-review-ui-change-screen-annotated.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-change-info-labels.png b/Documentation/images/user-review-ui-change-screen-change-info-labels.png
deleted file mode 100644
index 61e2b25..0000000
--- a/Documentation/images/user-review-ui-change-screen-change-info-labels.png
+++ /dev/null
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-comments-tab.png b/Documentation/images/user-review-ui-change-screen-comments-tab.png
new file mode 100644
index 0000000..d522f60
--- /dev/null
+++ b/Documentation/images/user-review-ui-change-screen-comments-tab.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-file-list.png b/Documentation/images/user-review-ui-change-screen-file-list.png
index 721b229..b0c2af3 100644
--- a/Documentation/images/user-review-ui-change-screen-file-list.png
+++ b/Documentation/images/user-review-ui-change-screen-file-list.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-keyboard-shortcuts.png b/Documentation/images/user-review-ui-change-screen-keyboard-shortcuts.png
index 9ef8f27..224de2d 100644
--- a/Documentation/images/user-review-ui-change-screen-keyboard-shortcuts.png
+++ b/Documentation/images/user-review-ui-change-screen-keyboard-shortcuts.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-reply.png b/Documentation/images/user-review-ui-change-screen-reply.png
index 1c50fc5..201db13 100644
--- a/Documentation/images/user-review-ui-change-screen-reply.png
+++ b/Documentation/images/user-review-ui-change-screen-reply.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen-topleft.png b/Documentation/images/user-review-ui-change-screen-topleft.png
index a1f7813..b3bf8e7f 100644
--- a/Documentation/images/user-review-ui-change-screen-topleft.png
+++ b/Documentation/images/user-review-ui-change-screen-topleft.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-change-screen.png b/Documentation/images/user-review-ui-change-screen.png
index ff2570b..98a5d6d 100644
--- a/Documentation/images/user-review-ui-change-screen.png
+++ b/Documentation/images/user-review-ui-change-screen.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-copy-links.png b/Documentation/images/user-review-ui-copy-links.png
new file mode 100644
index 0000000..f8fa114
--- /dev/null
+++ b/Documentation/images/user-review-ui-copy-links.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-side-by-side-diff-screen-inline-comments.png b/Documentation/images/user-review-ui-side-by-side-diff-screen-inline-comments.png
index 047034c..98cf7af 100644
--- a/Documentation/images/user-review-ui-side-by-side-diff-screen-inline-comments.png
+++ b/Documentation/images/user-review-ui-side-by-side-diff-screen-inline-comments.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-side-by-side-diff-screen.png b/Documentation/images/user-review-ui-side-by-side-diff-screen.png
index 74d02e3..ebdd177 100644
--- a/Documentation/images/user-review-ui-side-by-side-diff-screen.png
+++ b/Documentation/images/user-review-ui-side-by-side-diff-screen.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-submit-requirements.png b/Documentation/images/user-review-ui-submit-requirements.png
new file mode 100644
index 0000000..e4b88c1
--- /dev/null
+++ b/Documentation/images/user-review-ui-submit-requirements.png
Binary files differ
diff --git a/Documentation/images/user-review-ui-suggest-fix.png b/Documentation/images/user-review-ui-suggest-fix.png
new file mode 100644
index 0000000..e08fb26
--- /dev/null
+++ b/Documentation/images/user-review-ui-suggest-fix.png
Binary files differ
diff --git a/Documentation/images/user-suggest-edits-preview.png b/Documentation/images/user-suggest-edits-preview.png
new file mode 100644
index 0000000..0a6af91
--- /dev/null
+++ b/Documentation/images/user-suggest-edits-preview.png
Binary files differ
diff --git a/Documentation/images/user-suggest-edits-reviewer-comment.png b/Documentation/images/user-suggest-edits-reviewer-comment.png
new file mode 100644
index 0000000..76fbac1
--- /dev/null
+++ b/Documentation/images/user-suggest-edits-reviewer-comment.png
Binary files differ
diff --git a/Documentation/images/user-suggest-edits-reviewer-preview.png b/Documentation/images/user-suggest-edits-reviewer-preview.png
new file mode 100644
index 0000000..5b3015e
--- /dev/null
+++ b/Documentation/images/user-suggest-edits-reviewer-preview.png
Binary files differ
diff --git a/Documentation/images/user-suggest-edits-reviewer-suggest-fix.png b/Documentation/images/user-suggest-edits-reviewer-suggest-fix.png
new file mode 100644
index 0000000..2ac28bd
--- /dev/null
+++ b/Documentation/images/user-suggest-edits-reviewer-suggest-fix.png
Binary files differ
diff --git a/Documentation/images/user-suggest-edits-suggestion.png b/Documentation/images/user-suggest-edits-suggestion.png
new file mode 100644
index 0000000..a9c6d9c
--- /dev/null
+++ b/Documentation/images/user-suggest-edits-suggestion.png
Binary files differ
diff --git a/Documentation/index.txt b/Documentation/index.txt
index e0ece47..5d4a29b 100644
--- a/Documentation/index.txt
+++ b/Documentation/index.txt
@@ -15,18 +15,21 @@
== Contributor Guides
. link:dev-community.html[Gerrit Community]
. link:dev-community.html#how-to-contribute[How to Contribute]
+.. link:dev-readme.html[Developer Setup]
== User Guides
. link:intro-user.html[User Guide]
. link:intro-project-owner.html[Project Owner Guide]
. link:https://source.android.com/source/developing[Default Android Workflow,role=external,window=_blank] (external)
-== Tutorials
+== Features and Workflows
. Web
-.. link:user-review-ui.html[Reviewing Changes]
+.. link:user-review-ui.html[Review UI Overview]
.. link:user-search.html[Searching Changes]
.. link:user-inline-edit.html[Manipulating Changes in Browser]
.. link:user-notify.html[Subscribing to Email Notifications]
+.. link:user-attention-set.html[Attention Set]
+.. link:user-suggest-edits.html[User Suggest Edits]
. SSH
.. link:user-upload.html#ssh[SSH connection details]
.. link:cmd-index.html[Command Line Tools]
@@ -49,9 +52,6 @@
. Multi-project management
.. link:user-submodules.html[Submodules]
.. link:https://source.android.com/source/using-repo.html[Repo,role=external,window=_blank] (external)
-. Prolog rules
-.. link:prolog-cookbook.html[Prolog Cookbook]
-.. link:prolog-change-facts.html[Prolog Facts for Gerrit Changes]
. link:intro-project-owner.html#project-deletion[Project deletion]
== Customization and Integration
diff --git a/Documentation/intro-user.txt b/Documentation/intro-user.txt
index 0f78e1f..4642247 100644
--- a/Documentation/intro-user.txt
+++ b/Documentation/intro-user.txt
@@ -1014,7 +1014,7 @@
inline comment ("Yeah, I see why, let me try again.").
[[security-fixes]]
--- Security Fixes
+== Security Fixes
If a security vulnerability is discovered you normally want to have an
embargo about it until fixed releases have been made available. This
diff --git a/Documentation/js_licenses.txt b/Documentation/js_licenses.txt
index ae3064c..c032c36 100644
--- a/Documentation/js_licenses.txt
+++ b/Documentation/js_licenses.txt
@@ -603,39 +603,6 @@
----
-[[codemirror-minified]]
-codemirror-minified
-
-* codemirror-minified
-
-[[codemirror-minified_license]]
-----
-The MIT License (MIT)
-
-Copyright (c) 2016 Marijn Haverbeke <marijnh@gmail.com> and others
-Copyright (c) 2016 Michael Zhou <zhoumotongxue008@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-----
-
-
[[font-roboto-local-fonts-roboto]]
font-roboto-local-fonts-roboto
@@ -1241,38 +1208,6 @@
----
-[[isarray]]
-isarray
-
-* isarray
-
-[[isarray_license]]
-----
-(MIT)
-
-Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>;
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-----
-
-
[[marked]]
marked
@@ -1330,7 +1265,7 @@
[[page]]
page
-* page
+* polygerrit-gr-page
[[page_license]]
----
@@ -1360,38 +1295,6 @@
----
-[[path-to-regexp]]
-path-to-regexp
-
-* path-to-regexp
-
-[[path-to-regexp_license]]
-----
-The MIT License (MIT)
-
-Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-----
-
-
[[resemblejs]]
resemblejs
diff --git a/Documentation/licenses.txt b/Documentation/licenses.txt
index 1706f13..2d5ab1d 100644
--- a/Documentation/licenses.txt
+++ b/Documentation/licenses.txt
@@ -3507,39 +3507,6 @@
----
-[[codemirror-minified]]
-codemirror-minified
-
-* codemirror-minified
-
-[[codemirror-minified_license]]
-----
-The MIT License (MIT)
-
-Copyright (c) 2016 Marijn Haverbeke <marijnh@gmail.com> and others
-Copyright (c) 2016 Michael Zhou <zhoumotongxue008@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-----
-
-
[[font-roboto-local-fonts-roboto]]
font-roboto-local-fonts-roboto
@@ -4145,38 +4112,6 @@
----
-[[isarray]]
-isarray
-
-* isarray
-
-[[isarray_license]]
-----
-(MIT)
-
-Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>;
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-----
-
-
[[marked]]
marked
@@ -4234,7 +4169,7 @@
[[page]]
page
-* page
+* polygerrit-gr-page
[[page_license]]
----
@@ -4264,38 +4199,6 @@
----
-[[path-to-regexp]]
-path-to-regexp
-
-* path-to-regexp
-
-[[path-to-regexp_license]]
-----
-The MIT License (MIT)
-
-Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-----
-
-
[[resemblejs]]
resemblejs
diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt
index 13a6354..8b21ca2 100644
--- a/Documentation/metrics.txt
+++ b/Documentation/metrics.txt
@@ -200,6 +200,19 @@
=== Change
+* `change/count_rebases`: Total number of rebases
+** `on_behalf_of_uploader`:
+ Whether the rebase was done on behalf of the uploader.
+ If the uploader does a rebase with '`on_behalf_of_uploader = true`', the flag
+ is ignored and a normal rebase is done, hence such rebases are recorded as
+ '`on_behalf_of_uploader` = false`'.
+** `rebase_chain`:
+ Whether a chain was rebased.
+** `allow_conflicts`:
+ Whether the rebase was done with allowing conflicts.
+* `change/submitted_with_rebaser_approval`: Number of rebased changes that were
+ submitted with a Code-Review approval of the rebaser that would not have been
+ submittable if the rebase was not done on behalf of the uploader.
* `change/submit_rule_evaluation`: Latency for evaluating submit rules on a
change.
* `change/submit_type_evaluation`: Latency for evaluating the submit type on a
diff --git a/Documentation/pg-plugin-checks-api.txt b/Documentation/pg-plugin-checks-api.txt
index 9864f18..968adcc 100644
--- a/Documentation/pg-plugin-checks-api.txt
+++ b/Documentation/pg-plugin-checks-api.txt
@@ -10,6 +10,10 @@
when a change page is loaded. Such a call would return a list of `Runs` and each
run can contain a list of `Results`.
+`Results` messages will render as markdown. It follows the
+[CommonMark](https://commonmark.org/help/) spec except inline images and direct
+HTML are not rendered and kept as plaintext.
+
The details of the ChecksApi are documented in the
link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/api/checks.ts[source code].
Note that this link points to the `master` branch and might thus reflect a
diff --git a/Documentation/pg-plugin-dev.txt b/Documentation/pg-plugin-dev.txt
index 61944b6..7c93cc0 100644
--- a/Documentation/pg-plugin-dev.txt
+++ b/Documentation/pg-plugin-dev.txt
@@ -125,20 +125,29 @@
See link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/styles/themes/[app-theme.ts]
for the list of available variables.
-Just add code like this to your JavaScript plugin:
+You can just create `<style>` elements yourself and add them to the
+`document.head`, but for your convenience the Plugin API provides a simple
+`styleApi().insertCSSRule()` method for doing just that. Typically you would
+define a CSS rule for `html`, which is always applied, or for a specific theme
+such as `html.lightTheme`.
``` js
Gerrit.install(plugin => {
- const styleEl = document.createElement('style');
- styleEl.innerHTML = `
- html {
- --header-background-color: #c3d9ff;
- }
- html.darkTheme {
- --header-background-color: #c3d9ff90;
- }
- `;
- document.head.appendChild(styleEl);
+ plugin.styleApi().insertCSSRule(`
+ html {
+ --header-text-color: black;
+ }
+ `);
+ plugin.styleApi().insertCSSRule(`
+ html.lightTheme {
+ --header-background-color: red;
+ }
+ `);
+ plugin.styleApi().insertCSSRule(`
+ html.darkTheme {
+ --header-background-color: blue;
+ }
+ `);
});
```
@@ -181,12 +190,6 @@
See link:pg-plugin-endpoints.html[endpoints].
-=== registerStyleModule
-`plugin.registerStyleModule(endpointName, moduleName)`
-
-This API is deprecated and will be removed either in version 3.6 or 3.7,
-see link:#low-level-style[above] for an alternative.
-
=== on
Register a JavaScript callback to be invoked when events occur within
the web interface. Signature
diff --git a/Documentation/pg-plugin-endpoints.txt b/Documentation/pg-plugin-endpoints.txt
index 8fe0833..0429f91 100644
--- a/Documentation/pg-plugin-endpoints.txt
+++ b/Documentation/pg-plugin-endpoints.txt
@@ -151,6 +151,10 @@
=== settings-screen
This endpoint is situated at the end of the body of the settings screen.
+=== profile
+This endpoint is situated at the top of the Profile section of the settings
+screen below the section description text.
+
=== reply-text
This endpoint wraps the textarea in the reply dialog.
diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt
index c083f28..6c77109 100644
--- a/Documentation/prolog-cookbook.txt
+++ b/Documentation/prolog-cookbook.txt
@@ -1,5 +1,12 @@
:linkattrs:
-= Gerrit Code Review - Prolog Submit Rules Cookbook
+= Gerrit Code Review - Prolog Submit Rules Cookbook (Deprecated)
+
+[WARNING]
+Prolog rules are no longer supported in Gerrit. Existing usages of prolog rules
+can be modified or deleted, but uploading new "rules.pl" files are rejected.
+Please use link:config-submit-requirements.html[submit requirements] instead.
+Note that the link:#SubmitType[Submit Type] being deprecated in this
+documentation page currently has no substitution in submit requirements.
[[SubmitRule]]
== Submit Rule
diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt
index 7e06e4a..7646777 100644
--- a/Documentation/rest-api-accounts.txt
+++ b/Documentation/rest-api-accounts.txt
@@ -2316,6 +2316,9 @@
link:access-control.html#capability_viewPlugins[View Plugins] capability.
|`viewQueue` |not set if `false`|Whether the user has the
link:access-control.html#capability_viewQueue[View Queue] capability.
+|`viewSecondaryEmails`|not set if `false`|Whether the user has the
+link:access-control.html#capability_viewSecondaryEmails[View Secondary
+Emails] capability.
|=================================
[[contributor-agreement-info]]
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index b9de6ab..92d4030 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -103,15 +103,17 @@
"id": "demo~master~Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
"project": "demo",
"branch": "master",
- "attention_set": [
- {
+ "attention_set": {
+ "1000096": {
"account": {
- "name": "John Doe"
+ "_account_id": 1000096,
+ "name": "John Doe",
+ "email": "john.doe@example.com"
},
- "last_update": "2012-07-17 07:19:27.766000000",
- "reason": "reviewer or cc replied"
+ "last_update": "2012-07-17 07:19:27.766000000",
+ "reason": "reviewer or cc replied"
}
- ]
+ },
"change_id": "Idaf5e098d70898b7119f6f4af5a6c13343d64b57",
"subject": "One change",
"status": "NEW",
@@ -552,15 +554,17 @@
"id": "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940",
"project": "myProject",
"branch": "master",
- "attention_set": [
- {
+ "attention_set": {
+ "1000096": {
"account": {
- "name": "John Doe"
+ "_account_id": 1000096,
+ "name": "John Doe",
+ "email": "john.doe@example.com"
},
- "last_update": "2013-02-21 11:16:36.775000000",
- "reason": "reviewer or cc replied"
+ "last_update": "2013-02-21 11:16:36.775000000",
+ "reason": "reviewer or cc replied"
}
- ]
+ },
"change_id": "I8473b95934b5732ac55d26311a706c9c2bde9940",
"subject": "Implementing Feature X",
"status": "NEW",
@@ -619,15 +623,17 @@
)]}'
{
"added": {
- "attention_set": [
- {
+ "attention_set": {
+ "1000096": {
"account": {
- "name": "John Doe"
+ "_account_id": 1000096,
+ "name": "John Doe",
+ "email": "john.doe@example.com"
},
- "last_update": "2013-02-21 11:16:36.775000000",
- "reason": "reviewer or cc replied"
+ "last_update": "2013-02-21 11:16:36.775000000",
+ "reason": "reviewer or cc replied"
}
- ]
+ },
"updated": "2013-02-21 11:16:36.775000000",
"topic": "new-topic"
},
@@ -658,15 +664,17 @@
"id": "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940",
"project": "myProject",
"branch": "master",
- "attention_set": [
- {
+ "attention_set": {
+ "1000096": {
"account": {
- "name": "John Doe"
+ "_account_id": 1000096,
+ "name": "John Doe",
+ "email": "john.doe@example.com"
},
- "last_update": "2013-02-21 11:16:36.775000000",
- "reason": "reviewer or cc replied"
+ "last_update": "2013-02-21 11:16:36.775000000",
+ "reason": "reviewer or cc replied"
}
- ],
+ },
"change_id": "I8473b95934b5732ac55d26311a706c9c2bde9940",
"subject": "Implementing Feature X",
"status": "NEW",
@@ -726,18 +734,18 @@
"id": "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940",
"project": "myProject",
"branch": "master",
- "attention_set": [
- {
+ "attention_set": {
+ "1000096": {
"account": {
"_account_id": 1000096,
"name": "John Doe",
"email": "john.doe@example.com",
"username": "jdoe"
},
- "last_update": "2013-02-21 11:16:36.775000000",
- "reason": "reviewer or cc replied"
+ "last_update": "2013-02-21 11:16:36.775000000",
+ "reason": "reviewer or cc replied"
}
- ]
+ },
"change_id": "I8473b95934b5732ac55d26311a706c9c2bde9940",
"subject": "Implementing Feature X",
"status": "NEW",
@@ -823,6 +831,26 @@
"+2"
]
},
+ "removable_labels": {
+ "Code-Review": {
+ "-1": [
+ {
+ "_account_id": 1000096,
+ "name": "John Doe",
+ "email": "john.doe@example.com",
+ "username": "jdoe"
+ }
+ ],
+ "+1": [
+ {
+ "_account_id": 1000097,
+ "name": "Jane Roe",
+ "email": "jane.roe@example.com",
+ "username": "jroe"
+ }
+ ]
+ }
+ },
"removable_reviewers": [
{
"_account_id": 1000096,
@@ -1104,154 +1132,6 @@
HTTP/1.1 204 No Content
----
-[[get-assignee]]
-=== Get Assignee
---
-'GET /changes/link:#change-id[\{change-id\}]/assignee'
---
-
-Retrieves the account of the user assigned to a change.
-
-.Request
-----
- GET /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/assignee HTTP/1.0
-----
-
-As a response an link:rest-api-accounts.html#account-info[AccountInfo] entity
-describing the assigned account is returned.
-
-.Response
-----
- HTTP/1.1 200 OK
- Content-Disposition: attachment
- Content-Type: application/json; charset=UTF-8
-
- )]}'
- {
- "_account_id": 1000096,
- "name": "John Doe",
- "email": "john.doe@example.com",
- "username": "jdoe"
- }
-----
-
-If the change has no assignee the response is "`204 No Content`".
-
-[[get-past-assignees]]
-=== Get Past Assignees
---
-'GET /changes/link:#change-id[\{change-id\}]/past_assignees'
---
-
-Returns a list of every user ever assigned to a change, in the order in which
-they were first assigned.
-
-.Request
-----
- GET /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/past_assignees HTTP/1.0
-----
-
-As a response a list of link:rest-api-accounts.html#account-info[AccountInfo]
-entities is returned.
-
-.Response
-----
- HTTP/1.1 200 OK
- Content-Disposition: attachment
- Content-Type: application/json; charset=UTF-8
-
- )]}'
- [
- {
- "_account_id": 1000051,
- "name": "Jane Doe",
- "email": "jane.doe@example.com",
- "username": "janed"
- },
- {
- "_account_id": 1000096,
- "name": "John Doe",
- "email": "john.doe@example.com",
- "username": "jdoe"
- }
- ]
-
-----
-
-
-[[set-assignee]]
-=== Set Assignee
---
-'PUT /changes/link:#change-id[\{change-id\}]/assignee'
---
-
-Sets the assignee of a change.
-
-The new assignee must be provided in the request body inside a
-link:#assignee-input[AssigneeInput] entity.
-
-.Request
-----
- PUT /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/assignee HTTP/1.0
- Content-Type: application/json; charset=UTF-8
-
- {
- "assignee": "jdoe"
- }
-----
-
-As a response an link:rest-api-accounts.html#account-info[AccountInfo] entity
-describing the assigned account is returned.
-
-.Response
-----
- HTTP/1.1 200 OK
- Content-Disposition: attachment
- Content-Type: application/json; charset=UTF-8
-
- )]}'
- {
- "_account_id": 1000096,
- "name": "John Doe",
- "email": "john.doe@example.com",
- "username": "jdoe"
- }
-----
-
-[[delete-assignee]]
-=== Delete Assignee
---
-'DELETE /changes/link:#change-id[\{change-id\}]/assignee'
---
-
-Deletes the assignee of a change.
-
-
-.Request
-----
- DELETE /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/assignee HTTP/1.0
-----
-
-As a response an link:rest-api-accounts.html#account-info[AccountInfo] entity
-describing the account of the deleted assignee is returned.
-
-.Response
-----
- HTTP/1.1 200 OK
- Content-Disposition: attachment
- Content-Type: application/json; charset=UTF-8
-
- )]}'
- {
- "_account_id": 1000096,
- "name": "John Doe",
- "email": "john.doe@example.com",
- "username": "jdoe"
- }
-----
-
-If the change had no assignee the response is "`204 No Content`".
-
[[get-pure-revert]]
=== Get Pure Revert
--
@@ -1512,6 +1392,250 @@
The change could not be rebased due to a path conflict during merge.
----
+Rebasing a change is allowed for the change owner, users with the
+link:access-control.html#category_rebase[Rebase] permission and users
+with the link:access-control.html#category_submit[Submit] permission.
+
+In addition, the rebaser or the original uploader, if rebasing is done
+on behalf of the uploader (see `rebase_on_behalf_of_uploader` option in
+link:#rebase-input[RebaseInput]), needs to have all permissions that
+are required to create the new patch set:
+
+* the link:access-control.html#category_push[Push] permission
+* the link:access-control.html#category_add_patch_set[Add Patch Set]
+ permission (only if the user is not the change owner)
+* the link:access-control.html#category_forge_author[Forge Author]
+ permission (only if the commit author is forged)
+* the link:access-control.html#category_forge_server[Forge Server]
+ permission (only if the commit author is the server identity)
+
+The same permissions were required for the upload of the original patch
+set. This means if the rebase is done on behalf of the uploader these
+permission checks should just pass, unless the uploader lost
+permissions after the upload of the original patch set. In this case
+rebasing on behalf of the uploader is not possible and a normal rebase
+(on behalf of the rebaser) must be done, which means that the rebaser
+becomes the uploader and takes over the change. If self approvals are
+disallowed, this means that the rebaser can no longer approve the
+change (as approvals of the uploader are ignored).
+
+[[rebase-chain]]
+=== Rebase Chain
+--
+'POST /changes/link:#change-id[\{change-id\}]/rebase:chain'
+--
+
+Rebases an ancestry chain of changes.
+
+The operated change is treated as the chain tip. All unsubmitted ancestors are rebased.
+
+Requires a linear ancestry relation (single parenting throughout the chain).
+
+Optionally, the parent revision (of the oldest ancestor to be rebased) can be changed to another
+change, revision or branch through the link:#rebase-input[RebaseInput] entity.
+
+If the chain is outdated, i.e., there's a change that depends on an old revision of its parent, the
+result is the same as individually rebasing all outdated changes on top of their parent's latest
+revision before running the rebase chain action.
+
+.Request
+----
+ POST /changes/myProject~master~I08a021fb07b83fe845140a2c11508b3bdd93b48f/rebase:chain HTTP/1.0
+ Content-Type: application/json;charset=UTF-8
+
+ {
+ "base" : "1234",
+ }
+----
+
+As response a link:#rebase-chain-info[RebaseChainInfo] entity is returned that
+describes the rebased changes. Information about the current patch sets
+are included.
+
+.Response
+----
+ HTTP/1.1 200 OK
+ Content-Disposition: attachment
+ Content-Type: application/json; charset=UTF-8
+
+ )]}'
+ {
+ "rebased_changes": [
+ {
+ "id": "myProject~master~I0e534de9d7f0d6f35b71f7d726acf835b2110c66",
+ "project": "myProject",
+ "branch": "master",
+ "hashtags": [
+
+ ],
+ "change_id": "I0e534de9d7f0d6f35b71f7d726acf835b2110c66",
+ "subject": "456",
+ "status": "NEW",
+ "created": "2022-11-21 20: 51: 31.000000000",
+ "updated": "2022-11-21 20: 56: 49.000000000",
+ "submit_type": "MERGE_IF_NECESSARY",
+ "insertions": 0,
+ "deletions": 0,
+ "total_comment_count": 0,
+ "unresolved_comment_count": 0,
+ "has_review_started": true,
+ "meta_rev_id": "a2a6692213f546e1045ecf4647439fac8d6d8faa",
+ "_number": 21,
+ "owner": {
+ "_account_id": 1000000
+ },
+ "current_revision": "c3b2ba222d42a56e05c90f88d4509a124620517d",
+ "revisions": {
+ "c3b2ba222d42a56e05c90f88d4509a124620517d": {
+ "kind": "NO_CHANGE",
+ "_number": 2,
+ "created": "2022-11-21 20: 56: 49.000000000",
+ "uploader": {
+ "_account_id": 1000000
+ },
+ "ref": "refs/changes/21/21/2",
+ "fetch": {
+
+ },
+ "commit": {
+ "parents": [
+ {
+ "commit": "7803f427dd7c4a2441466e4d740a1850dcee1af4",
+ "subject": "123"
+ }
+ ],
+ "author": {
+ "name": "Nitzan Gur-Furman",
+ "email": "nitzan@google.com",
+ "date": "2022-11-21 20: 49: 39.000000000",
+ "tz": 60
+ },
+ "committer": {
+ "name": "Administrator",
+ "email": "admin@example.com",
+ "date": "2022-11-21 20: 56: 49.000000000",
+ "tz": 60
+ },
+ "subject": "456",
+ "message": "456\n"
+ },
+ "description": "Rebase"
+ }
+ },
+ "requirements": [
+
+ ],
+ "submit_records": [
+ {
+ "rule_name": "gerrit~DefaultSubmitRule",
+ "status": "NOT_READY",
+ "labels": [
+ {
+ "label": "Code-Review",
+ "status": "NEED"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "id": "myProject~master~I08a021fb07b83fe845140a2c11508b3bdd93b48f",
+ "project": "myProject",
+ "branch": "master",
+ "hashtags": [
+
+ ],
+ "change_id": "I08a021fb07b83fe845140a2c11508b3bdd93b48f",
+ "subject": "789",
+ "status": "NEW",
+ "created": "2022-11-21 20: 51: 31.000000000",
+ "updated": "2022-11-21 20: 56: 49.000000000",
+ "submit_type": "MERGE_IF_NECESSARY",
+ "insertions": 0,
+ "deletions": 0,
+ "total_comment_count": 0,
+ "unresolved_comment_count": 0,
+ "has_review_started": true,
+ "meta_rev_id": "3bfb843fea471f96e16b9199c3a30fff0285bc45",
+ "_number": 22,
+ "owner": {
+ "_account_id": 1000000
+ },
+ "current_revision": "77eb17a9501a5c21963bc6af56085e60f281acbb",
+ "revisions": {
+ "77eb17a9501a5c21963bc6af56085e60f281acbb": {
+ "kind": "NO_CHANGE",
+ "_number": 2,
+ "created": "2022-11-21 20: 56: 49.000000000",
+ "uploader": {
+ "_account_id": 1000000
+ },
+ "ref": "refs/changes/22/22/2",
+ "fetch": {
+
+ },
+ "commit": {
+ "parents": [
+ {
+ "commit": "c3b2ba222d42a56e05c90f88d4509a124620517d",
+ "subject": "456"
+ }
+ ],
+ "author": {
+ "name": "Nitzan Gur-Furman",
+ "email": "nitzan@google.com",
+ "date": "2022-11-21 20: 51: 07.000000000",
+ "tz": 60
+ },
+ "committer": {
+ "name": "Administrator",
+ "email": "admin@example.com",
+ "date": "2022-11-21 20: 56: 49.000000000",
+ "tz": 60
+ },
+ "subject": "789",
+ "message": "789\n"
+ },
+ "description": "Rebase"
+ }
+ },
+ "requirements": [
+
+ ],
+ "submit_records": [
+ {
+ "rule_name": "gerrit~DefaultSubmitRule",
+ "status": "NOT_READY",
+ "labels": [
+ {
+ "label": "Code-Review",
+ "status": "NEED"
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ }
+----
+
+If the change cannot be rebased, e.g. due to conflicts, the response is
+"`409 Conflict`" and the error message is contained in the response
+body.
+
+.Response
+----
+ HTTP/1.1 409 Conflict
+ Content-Disposition: attachment
+ Content-Type: text/plain; charset=UTF-8
+
+ Change I0e534de9d7f0d6f35b71f7d726acf835b2110c66 could not be rebased due to a conflict during
+ merge.
+
+ merge conflict(s):
+ a.txt
+----
+
[[move-change]]
=== Move Change
--
@@ -2131,6 +2255,66 @@
HTTP/1.1 204 No Content
----
+[[apply-patch]]
+=== Create patch-set from patch
+--
+'POST /changes/link:#change-id[\{change-id\}]/patch:apply'
+--
+
+Creates a new patch set on a destination change from the provided patch.
+
+The patch must be provided in the request body, inside a
+link:#applypatchpatchset-input[ApplyPatchPatchSetInput] entity.
+
+If a base commit is given, the patch is applied on top of it. Otherwise, the
+patch is applied on top of the target change's original parent.
+
+Applying the patch will fail if the destination change is closed, or in case of any conflicts.
+
+.Request
+----
+ POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/patch:apply HTTP/1.0
+ Content-Type: application/json; charset=UTF-8
+
+ {
+ "patch": {
+ "patch": "new file mode 100644\n--- /dev/null\n+++ b/a_new_file.txt\n@@ -0,0 +1,2 @@ \
++Patch compatible `git diff` output \
++For example: `link:#get-patch[<gerrit patch>] | base64 -d | sed -z 's/\n/\\n/g'`"
+ }
+ }
+----
+
+As response a link:#change-info[ChangeInfo] entity is returned that
+describes the destination change after applying the patch.
+
+.Response
+----
+ HTTP/1.1 200 OK
+ Content-Disposition: attachment
+ Content-Type: application/json; charset=UTF-8
+
+ )]}'
+ {
+ "id": "myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9941",
+ "project": "myProject",
+ "branch": "release-branch",
+ "change_id": "I8473b95934b5732ac55d26311a706c9c2bde9941",
+ "subject": "Original change subject",
+ "status": "NEW",
+ "created": "2013-02-01 09:59:32.126000000",
+ "updated": "2013-02-21 11:16:36.775000000",
+ "mergeable": true,
+ "insertions": 12,
+ "deletions": 11,
+ "_number": 3965,
+ "owner": {
+ "name": "John Doe"
+ },
+ "current_revision": "184ebe53805e102605d11f6b143486d15c23a09c"
+ }
+----
+
[[get-included-in]]
=== Get Included In
--
@@ -2862,7 +3046,7 @@
'GET /changes/link:#change-id[\{change-id\}]/edit
--
-Retrieves a change edit details.
+Retrieves the details of the change edit done by the caller to the given change.
.Request
----
@@ -2934,12 +3118,19 @@
Content-Type: application/json; charset=UTF-8
{
- "binary_content": "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="
+ "binary_content": "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==",
+ "file_mode": 100755
}
----
Note that it must be base-64 encoded data uri.
+The "file_mode" field is optional, and if provided must be in octal format. The field
+indicates whether the file is executable or not and has a value of either 100755
+(executable) or 100644 (not executable). If it's unset, this indicates no change
+has been made. New files default to not being executable if this parameter is not
+provided
+
When change edit doesn't exist for this change yet it is created. When file
content isn't provided, it is wiped out for that file. As response
"`204 No Content`" is returned.
@@ -3642,6 +3833,10 @@
If another user removed a user's vote, the user with the deleted vote will be
added to the attention set.
+The request returns:
+ * '204 No Content' if the vote is deleted successfully;
+ * '404 Not Found' when the vote to be deleted is zero or not present.
+
.Request
----
DELETE /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/reviewers/John%20Doe/votes/Code-Review HTTP/1.0
@@ -6469,7 +6664,7 @@
* a commit ID ("674ac754f91e64a0efb8087e59a176484bd534d1")
* an abbreviated commit ID that uniquely identifies one revision of the
change ("674ac754"), at least 4 digits are required
-* a legacy numeric patch number ("1" for first patch set of the change)
+* a numeric patch number ("1" for first patch set of the change)
* "0" or the literal `edit` for a change edit
[[json-entities]]
@@ -6520,8 +6715,94 @@
If true the action is permitted at this time and the caller is
likely allowed to execute it. This may change if state is updated
at the server or permissions are modified. Not present if false.
+|`enabled_options` |optional|
+Optional list of enabled options. +
+See the list of suppported options link:#action-options[below].
|====================================
+[[action-options]]
+==== Action Options
+
+Options that are returned via the `enabled_options` field of
+link:#action-info[ActionInfo].
+
+[options="header",cols="1,^1,5"]
+|===================================
+|REST view |Option |Description
+|`rebase` |`rebase`|
+Present if the user can rebase the change. +
+This is the case for the change owner and users with the
+link:access-control.html#category_submit[Submit] or
+link:access-control.html#category_rebase[Rebase] permission if they
+have the link:access-control.html#category_push[Push] permission.
+|`rebase` |`rebase_on_behalf_of_uploader`|
+Present if the user can rebase the change on behalf of the uploader. +
+This is the case for the change owner and users with the
+link:access-control.html#category_submit[Submit] or
+link:access-control.html#category_rebase[Rebase] permission.
+|`rebase:chain`|`rebase`|
+Present if the user can rebase the chain. +
+This is the case if the calling user can rebase each change in the
+chain.
+Rebasing a change is allowed for the change owner and users with the
+link:access-control.html#category_submit[Submit] or
+link:access-control.html#category_rebase[Rebase] permission if they
+have the link:access-control.html#category_push[Push] permission.
+|`rebase:chain`|`rebase_on_behalf_of_uploader`|
+Present if the user can rebase the chain on behalf of the uploader. +
+This is the case if the calling user can rebase each change in the
+chain on behalf of the uploader.
+Rebasing a change on behalf of the uploader is allowed for the change
+owner and users with the link:access-control.html#category_submit[Submit]
+or link:access-control.html#category_rebase[Rebase] permission.
+|===================================
+
+For all other REST views no options are returned.
+
+[[applypatch-input]]
+=== ApplyPatchInput
+The `ApplyPatchInput` entity contains information about a patch to apply.
+
+A new commit will be created from the patch, and saved as a new patch set.
+
+[options="header",cols="1,^1,5"]
+|=================================
+|Field Name ||Description
+|`patch` |required|
+The patch to be applied. Must be compatible with `git diff` output.
+For example, link:#get-patch[Get Patch] output.
+The patch must be provided as UTF-8 text, either directly or base64-encoded.
+|=================================
+
+[[applypatchpatchset-input]]
+=== ApplyPatchPatchSetInput
+The `ApplyPatchPatchSetInput` entity contains information for creating a new patch set from a
+given patch.
+
+[options="header",cols="1,^1,5"]
+|=================================
+|Field Name ||Description
+|`patch` |required|
+The details of the patch to be applied as a link:#applypatch-input[ApplyPatchInput] entity.
+|`commit_message` |optional|
+The commit message for the new patch set. If not specified, the latest patch-set message will be
+used.
+|`base` |optional|
+40-hex digit SHA-1 of the commit which will be the parent commit of the newly created patch set.
+If set, it must be a merged commit or a change revision on the destination branch.
+Otherwise, the target change's branch tip will be used.
+|`author` |optional|
+The author of the commit to create. Must be an
+link:rest-api-accounts.html#account-input[AccountInput] entity with at least
+the `name` and `email` fields set.
+The caller needs "Forge Author" permission when using this field, unless specifies their own details.
+This field does not affect the owner of the change, which will continue to use the identity of the
+caller.
+|`response_format_options` |optional|
+List of link:#query-options[query options] to format the response.
+|=================================
+
+
[[approval-info]]
=== ApprovalInfo
The `ApprovalInfo` entity contains information about an approval from a
@@ -6555,18 +6836,6 @@
If true, this vote was made after the change was submitted.
|===========================
-[[assignee-input]]
-=== AssigneeInput
-The `AssigneeInput` entity contains the identity of the user to be set as assignee.
-
-[options="header",cols="1,^1,5"]
-|===========================
-|Field Name ||Description
-|`assignee` ||
-The link:rest-api-accounts.html#account-id[ID] of one account that
-should be added as assignee.
-|===========================
-
[[attention-set-info]]
=== AttentionSetInfo
The `AttentionSetInfo` entity contains details of users that are in
@@ -6675,9 +6944,6 @@
accounts that were in the attention set but were removed. The
link:#attention-set-info[AttentionSetInfo] is the latest and most recent removal
of the account from the attention set.
-|`assignee` |optional|
-The assignee of the change as an link:rest-api-accounts.html#account-info[
-AccountInfo] entity.
|`hashtags` |optional|
List of hashtags that are set on the change.
|`change_id` ||The Change-Id of the change.
@@ -6756,6 +7022,13 @@
A map of the permitted labels that maps a label name to the list of
values that are allowed for that label. +
Only set if link:#detailed-labels[detailed labels] are requested.
+|`removable_labels` |optional|
+A map of the removable labels that maps a label name to the map of
+values and reviewers (
+link:rest-api-accounts.html#account-info[AccountInfo] entities)
+that are allowed to be removed from the change. +
+Only set if link:#labels[labels] or
+link:#detailed-labels[detailed labels] are requested.
|`removable_reviewers`|optional|
The reviewers that can be removed by the calling user as a list of
link:rest-api-accounts.html#account-info[AccountInfo] entities. +
@@ -6874,11 +7147,16 @@
Whether the new change should be set to work in progress.
|`base_change` |optional|
A link:#change-id[\{change-id\}] that identifies the base change for a create
-change operation. Mutually exclusive with `base_commit`.
+change operation. +
+Mutually exclusive with `base_commit`. +
+If neither `base_commit` nor `base_change` are set, the target branch tip will
+be used as the parent commit.
|`base_commit` |optional|
A 40-digit hex SHA-1 of the commit which will be the parent commit of the newly
-created change. If set, it must be a merged commit on the destination branch.
-Mutually exclusive with `base_change`.
+created change. If set, it must be a merged commit on the destination branch. +
+Mutually exclusive with `base_change`. +
+If neither `base_commit` nor `base_change` are set, the target branch tip will
+be used as the parent commit.
|`new_branch` |optional, default to `false`|
Allow creating a new branch when set to `true`. Using this option is
only possible for non-merge commits (if the `merge` field is not set).
@@ -6895,10 +7173,12 @@
If set, the target branch (see `branch` field) must exist (it is not
possible to create it automatically by setting the `new_branch` field
to `true`.
+|`patch` |optional|
+The detail of a patch to be applied as an link:#applypatch-input[ApplyPatchInput] entity.
|`author` |optional|
-An link:rest-api-accounts.html#account-input[AccountInput] entity
-that will set the author of the commit to create. The author must be
-specified as name/email combination.
+The author of the commit to create. Must be an
+link:rest-api-accounts.html#account-input[AccountInput] entity with at least
+the `name` and `email` fields set.
The caller needs "Forge Author" permission when using this field.
This field does not affect the owner of the change, which will
continue to use the identity of the caller.
@@ -6911,6 +7191,8 @@
Additional information about whom to notify about the change creation
as a map of link:user-notify.html#recipient-types[recipient type] to
link:#notify-info[NotifyInfo] entity.
+|`response_format_options` |optional|
+List of link:#query-options[query options] to format the response.
|==================================
[[change-message-info]]
@@ -6929,7 +7211,7 @@
|`real_author` |optional|
Real author of the message as an
link:rest-api-accounts.html#account-info[AccountInfo] entity. +
-Set if the message was posted on behalf of another user.
+Only set if the message was posted on behalf of another user.
|`date` ||
The link:rest-api.html#timestamp[timestamp] this message was posted.
|`message` ||
@@ -7386,18 +7668,19 @@
[[diff-web-link-info]]
=== DiffWebLinkInfo
-The `DiffWebLinkInfo` entity describes a link on a diff screen to an
-external site.
+The `DiffWebLinkInfo` entity extends link:#web-link-info[WebLinkInfo] and
+describes a link on a diff screen to an external site.
-[options="header",cols="1,6"]
+[options="header",cols="1,^1,5"]
|=======================
-|Field Name|Description
-|`name` |The link name.
-|`url` |The link URL.
-|`image_url`|URL to the icon of the link.
-|show_on_side_by_side_diff_view|
+|Field Name||Description
+|`name` ||See link:#web-link-info[WebLinkInfo]
+|`tooltip` |optional|See link:#web-link-info[WebLinkInfo]
+|`url` ||See link:#web-link-info[WebLinkInfo]
+|`image_url`|optional|See link:#web-link-info[WebLinkInfo]
+|show_on_side_by_side_diff_view||
Whether the web link should be shown on the side-by-side diff screen.
-|show_on_unified_diff_view|
+|show_on_unified_diff_view||
Whether the web link should be shown on the unified diff screen.
|=======================
@@ -7488,8 +7771,13 @@
differ by one from details provided in <<diff-info,DiffInfo>>.
|`size_delta` ||
Number of bytes by which the file size increased/decreased.
-|`size` ||
-File size in bytes.
+|`size` || File size in bytes.
+|`old_mode` |optional|File mode in octal (e.g. 100644) at the old commit.
+The first three digits indicate the file type and the last three digits contain
+the file permission bits. For added files, this field will not be present.
+|`new_mode` |optional|File mode in octal (e.g. 100644) at the new commit.
+The first three digits indicate the file type and the last three digits contain
+the file permission bits. For deleted files, this field will not be present.
|=============================
[[fix-input]]
@@ -7731,11 +8019,11 @@
The detail of the source commit for merge as a link:#merge-input[MergeInput]
entity.
|`author` |optional|
-An link:rest-api-accounts.html#account-input[AccountInput] entity
-that will set the author of the commit to create. The author must be
-specified as name/email combination.
+The author of the commit to create. Must be an
+link:rest-api-accounts.html#account-input[AccountInput] entity with at least
+the `name` and `email` fields set.
The caller needs "Forge Author" permission when using this field.
-This field does not affect the owner of the change, which will
+This field does not affect the owner or the committer of the change, which will
continue to use the identity of the caller.
|==================================
@@ -7865,22 +8153,32 @@
The `RebaseInput` entity contains information for changing parent when rebasing.
[options="header",cols="1,^1,5"]
-|===========================
-|Field Name ||Description
-|`base` |optional|
+|====================================
+|Field Name ||Description
+|`base` |optional|
The new parent revision. This can be a ref or a SHA-1 to a concrete patchset. +
Alternatively, a change number can be specified, in which case the current
patch set is inferred. +
Empty string is used for rebasing directly on top of the target branch,
which effectively breaks dependency towards a parent change.
-|`allow_conflicts` |optional, defaults to false|
+|`allow_conflicts` |optional, defaults to false|
If `true`, the rebase also succeeds if there are conflicts. +
If there are conflicts the file contents of the rebased patch set contain
git conflict markers to indicate the conflicts. +
Callers can find out whether there were conflicts by checking the
`contains_git_conflicts` field in the returned link:#change-info[ChangeInfo]. +
-If there are conflicts the change is marked as work-in-progress.
-|`validation_options`|optional|
+If there are conflicts the change is marked as work-in-progress. +
+Cannot be combined with the `on_behalf_of_uploader` option.
+|`on_behalf_of_uploader`|optional, defaults to false|
+If `true`, the rebase is done on behalf of the uploader. +
+This means the uploader of the current patch set will also be the uploader of
+the rebased patch set. The calling user will be recorded as the real user. +
+Rebasing on behalf of the uploader is only supported for trivial rebases.
+This means this option cannot be combined with the `allow_conflicts` option. +
+In addition, rebasing on behalf of the uploader is only supported for the
+current patch set of a change. +
+If the caller is the uploader this flag is ignored and a normal rebase is done.
+|`validation_options` |optional|
Map with key-value pairs that are forwarded as options to the commit validation
listeners (e.g. can be used to skip certain validations). Which validation
options are supported depends on the installed commit validation listeners.
@@ -7888,6 +8186,22 @@
listeners that are implemented in plugins may. Please refer to the
documentation of the installed plugins to learn whether they support validation
options. Unknown validation options are silently ignored.
+|====================================
+
+[[rebase-chain-info]]
+=== RebaseChainInfo
+
+The `RebaseChainInfo` entity contains information about a chain of changes
+that were rebased.
+
+[options="header",cols="1,^1,5"]
+|===========================
+|Field Name ||Description
+|`rebased_changes` ||List of the unsubmitted ancestors, as link:#change-info[ChangeInfo]
+entities. Includes both rebased changes, and previously up-to-date ancestors. The list is ordered by
+ancestry, where the oldest ancestor is the first.
+|`contains_git_conflicts` ||Whether any of the rebased changes has conflicts
+due to rebasing.
|===========================
[[related-change-and-commit-info]]
@@ -7982,7 +8296,9 @@
Topic can't contain quotation marks.
|`work_in_progress` |optional|
When present, change is marked as Work In Progress. The `notify` input is
-used if it's present, otherwise it will be overridden to `OWNER`. +
+used if it's present, otherwise it will be overridden to `NONE`. +
+Notifications for the reverted change will only sent once the result change is
+no longer WIP. +
If not set, the default is false.
|`validation_options`|optional|
Map with key-value pairs that are forwarded as options to the commit validation
@@ -8251,6 +8567,10 @@
|`uploader` ||
The uploader of the patch set as an
link:rest-api-accounts.html#account-info[AccountInfo] entity.
+|`real_uploader`|optional|
+The real uploader of the patch set as an
+link:rest-api-accounts.html#account-info[AccountInfo] entity. +
+Only set if the upload was done on behalf of another user.
|`ref` ||The Git reference for the patch set.
|`fetch` ||
Information about how to fetch this patch set. The fetch information is
@@ -8380,7 +8700,13 @@
Notify handling that defines to whom email notifications should be sent after
the change is submitted. +
Allowed values are `NONE`, `OWNER`, `OWNER_REVIEWERS` and `ALL`. +
-If not set, the default is `ALL`.
+If not set, the default is `ALL`.+
+Ignored if a post approval diff is present (i.e. if the change is submitted
+with copied approvals), because in this case everyone should be informed
+about the non-reviewed diff which has been applied after the change has been
+approved so that they can take action if the post approval diff looks
+unexpected. In other words if a post approval diff is present `ALL` is
+enforced.
|`notify_details`|optional|
Additional information about whom to notify about the update as a map
of link:user-notify.html#recipient-types[recipient type] to
@@ -8635,15 +8961,23 @@
[[web-link-info]]
=== WebLinkInfo
-The `WebLinkInfo` entity describes a link to an external site.
+The `WebLinkInfo` entity describes a link to an external site. Depending on the
+context and the provided data the UI may decide to show the link as a text link,
+a linkified icon, or both.
+
+If the `tooltip` is not provided, then the UI may fall back to showing something
+like "Open in External Tool".
+
+Weblinks will always be opened in a new tab.
[options="header",cols="1,^1,5"]
|========================
|Field Name ||Description
-|`name` ||The link name.
+|`name` ||The text to be linkified.
+|`tooltip` |optional|Tooltip to show when hovering over the link. Using "Open
+in $NAME_OF_EXTERNAL_TOOL" is a good option here.
|`url` ||The link URL.
|`image_url`|optional|URL to the icon of the link.
-|`target` |optional|The target window in which the web link should be opened.
|========================
[[work-in-progress-input]]
diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt
index 45de1b1..fe9b13c 100644
--- a/Documentation/rest-api-config.txt
+++ b/Documentation/rest-api-config.txt
@@ -1575,10 +1575,8 @@
configuration parameter] that controls whether the mergeability bit in
link:rest-api-changes.html#change-info[ChangeInfo] will never be set and if the
bit is indexed.
-|`enable_attention_set` |defaults to `false`|
-Returns true if attention set UI features are enabled.
-|`enable_assignee` |defaults to `true`|
-Returns true if assignee related UI features are enabled.
+|`enable_robot_comments`|not set if `false`|
+link:config-gerrit.html#change.enableRobotComments[Are robot comments enabled?].
|`conflicts_predicate_enabled`|not set if `false`|
link:config-gerrit.html#change.conflictsPredicateEnabled[Are conflicts enabled?].
|=============================
diff --git a/Documentation/rest-api-projects.txt b/Documentation/rest-api-projects.txt
index 578fe75..675c054 100644
--- a/Documentation/rest-api-projects.txt
+++ b/Documentation/rest-api-projects.txt
@@ -3817,13 +3817,13 @@
|`enabled` |optional|Whether the commentlink is enabled, as documented
in link:config-gerrit.html#commentlink.name.enabled[
commentlink.name.enabled]. If not set the commentlink is enabled.
+|==================================================
[[commentlink-input]]
=== CommentLinkInput
The `CommentLinkInput` entity describes the input for a
link:config-gerrit.html#commentlink[commentlink].
-|==================================================
[options="header",cols="1,^2,4"]
|==================================================
|Field Name | |Description
@@ -3909,17 +3909,19 @@
Map with the comment link configurations of the project. The name of
the comment link configuration is mapped to a link:#commentlink-info[
CommentlinkInfo] entity.
-|`plugin_config` |optional|
+|`plugin_config` |optional|
Plugin configuration as map which maps the plugin name to a map of
parameter names to link:#config-parameter-info[ConfigParameterInfo]
entities. Only filled for users who have read access to `refs/meta/config`.
-|`actions` |optional|
+|`actions` |optional|
Actions the caller might be able to perform on this project. The
information is a map of view names to
-|`reject_empty_commit` |optional|
+|`reject_empty_commit` |optional|
link:#inherited-boolean-info[InheritedBooleanInfo] that tells whether
empty commits should be rejected when a change is merged.
link:rest-api-changes.html#action-info[ActionInfo] entities.
+|`skip_adding_author_and_committer_as_reviewers` |optional|
+Whether to skip adding the Git commit author and committer as reviewers for a new change.
|=======================================================
[[config-input]]
diff --git a/Documentation/rest-api.txt b/Documentation/rest-api.txt
index 469bee5..348af76 100644
--- a/Documentation/rest-api.txt
+++ b/Documentation/rest-api.txt
@@ -76,6 +76,16 @@
headers. If the named resource already exists the server will respond
with HTTP 412 Precondition Failed.
+[[backwards-compatibility]]
+=== Backwards Compatibility
+
+The REST API is regularly extended (e.g. addition of new REST endpoints or new fields in existing
+JSON entities). Callers of the REST API must be able to deal with this (e.g. ignore unknown fields
+in the REST responses). Incompatible changes (e.g. removal of REST endpoints, altering/removal of
+existing fields in JSON entities) are avoided if possible, but can happen in rare cases. If they
+happen, they are announced in the link:https://www.gerritcodereview.com/releases-readme.html[release
+notes].
+
[[output]]
=== Output Format
JSON responses are encoded using UTF-8 and use content type
diff --git a/Documentation/user-attention-set.txt b/Documentation/user-attention-set.txt
index 5dc1416..4fe5aae 100644
--- a/Documentation/user-attention-set.txt
+++ b/Documentation/user-attention-set.txt
@@ -131,6 +131,27 @@
Gerrit-Attention: Marian Harbach <mharbach@google.com>
----
+=== Browser notifications
+
+You'll automatically get notifications when you are in the attention set. You
+must enable desktop notifications on your browser to see them.
+
+image::images/browser-notification-example.png["browser notification example", align="center"]
+
+You can turn off automatic notifications in user preferences. They are enabled
+by default.
+
+image::images/browser-notification-preference.png["user preference for browser notifications", align="center"]
+
+The notifications work only when Gerrit is open in one of the browser tabs.
+The latency to get the notification is up to 5 minutes.
+
+If you are not getting notifications:
+ - Check your user preferences - Allow browser notification setting
+ - Make sure notifications are turned on for the Gerrit site in the browser
+ - Make sure browser notifications are turned on in your operating system
+ - Your host can have browser notifications disabled for some user groups
+
=== Bold Changes / Mark Reviewed
Before the attention set feature, changes were bolded in the dashboard when
@@ -140,13 +161,7 @@
=== For Gerrit Admins
-The Attention Set has been available since the 3.3 release (late 2020). It
-is enabled by default, but you can disable it by setting
-link:config-gerrit.html#change.enableAttentionSet[enableAttentionSet] to false.
-
-As part of Gerrit 3.3 upgrade, the user group "Non-Interactive Users" is
-renamed "Service Users". For a new installation, the group is automatically
-created upon initialization.
+The Attention Set has been available since the 3.3 release (late 2020).
=== Important note for all host owners, project owners, and bot owners
diff --git a/Documentation/user-inline-edit.txt b/Documentation/user-inline-edit.txt
index 4a9d18f..7ed87b6 100644
--- a/Documentation/user-inline-edit.txt
+++ b/Documentation/user-inline-edit.txt
@@ -15,6 +15,9 @@
[[create-change]]
== Creating a Change
+[[create_in_web_interface]]
+=== In the web interface
+
To create a change in the Gerrit web interface:
. From the link:http://gerrit-review.googlesource.com[Gerrit Code Review,role=external,window=_blank]
@@ -64,6 +67,22 @@
. Add the files you want to be reviewed.
+[[create_from_url]]
+=== From URL
+
+Gerrit supports creating a new change and opening a specific file for edit
+in that change from an "Edit URL":
+```
+^\/admin\/repos\/edit\/repo\/(.+)\/branch\/(.+)\/file\/(.+)$
+```
+This enables other tools to provide a direct link to edit their configuration
+files in Gerrit.
+
+Ex:
+```
+https://gerrit.mycompany.com/admin/repos/edit/repo/my/repo/branch/refs/heads/master/file/Jenkinsfile # Jenkins build file
+https://gerrit.mycompany.com/admin/repos/edit/repo/my/repo/branch/refs/heads/master/file/catalog-info.yaml # Backstage catalog-info
+```
[[add-files]]
== Adding a File to a Change
@@ -173,7 +192,7 @@
[[search-for-changes]]
== Searching for Changes with Pending Edits
-To find changes with pending edits:
+To find changes with pending edits created by you:
* From the Gerrit dashboard, select Your > Changes. All your changes are
listed, according to Work in progress, Outgoing reviews, Incoming reviews,
@@ -183,6 +202,12 @@
link:user-search.html[Searching Changes]. For example, to find only
those changes that contain edits, see link:user-search.html#has[has:edit].
+[NOTE]
+Though edits created by others are not accessible from the Gerrit UI, edits
+are not considered to be private data, and are stored in non-encrypted special
+branches under the target repository. As such, they can be accessed by users who
+have access to the repository.
+
[[change-edit-actions]]
== Modifying Changes
diff --git a/Documentation/user-notify.txt b/Documentation/user-notify.txt
index de5ea57..f420fe7 100644
--- a/Documentation/user-notify.txt
+++ b/Documentation/user-notify.txt
@@ -181,7 +181,6 @@
* newpatchset
* restore
* revert
-* setassignee
[[Gerrit-Change-Id]]Gerrit-Change-Id::
diff --git a/Documentation/user-review-ui.txt b/Documentation/user-review-ui.txt
index 6f5f7297..39929e1 100644
--- a/Documentation/user-review-ui.txt
+++ b/Documentation/user-review-ui.txt
@@ -1,21 +1,15 @@
:linkattrs:
-= Review UI
+= Review UI Overview
Reviewing changes is an important task and the Gerrit Web UI provides
many functionalities to make the review process comfortable and
efficient.
-The UI has three different main views,
-
-** The dashboard, which shows all changes that are relevant to you
-** The change screen, which shows the change with all its metadata
-** The diff view, which shows changes to a single file
-
[[change-screen]]
== Change Screen
-The change screen shows the details of a single change and provides
-various actions on it.
+The change screen is the main view for a change. It shows the details of a
+single change and allows various actions on it.
image::images/user-review-ui-change-screen.png[width=800, link="images/user-review-ui-change-screen.png"]
@@ -28,44 +22,81 @@
Top left, you find the status of the change, and a permalink.
-image::images/user-review-ui-change-screen-topleft.png[width=400, link="images/user-review-ui-change-screen-topleft.png"]
+image::images/user-review-ui-change-screen-topleft.png[width=600, link="images/user-review-ui-change-screen-topleft.png"]
[[change-status]]
The change status shows the state of the change:
-- [[active]]`Active`:
+- `Active`:
+
The change is under active review.
-- [[merge-conflict]]`Merge Conflict`:
+- `Merge Conflict`:
+
-The change can't be merged due to conflicts.
+The change can't be merged into the destination branch due to conflicts.
-- [[ready-to-submit]]`Ready to Submit`:
+- `Ready to Submit`:
+
-The change has all necessary approvals and may be submitted.
+The change has all necessary approvals and fulfils all other submit
+requirements. It can be submitted.
-- [[merged]]`Merged`:
+- `Merged`:
+
The change was successfully merged into the destination branch.
-- [[abandoned]]`Abandoned`:
+- `Abandoned`:
+
-The change was abandoned.
+The change was abandoned. It is not intended to be updated, reviewed or
+submitted anymore.
+
+- `Private`:
++
+The change is marked as link:intro-user.html#private-changes[Private]. And has
+reduced visibility.
+
+- `Revert Created|Revert Submitted`:
++
+The change has a corresponding revert change. Revert changes can be created
+through UI (see <<actions, Actions section>>).
+
+- `WIP`:
++
+The change was marked as "Work in Progress". For example to indicate to
+reviewers that they shouldn't review the change yet.
[[star]]
=== Star Change
-Clicking the star icon marks the change as a favorite: it turns on
+Clicking the star icon bookmarks the change: it turns on
email notifications for this change, and the change is added to the
list under `Your` > `Starred Changes`. They can be queried by the
link:user-search.html#is[is:starred] search operator.
+[[quick-links]]
+=== Links Menu
+
+Links menu contains various change related strings for quick copying. Such as:
+Change Number, URL, Title+Url, etc. The lines in this menu can also be accessed
+via shortcuts for convenience.
+
+image::images/user-review-ui-copy-links.png[width=600, link="images/user-review-ui-copy-links.png"]
+
[[change-info]]
=== Change metadata
-The change metadata block contains detailed information about the change
-and offers actions on the change.
+The change metadata block contains detailed information about the change.
+
+image::images/user-review-ui-change-metadata.png[width=600, link="images/user-review-ui-change-metadata.png"]
+
+- [[owner]]Owner/Uploader/Author/Committer:
++
+Owner is the person who created the change
++
+Uploader is the person who uploaded the latest patchset (the patchset that will
+be merged if the change is submitted)
++
+Author/Committer are concepts from Git and are retrieved from the commit when
+it's sent for review.
- [[reviewers]]Reviewers:
+
@@ -74,16 +105,36 @@
For each reviewer there is a tooltip that shows on which labels the
reviewer is allowed to vote.
+
-New reviewers can be added by clicking on the pencil icon. Typing
-into the pop-up text field activates auto completion of user and group
-names.
+New reviewers can be added through reply dialog that is opened by clicking on
+the pencil icon or on "Reply" button. Typing into the reviewer text field
+activates auto completion of user and group names.
+
+
+- [[cc-list]]CC:
++
+Accounts in CC receive notifications for the updates on the change, but don't
+need to vote/review. If the CC'ed user votes they are moved to reviewers.
++
+
+- [[attention-set]]link:user-attention-set.html[Attention set]:
++
+Users in attention set are marked by "chevron" symbol (see screenshot above).
+The mark indicates that there are actions their attention is required on the
+change: Something updated/changed since last review, their vote is required,
+etc.
++
+Changes for which you are currently in attention set can be found using
+`attention:<User>` in search and show up in a separate category of personal
+dashboard.
++
+Clicking on the mark removes the user from attention set.
+
+
[[remove-reviewer]]
-Reviewers can be removed from the change by clicking on the `x` icon
-in the reviewer's chip token. Removing a reviewer also removes the
-current votes of the reviewer. The removal of votes is recorded as a
-message on the change.
-+
+Reviewers can be removed from the change by selecting the appropriate option on
+the chip's hovercard. Removing a reviewer also removes current votes of the
+reviewer. The removal of votes is recorded in the change log.
+
Removing reviewers is protected by permissions:
** Users can always remove themselves.
@@ -92,10 +143,7 @@
Remove Reviewer] access right, the branch owner, the project owner
and Gerrit administrators may remove anyone.
-+
-image::images/user-review-ui-change-screen-info-reviewers.png[width=600, link="images/user-review-ui-change-screen-reviewers.png"]
-
-- [[project-branch-topic]]Project / Branch / Topic:
+- [[repo-branch-topic]]Project (Repo) / Branch / Topic:
+
The name of the project for which the change was done is displayed as a
link to the link:user-dashboards.html#project-default-dashboard[default
@@ -112,15 +160,55 @@
access right. To be able to set a topic on a closed change, the
`Edit Topic Name` must be assigned with the `force` flag.
+- [[parent]]Parent:
++
+Parent commit of the latest uploaded patchset. Or if the change has been merged
+the parent of the commit it was merged as into the destination branch.
+
+- [[merged-as]]Merged As:
++
+The SHA of the commit corresponding to the merged change on the destination
+branch.
+
+- [[revert-created-as]]Revert (Created|Submitted) As:
++
+Points to the revert change, if one was created.
+
+- [[cherry-pick-of]]Cherry-pick of:
++
+If the change was created as cherry-pick of some other change to a different
+branch, points to the original change.
+
- [[submit-strategy]]Submit Strategy:
+
The link:project-setup.html#submit_type[submit strategy] that will be
used to submit the change. The submit strategy is only displayed for
open changes.
-- [[actions]]Actions:
+- [[hastags]]Hashtags:
+
-Actions buttons are at the top, and in the overflow menu.
+Arbitrary string hashtags, that can be used to categorize changes and later use
+hashtags for search queries.
+
+[[submit-requirements]]
+=== Submit Requirements
+
+image::images/user-review-ui-submit-requirements.png[width=600, link="images/user-review-ui-copy-links.png"]
+
+Submit Requirements describe various conditions that must be fulfilled before
+the change can be submitted. Hovering over the requirement will show the
+description of the requirement, as well as additional information, such as:
+corresponding expression that is being evaluated, who can vote on the related
+labels etc.
+
+Approving votes are colored green; negative votes are colored red.
+
+For more detail on Submit Requirements see
+link:config-submit-requirements.html[Submit Requirement Configuration] page.
+
+[[actions]]
+=== Actions
+Actions buttons are at the top right and in the overflow menu.
Depending on the change state and the permissions of the user, different
actions are available on the change:
@@ -220,13 +308,7 @@
+
image::images/user-review-ui-change-screen-change-info-actions.png[width=400, link="images/user-review-ui-change-screen-change-info-actions.png"]
-- [[labels]]Labels & Votes:
-+
-Approving votes are colored green; negative votes are colored red.
-+
-image::images/user-review-ui-change-screen-change-info-labels.png[width=400, link="images/user-review-ui-change-screen-change-info-labels.png"]
-
-[[files]]
+[[files-tab]]
=== File List
The file list shows the files that are modified in the currently viewed
@@ -251,17 +333,40 @@
The list of commits that are being integrated into the destination
branch by submitting the merge commit.
+Every file is accompanied by a number of extra information, such as status
+(modified, added, deleted, etc.), number of changed lines, type (executable,
+link, plain), comments and others. Hovering over most icons and columns reveals
+additional information.
+
+Each file can be expanded to view the contents of the file and diff. For more
+information see <<diff-view, Diff View>> section.
+
+[[comments-tab]]
+=== Comments Tab
+
+Instead of the file list, a comments tab can be selected. Comments tab presents
+comments along with related file/diff snippets. It also offers some filtering
+opportunities at the top (ex. only unresolved, only comments from user X, etc.)
+
+image::images/user-review-ui-change-screen-comments-tab.png[width=800, link="images/user-review-ui-change-screen-comments-tab.png"]
+
+[[checks-tab]]
+=== Checks Tab
+Checks tab contains results of different "Check Runs" installed by plugins. For
+more information see link:pg-plugin-checks-api.html[Checks API] page.
[[patch-sets]]
=== Patch Sets
-The change screen only presents one patch set at a time. Which patch
-set is currently viewed can be seen from the `Patch Sets` drop-down
-panel in the change header.
+The change screen only presents one pair of patch sets (`Patchset A` and
+`Patchset B`) at a time. `A` is always an earlier upload than `B` and serves as
+a base for diffing when viewing changes in the files. Which patch
+sets is currently viewed can be seen from the `Patch Sets` drop-down
+panel in the change header. If patchset 'A' is not selected a parent commit of
+patchset 'B' is used by default.
image::images/user-review-ui-change-screen-patch-sets.png[width=300, link="images/user-review-ui-change-screen-patch-sets.png"]
-
[[download]]
=== Download
@@ -278,7 +383,8 @@
Each command has a copy-to-clipboard icon that allows the command to be
copied into the clipboard. This makes it easy to paste and execute the
-command on a Git command line.
+command on a Git command line. Additionally each line can copied to clipboard
+using number (1..9) of the appropriate line as a keyboard shortcut.
If several download schemes are configured on the server (e.g. SSH and
HTTP) there is a drop-down list to switch between the download schemes.
@@ -306,22 +412,20 @@
image::images/user-review-ui-change-screen-included-in.png[width=800, link="images/user-review-ui-change-screen-included-in.png"]
-
-
[[related-changes]]
=== Related Changes
If there are changes that are related to the currently viewed change
they are displayed in the third column of the change screen.
-There are several lists of related changes and a tab control is used to
-display each list of related changes in its own tab.
+There are several lists of related changes that are displayed in separate
+sectionsunder each other.
-The following tabs may be displayed:
+The following sections may be displayed:
-- [[related-changes-tab]]`Related Changes`:
+- [[related-changes-section]]`Related Changes`:
+
-This tab page shows changes on which the current change depends
+This section shows changes on which the current change depends
(ancestors) and open changes that depend on the current change
(descendants). For merge commits it also shows the closed changes that
will be merged into the destination branch by submitting the merge
@@ -341,10 +445,10 @@
+
** [[not-current]]Not current:
+
-The selected patch set of the change is outdated; it is not the current
-patch set of the change.
+The patch set of the related change which is related to the current change is
+outdated; it is not the current patch set of the change.
+
-It means that the
+For ancestor it means that the
currently viewed patch set depends on a outdated patch set of the
ancestor change. This is because a new patch set for the ancestor
change was uploaded in the meantime and as result the currently viewed
@@ -364,20 +468,24 @@
note that following the link to an indirect descendant change may
result in a completely different related changes listing.
-** [[closed-ancestor]]Closed ancestor:
+** [[merged-related-change]]Merged
+
-Indicates a closed ancestor, e.g. the commit was directly pushed into
-the repository bypassing code review, or the ancestor change was
-reviewed and submitted on another branch. The latter may indicate that
-the user has accidentally pushed the commit to the wrong branch, e.g.
-the commit was done on `branch-a`, but was then pushed to
-`refs/for/branch-b`.
+The change has been merged.
++
+If the relationship to submitted change falls under conditions described in
+<<not-current, Not current>> the status is orange. Such changes can appear as
+both ancestors and descendants of the change.
+
+** [[submittable-related-change]]Submittable
++
+All the submit requirements are fulfilled for the related change and it can be
+submitted when all of its ancestors are submitted.
** [[closed-ancestor-abandoned]]Abandoned:
+
Indicates an abandoned change.
-- [[conflicts-with]]`Conflicts With`:
+- [[conflicts-with]]`Merge Conflicts`:
+
This section shows changes that conflict with the current change.
Non-mergeable changes are filtered out; only conflicting changes that
@@ -393,10 +501,9 @@
currently viewed change, when clicking the submit button. It includes
ancestors of the current patch set.
+
-This may include changes and its ancestors with the same topic if
-`change.submitWholeTopic` is enabled. Only open changes with the
-same topic are included in the list.
-+
+If `change.submitWholeTopic` is enabled this section also includes changes with
+the same topic. The list recursively includes all changes that can be reached by
+ancestor and topic relationships. Only open changes are included in the result.
- [[cherry-picks]]`Cherry-Picks`:
+
@@ -411,12 +518,18 @@
If there are no related changes for a tab, the tab is not displayed.
+- [[same-topic]]`Same Topic`:
++
+This section shows changes which are part of the same topic. If
+`change.submitWholeTopic` is enabled, then this section is omitted and changes
+are included as part of <<submitted-together, `Submitted Together`>>
+
[[reply]]
=== Reply
The `Reply...` button in the change header allows to reply to the
currently viewed patch set; one can add a summary comment, publish
-inline draft comments, and vote on the labels.
+inline draft comments, vote on the labels and adjust attention set.
image::images/user-review-ui-change-screen-reply.png[width=800, link="images/user-review-ui-change-screen-reply.png"]
@@ -424,10 +537,8 @@
[[summary-comment]]
A text box allows to type a summary comment for the currently viewed
-patch set. Some basic markdown-like syntax is supported which renders
-indented lines preformatted, lines starting with "- " or "* " as list
-items, and lines starting with "> " as block quotes (also see replying to
-link:#reply-to-message[messages] and link:#reply-inline-comment[inline comments]).
+patch set. Markdown syntax is supported same as in other
+<<comments-markdown, Comments>>.
[[vote]]
If the current patch set is viewed, buttons are displayed for
@@ -439,7 +550,7 @@
are links to navigate to the inline comments which can be used if a
comment needs to be edited.
-The `Post` button publishes the comments and the votes.
+The `SEND` button publishes the comments and the votes.
[[quick-approve]]
If a user can approve a label that is still required, a quick approve
@@ -460,12 +571,12 @@
image::images/user-review-ui-change-screen-quick-approve.png[width=800, link="images/user-review-ui-change-screen-quick-approve.png"]
-[[history]]
-=== History
+[[change-log]]
+=== Change Log
The history of the change can be seen in the lower part of the screen.
-The history contains messages for all kinds of change updates, e.g. a
+The log contains messages for all kinds of change updates, e.g. a
message is added when a new patch set is uploaded or when a review was
done.
@@ -491,12 +602,12 @@
image::images/user-review-ui-change-screen-plugin-extensions.png[width=300, link="images/user-review-ui-change-screen-plugin-extensions.png"]
-[[side-by-side]]
+[[diff-view]]
== Side-by-Side Diff Screen
-The side-by-side diff screen shows a single patch; the old file version
-is displayed on the left side of the screen; the new file version is
-displayed on the right side of the screen.
+The side-by-side diff screen shows a single patch (or difference between two
+patchsets); the old file version is displayed on the left side of the screen;
+the new file version is displayed on the right side of the screen.
This screen allows to review a patch and to comment on it.
@@ -557,6 +668,10 @@
Code blocks with comments may overlap. This means it is possible to
attach several comments to the same code.
+[[comments-markdown]]
+The comments support markdown. It follows the CommonMark spec, except inline
+images and direct HTML are not rendered and kept as plaintext.
+
[[line-links]]
The lines of the patch file are linkable: simply append
'#<linenumber>' to the URL, or click on the line-number. This not only
@@ -565,15 +680,14 @@
[[reply-inline-comment]]
Clicking on the `Reply` button opens an editor to type the reply.
-Quoting is supported, but only by manually copying & pasting the old
-comment that should be quoted and prefixing every line by "> ". Please
-note that for a correct rendering it is important to leave a blank line
-between a quoted block and the reply to it.
+Previous comment can be quoted using "Quote" button. A new draft would be open
+on the same comment thread with the text of the previoused comment quoted using
+markdown syntax.
image::images/user-review-ui-side-by-side-diff-screen-inline-comments.png[width=800, link="images/user-review-ui-side-by-side-diff-screen-inline-comments.png"]
Comments are first saved as drafts, and you can revisit the drafts as
-you read through code review. Finally, they should be published by
+you read through code review. Finally, they will be published by
clicking the "Reply".
[[done]]
@@ -610,6 +724,21 @@
make it visible to other users it must be published from the change
screen by link:#reply[replying] to the change.
+[[suggest-fix]]
+=== Suggest fix (WIP)
+Comments can contain suggested fixes.
+
+Clicking "Suggest Fix" will insert a special code-block in the text of the
+comment. The contents of this code block will replace the lines the comment is
+attached to (what gets highlighted when hovering over comment).
+
+image::images/user-review-ui-suggest-fix.png[width=400, link="images/user-review-ui-suggest-fix.png"]
+
+The author of the change can then preview and apply the change. This will created
+a new patchset with changes applied.
+
+image::images/user-review-ui-apply-fix.png[width=800, link="images/user-review-ui-apply-fix.png"]
+
[[file-level-comments]]
=== File Level Comments
diff --git a/Documentation/user-search-accounts.txt b/Documentation/user-search-accounts.txt
index 6bcd18e..d5318c9 100644
--- a/Documentation/user-search-accounts.txt
+++ b/Documentation/user-search-accounts.txt
@@ -26,7 +26,10 @@
[[cansee]]
cansee:'CHANGE'::
+
-Matches accounts that can see the change 'CHANGE'.
+Matches accounts that can see the change 'CHANGE'. If the change is private,
+this operator will match with the owner/reviewers/ccs of the change if the
+caller is in owner/reviewers/ccs of the change. Otherwise, the request will fail
+with 404 `Bad Request` with "change not found" message.
[[email]]
email:'EMAIL'::
diff --git a/Documentation/user-search.txt b/Documentation/user-search.txt
index d09717de..67b8d75 100644
--- a/Documentation/user-search.txt
+++ b/Documentation/user-search.txt
@@ -43,6 +43,17 @@
For more predictable results, use explicit search operators as described
in the following section.
+[IMPORTANT]
+--
+The change search API is backed by a secondary index and might sometimes return
+stale results if the re-indexing operation failed for a change update.
+
+Please also note that changes are not re-indexed if the project configuration
+is updated with newly added or modified
+link:config-submit-requirements.html[submit requirements].
+--
+
+
[[search-operators]]
== Search Operators
@@ -74,11 +85,6 @@
means 'everything older than 2 days' while `-age:2d` means
'everything with an age of at most 2 days'.
-[[assignee]]
-assignee:'USER'::
-+
-Changes assigned to the given user.
-
[[attention]]
attention:'USER'::
+
@@ -345,6 +351,18 @@
regular expressions is limited to the first 32766 bytes of the
commit message due to limitations in Lucene.
+[[subject]]
+subject:'SUBJECT'::
++
+Changes that have a commit message where the first line (aka the subject)
+matches 'SUBJECT'. The matching is done by full text search over the subject.
+
+[[prefixsubject]]
+prefixsubject:'PREFIX'::
++
+Changes that have a commit message where the first line (aka the subject)
+has the prefix 'PREFIX'.
+
[[comment]]
comment:'TEXT'::
+
@@ -359,6 +377,10 @@
The link:http://www.brics.dk/automaton/[dk.brics.automaton library,role=external,window=_blank]
is used for the evaluation of such patterns.
+
+Note that the Gerrit host may not support regular expression search.
+You will then see an error dialog when using expressions starting with
+`^`.
++
The `^` required at the beginning of the regular expression not only
denotes a regular expression, but it also has the usual meaning of
anchoring the match to the start of the string. To match all Java
@@ -460,20 +482,12 @@
[[is]]
-is:assigned::
-+
-True if the change has an assignee.
-
[[is-starred]]
is:starred::
+
Same as 'has:star', true if the change has been starred by the
current user with the default label.
-is:unassigned::
-+
-True if the change does not have an assignee.
-
is:attention::
+
True if the change has attention by the current user.
@@ -618,7 +632,7 @@
+
Changes containing a top-level or inline comment by 'USER'. The special
case of `commentby:self` will find changes where the caller has
-commented.
+commented. Note that setting a vote is also considered as a comment.
[[from]]
from:'USER'::
@@ -633,7 +647,7 @@
last update (comment or patch set) from the change owner.
[[author]]
-author:'AUTHOR'::
+author:'AUTHOR', a:'AUTHOR'::
+
Changes where 'AUTHOR' is the author of the current patch set. 'AUTHOR' may be
the author's exact email address, or part of the name or email address. The
diff --git a/Documentation/user-suggest-edits.txt b/Documentation/user-suggest-edits.txt
new file mode 100644
index 0000000..99f17a4
--- /dev/null
+++ b/Documentation/user-suggest-edits.txt
@@ -0,0 +1,37 @@
+= Gerrit Code Review - User suggested edits (Experiment)
+
+Easy and fast way for reviewers to suggest code changes that can be easily applied
+by change owner.
+
+== Reviewer workflow
+
+** Select line or multiple lines of diff and start comment
+
+image::images/user-suggest-edits-reviewer-comment.png["Comment example", align="center", width=400]
+
+** Click on suggest fix - that copies whole selected line/lines
+
+image::images/user-suggest-edits-reviewer-suggest-fix.png["Comment example", align="center", width=400]
+
+** Modify lines in the suggestion block. Optionally add more details as normal comment text before or after
+the suggestion block.
+
+image::images/user-suggest-edits-suggestion.png["Suggestion example", align="center", width=400]
+
+** Optionally you can preview suggested edit by clicking on Preview fix when you stop editing comment
+
+image::images/user-suggest-edits-reviewer-preview.png["Suggestion Draft example", align="center", width=400]
+
+image::images/user-suggest-edits-preview.png["Suggestion Preview", align="center", width=400]
+
+== Author workflow
+
+You can apply one or more suggested fixes. When suggested fix is applied - it creates
+a change edit that you can modify. link:user-inline-edit.html#editing-change[More about editing mode.]
+
+GERRIT
+------
+Part of link:index.html[Gerrit Code Review]
+
+SEARCHBOX
+---------
diff --git a/Documentation/user-upload.txt b/Documentation/user-upload.txt
index 8c51207..c6fce2a5 100644
--- a/Documentation/user-upload.txt
+++ b/Documentation/user-upload.txt
@@ -1,13 +1,15 @@
:linkattrs:
= Gerrit Code Review - Uploading Changes
-Gerrit supports three methods of uploading changes:
+Gerrit supports five methods of uploading changes:
* Use `repo upload`, to create changes for review
* Use `git push`, to create changes for review
+* link:user-inline-edit.html#create_in_web_interface[Create a change for review from the web interface]
+* link:user-inline-edit.html#create_from_url[Create a change for review by using an "Edit URL"]
* Use `git push`, and bypass code review
-All three methods rely on authentication, which must first be configured
+All five methods rely on authentication, which must first be configured
by the uploading user.
Gerrit supports two protocols for uploading changes; SSH and HTTP/HTTPS. These
diff --git a/README.md b/README.md
index 4df9271..c8f0b70 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
[Gerrit](https://www.gerritcodereview.com) is a code review and project
management tool for Git based projects.
-[![Build Status](https://gerrit-ci.gerritforge.com/job/Gerrit-bazel-java11-master/badge/icon)](https://gerrit-ci.gerritforge.com/job/Gerrit-bazel-java11-master/)
+[![Build Status](https://gerrit-ci.gerritforge.com/view/Gerrit/job/Gerrit-bazel-master/badge/icon)](https://gerrit-ci.gerritforge.com/view/Gerrit/job/Gerrit-bazel-master/)
![Maven Central](https://img.shields.io/maven-central/v/com.google.gerrit/gerrit-war)
## Objective
diff --git a/WORKSPACE b/WORKSPACE
index cf399dc..047da6a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -65,8 +65,8 @@
http_archive(
name = "build_bazel_rules_nodejs",
- sha256 = "0fad45a9bda7dc1990c47b002fd64f55041ea751fafc00cd34efb96107675778",
- urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.0/rules_nodejs-5.5.0.tar.gz"],
+ sha256 = "c29944ba9b0b430aadcaf3bf2570fece6fc5ebfb76df145c6cdad40d65c20811",
+ urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.7.0/rules_nodejs-5.7.0.tar.gz"],
)
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
@@ -136,8 +136,8 @@
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
node_repositories(
- node_version = "16.15.0",
- yarn_version = "1.22.18",
+ node_version = "17.9.1",
+ yarn_version = "1.22.19",
)
yarn_install(
diff --git a/contrib/git-gc-preserve b/contrib/git-gc-preserve
new file mode 100755
index 0000000..33c8f5b
--- /dev/null
+++ b/contrib/git-gc-preserve
@@ -0,0 +1,149 @@
+#!/bin/bash
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+usage() { # exit code
+ cat <<-EOF
+NAME
+ git-gc-preserve - Run git gc and preserve old packs to avoid races for JGit
+
+SYNOPSIS
+ git gc-preserve
+
+DESCRIPTION
+ Runs git gc and can preserve old packs to avoid races with concurrently
+ executed commands in JGit.
+
+ This command uses custom git config options to configure if preserved packs
+ from the last run of git gc should be pruned and if packs should be preserved.
+
+ This is similar to the implementation in JGit [1] which is used by
+ JGit to avoid errors [2] in such situations.
+
+ The command prevents concurrent runs of the command on the same repository
+ by acquiring an exclusive file lock on the file
+ "\$repopath/gc-preserve.pid"
+ If it cannot acquire the lock it fails immediately with exit code 3.
+
+ Failure Exit Codes
+ 1: General failure
+ 2: Couldn't determine repository path. If the current working directory
+ is outside of the working tree of the git repository use git option
+ --git-dir to pass the root path of the repository.
+ E.g.
+ $ git --git-dir ~/git/foo gc-preserve
+ 3: Another process already runs $0 on the same repository
+
+ [1] https://git.eclipse.org/r/c/jgit/jgit/+/87969
+ [2] https://git.eclipse.org/r/c/jgit/jgit/+/122288
+
+CONFIGURATION
+ "pack.prunepreserved": if set to "true" preserved packs from the last gc run
+ are pruned before current packs are preserved.
+
+ "pack.preserveoldpacks": if set to "true" current packs will be hard linked
+ to objects/pack/preserved before git gc is executed. JGit will
+ fallback to the preserved packs in this directory in case it comes
+ across missing objects which might be caused by a concurrent run of
+ git gc.
+EOF
+ exit "$1"
+}
+
+# acquire file lock, unlock when the script exits
+lock() { # repo
+ readonly LOCKFILE="$1/gc-preserve.pid"
+ test -f "$LOCKFILE" || touch "$LOCKFILE"
+ exec 9> "$LOCKFILE"
+ if flock -nx 9; then
+ echo -n "$$ $USERNAME@$HOSTNAME" >&9
+ trap unlock EXIT
+ else
+ echo "$0 is already running"
+ exit 3
+ fi
+}
+
+unlock() {
+ # only delete if the file descriptor 9 is open
+ if { : >&9 ; } &> /dev/null; then
+ rm -f "$LOCKFILE"
+ fi
+ # close the file handle to release file lock
+ exec 9>&-
+}
+
+# prune preserved packs if pack.prunepreserved == true
+prune_preserved() { # repo
+ configured=$(git --git-dir="$1" config --get pack.prunepreserved)
+ if [ "$configured" != "true" ]; then
+ return 0
+ fi
+ local preserved=$1/objects/pack/preserved
+ if [ -d "$preserved" ]; then
+ printf "Pruning old preserved packs: "
+ count=$(find "$preserved" -name "*.old-pack" | wc -l)
+ rm -rf "$preserved"
+ echo "$count, done."
+ fi
+}
+
+# preserve packs if pack.preserveoldpacks == true
+preserve_packs() { # repo
+ configured=$(git --git-dir="$1" config --get pack.preserveoldpacks)
+ if [ "$configured" != "true" ]; then
+ return 0
+ fi
+ local packdir=$1/objects/pack
+ pushd "$packdir" >/dev/null || exit 1
+ mkdir -p preserved
+ printf "Preserving packs: "
+ count=0
+ for file in pack-*{.pack,.idx} ; do
+ ln -f "$file" preserved/"$(get_preserved_packfile_name "$file")"
+ if [[ "$file" == pack-*.pack ]]; then
+ ((count++))
+ fi
+ done
+ echo "$count, done."
+ popd >/dev/null || exit 1
+}
+
+# pack-0...2.pack to pack-0...2.old-pack
+# pack-0...2.idx to pack-0...2.old-idx
+get_preserved_packfile_name() { # packfile > preserved_packfile
+ local old=${1/%\.pack/.old-pack}
+ old=${old/%\.idx/.old-idx}
+ echo "$old"
+}
+
+# main
+
+while [ $# -gt 0 ] ; do
+ case "$1" in
+ -u|-h) usage 0 ;;
+ esac
+ shift
+done
+args=$(git rev-parse --sq-quote "$@")
+
+repopath=$(git rev-parse --git-dir)
+if [ -z "$repopath" ]; then
+ usage 2
+fi
+
+lock "$repopath"
+prune_preserved "$repopath"
+preserve_packs "$repopath"
+git gc ${args:+"$args"} || { echo "git gc failed"; exit "$?"; }
diff --git a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
index 01c4942..f4e7cce 100644
--- a/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
+++ b/java/com/google/gerrit/acceptance/AbstractDaemonTest.java
@@ -32,6 +32,8 @@
import static com.google.gerrit.server.project.ProjectCache.illegalState;
import static com.google.gerrit.server.project.testing.TestLabels.label;
import static com.google.gerrit.server.project.testing.TestLabels.value;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
@@ -91,6 +93,7 @@
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ProjectWatchInfo;
+import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -100,6 +103,7 @@
import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.IdString;
+import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.json.OutputFormat;
import com.google.gerrit.server.GerritPersonIdent;
@@ -1100,6 +1104,19 @@
}
}
+ protected void setSkipAddingAuthorAndCommitterAsReviewers(InheritableBoolean value)
+ throws Exception {
+ try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
+ ProjectConfig config = projectConfigFactory.read(md);
+ config.updateProject(
+ p ->
+ p.setBooleanConfig(
+ BooleanProjectConfig.SKIP_ADDING_AUTHOR_AND_COMMITTER_AS_REVIEWERS, value));
+ config.commit(md);
+ projectCache.evictAndReindex(config.getProject());
+ }
+ }
+
protected void blockAnonymousRead() throws Exception {
String allRefs = RefNames.REFS + "*";
projectOperations
@@ -1123,6 +1140,42 @@
gApi.changes().id(id).current().review(ReviewInput.recommend());
}
+ protected void assertThatAccountIsNotVisible(TestAccount... testAccounts) {
+ for (TestAccount testAccount : testAccounts) {
+ assertThrows(
+ ResourceNotFoundException.class, () -> gApi.accounts().id(testAccount.id().get()).get());
+ }
+ }
+
+ protected void assertReviewers(String changeId, TestAccount... expectedReviewers)
+ throws RestApiException {
+ Map<ReviewerState, Collection<AccountInfo>> reviewerMap =
+ gApi.changes().id(changeId).get().reviewers;
+ assertThat(reviewerMap).containsKey(ReviewerState.REVIEWER);
+ List<Integer> reviewers =
+ reviewerMap.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
+ assertThat(reviewers)
+ .containsExactlyElementsIn(
+ Arrays.stream(expectedReviewers).map(a -> a.id().get()).collect(toList()));
+ }
+
+ protected void assertCcs(String changeId, TestAccount... expectedCcs) throws RestApiException {
+ Map<ReviewerState, Collection<AccountInfo>> reviewerMap =
+ gApi.changes().id(changeId).get().reviewers;
+ assertThat(reviewerMap).containsKey(ReviewerState.CC);
+ List<Integer> ccs =
+ reviewerMap.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
+ assertThat(ccs)
+ .containsExactlyElementsIn(
+ Arrays.stream(expectedCcs).map(a -> a.id().get()).collect(toList()));
+ }
+
+ protected void assertNoCcs(String changeId) throws RestApiException {
+ Map<ReviewerState, Collection<AccountInfo>> reviewerMap =
+ gApi.changes().id(changeId).get().reviewers;
+ assertThat(reviewerMap).doesNotContainKey(ReviewerState.CC);
+ }
+
protected void assertSubmittedTogether(String chId, String... expected) throws Exception {
assertSubmittedTogether(chId, ImmutableSet.of(), expected);
}
@@ -1237,34 +1290,61 @@
assertThat(refValues.keySet()).containsAnyIn(trees.keySet());
}
- protected void assertDiffForNewFile(
- DiffInfo diff, RevCommit commit, String path, String expectedContentSideB) throws Exception {
- List<String> expectedLines = ImmutableList.copyOf(expectedContentSideB.split("\n", -1));
+ protected void assertDiffForFullyModifiedFile(
+ DiffInfo diff,
+ String commitName,
+ String path,
+ String expectedContentSideA,
+ String expectedContentSideB)
+ throws Exception {
+ assertDiffForFile(diff, commitName, path);
- assertThat(diff.binary).isNull();
+ ImmutableList<String> expectedOldLines =
+ ImmutableList.copyOf(expectedContentSideA.split("\n", -1));
+ ImmutableList<String> expectedNewLines =
+ ImmutableList.copyOf(expectedContentSideB.split("\n", -1));
+
+ assertThat(diff.changeType).isEqualTo(ChangeType.MODIFIED);
+
+ assertThat(diff.metaA).isNotNull();
+ assertThat(diff.metaB).isNotNull();
+
+ assertThat(diff.metaA.name).isEqualTo(path);
+ assertThat(diff.metaA.lines).isEqualTo(expectedOldLines.size());
+ assertThat(diff.metaB.name).isEqualTo(path);
+ assertThat(diff.metaB.lines).isEqualTo(expectedNewLines.size());
+
+ DiffInfo.ContentEntry contentEntry = diff.content.get(0);
+ assertThat(contentEntry.a).containsExactlyElementsIn(expectedOldLines).inOrder();
+ assertThat(contentEntry.b).containsExactlyElementsIn(expectedNewLines).inOrder();
+ assertThat(contentEntry.ab).isNull();
+ assertThat(contentEntry.common).isNull();
+ assertThat(contentEntry.editA).isNull();
+ assertThat(contentEntry.editB).isNull();
+ assertThat(contentEntry.skip).isNull();
+ }
+
+ protected void assertDiffForNewFile(
+ DiffInfo diff, @Nullable RevCommit commit, String path, String expectedContentSideB)
+ throws Exception {
+ assertDiffForNewFile(diff, commit.name(), path, expectedContentSideB);
+ }
+
+ protected void assertDiffForNewFile(
+ DiffInfo diff, String commitName, String path, String expectedContentSideB) throws Exception {
+ assertDiffForFile(diff, commitName, path);
+
+ ImmutableList<String> expectedLines =
+ ImmutableList.copyOf(expectedContentSideB.split("\n", -1));
+
assertThat(diff.changeType).isEqualTo(ChangeType.ADDED);
- assertThat(diff.diffHeader).isNotNull();
- assertThat(diff.intralineStatus).isNull();
- assertThat(diff.webLinks).isNull();
- assertThat(diff.editWebLinks).isNull();
assertThat(diff.metaA).isNull();
assertThat(diff.metaB).isNotNull();
- assertThat(diff.metaB.commitId).isEqualTo(commit.name());
- String expectedContentType = "text/plain";
- if (COMMIT_MSG.equals(path)) {
- expectedContentType = FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE;
- } else if (MERGE_LIST.equals(path)) {
- expectedContentType = FileContentUtil.TEXT_X_GERRIT_MERGE_LIST;
- }
- assertThat(diff.metaB.contentType).isEqualTo(expectedContentType);
-
- assertThat(diff.metaB.lines).isEqualTo(expectedLines.size());
assertThat(diff.metaB.name).isEqualTo(path);
- assertThat(diff.metaB.webLinks).isNull();
+ assertThat(diff.metaB.lines).isEqualTo(expectedLines.size());
- assertThat(diff.content).hasSize(1);
DiffInfo.ContentEntry contentEntry = diff.content.get(0);
assertThat(contentEntry.b).containsExactlyElementsIn(expectedLines).inOrder();
assertThat(contentEntry.a).isNull();
@@ -1275,6 +1355,57 @@
assertThat(contentEntry.skip).isNull();
}
+ protected void assertDiffForDeletedFile(DiffInfo diff, String path, String expectedContentSideA)
+ throws Exception {
+ assertDiffHeaders(diff);
+
+ ImmutableList<String> expectedOriginalLines =
+ ImmutableList.copyOf(expectedContentSideA.split("\n", -1));
+
+ assertThat(diff.changeType).isEqualTo(ChangeType.DELETED);
+
+ assertThat(diff.metaA).isNotNull();
+ assertThat(diff.metaB).isNull();
+
+ assertThat(diff.metaA.name).isEqualTo(path);
+ assertThat(diff.metaA.lines).isEqualTo(expectedOriginalLines.size());
+
+ DiffInfo.ContentEntry contentEntry = diff.content.get(0);
+ assertThat(contentEntry.a).containsExactlyElementsIn(expectedOriginalLines).inOrder();
+ assertThat(contentEntry.b).isNull();
+ assertThat(contentEntry.ab).isNull();
+ assertThat(contentEntry.common).isNull();
+ assertThat(contentEntry.editA).isNull();
+ assertThat(contentEntry.editB).isNull();
+ assertThat(contentEntry.skip).isNull();
+ }
+
+ private void assertDiffForFile(DiffInfo diff, String commitName, String path) throws Exception {
+ assertDiffHeaders(diff);
+
+ assertThat(diff.metaB.commitId).isEqualTo(commitName);
+
+ String expectedContentType = "text/plain";
+ if (COMMIT_MSG.equals(path)) {
+ expectedContentType = FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE;
+ } else if (MERGE_LIST.equals(path)) {
+ expectedContentType = FileContentUtil.TEXT_X_GERRIT_MERGE_LIST;
+ }
+
+ assertThat(diff.metaB.contentType).isEqualTo(expectedContentType);
+
+ assertThat(diff.metaB.name).isEqualTo(path);
+ assertThat(diff.metaB.webLinks).isNull();
+ }
+
+ private void assertDiffHeaders(DiffInfo diff) throws Exception {
+ assertThat(diff.binary).isNull();
+ assertThat(diff.diffHeader).isNotNull();
+ assertThat(diff.intralineStatus).isNull();
+ assertThat(diff.webLinks).isNull();
+ assertThat(diff.editWebLinks).isNull();
+ }
+
protected void assertPermitted(ChangeInfo info, String label, Integer... expected) {
assertThat(info.permittedLabels).isNotNull();
Collection<String> strs = info.permittedLabels.get(label);
@@ -1286,6 +1417,17 @@
}
}
+ protected void assertOnlyRemovableLabel(
+ ChangeInfo info, String labelId, String labelValue, TestAccount reviewer) {
+ assertThat(info.removableLabels).hasSize(1);
+ assertThat(info.removableLabels).containsKey(labelId);
+ assertThat(info.removableLabels.get(labelId)).hasSize(1);
+ assertThat(info.removableLabels.get(labelId)).containsKey(labelValue);
+ assertThat(info.removableLabels.get(labelId).get(labelValue)).hasSize(1);
+ assertThat(info.removableLabels.get(labelId).get(labelValue).get(0).email)
+ .isEqualTo(reviewer.email());
+ }
+
protected void assertPermissions(
Project.NameKey project,
GroupReference groupReference,
@@ -1589,11 +1731,14 @@
}
public void save() throws Exception {
- metaDataUpdate.setAuthor(identifiedUserFactory.create(admin.id()));
- projectConfig.commit(metaDataUpdate);
- metaDataUpdate.close();
- metaDataUpdate = null;
- projectCache.evictAndReindex(projectConfig.getProject());
+ testRefAction(
+ () -> {
+ metaDataUpdate.setAuthor(identifiedUserFactory.create(admin.id()));
+ projectConfig.commit(metaDataUpdate);
+ metaDataUpdate.close();
+ metaDataUpdate = null;
+ projectCache.evictAndReindex(projectConfig.getProject());
+ });
}
@Override
@@ -1636,6 +1781,14 @@
.collect(ImmutableMap.toImmutableMap(branch -> branch.ref, branch -> branch));
}
+ protected void createRefLogFileIfMissing(Repository repo, String ref) throws IOException {
+ File log = new File(repo.getDirectory(), "logs/" + ref);
+ if (!log.exists()) {
+ log.getParentFile().mkdirs();
+ assertThat(log.createNewFile()).isTrue();
+ }
+ }
+
protected AutoCloseable installPlugin(String pluginName, Class<? extends Module> sysModuleClass)
throws Exception {
return installPlugin(pluginName, sysModuleClass, null, null);
diff --git a/java/com/google/gerrit/acceptance/AbstractNotificationTest.java b/java/com/google/gerrit/acceptance/AbstractNotificationTest.java
index da033c1..8a9e56a 100644
--- a/java/com/google/gerrit/acceptance/AbstractNotificationTest.java
+++ b/java/com/google/gerrit/acceptance/AbstractNotificationTest.java
@@ -343,7 +343,6 @@
public final TestAccount reviewer;
public final TestAccount ccer;
public final TestAccount starrer;
- public final TestAccount assignee;
public final TestAccount watchingProjectOwner;
private final Map<NotifyType, TestAccount> watchers = new HashMap<>();
private final Map<String, TestAccount> accountsByEmail = new HashMap<>();
@@ -369,7 +368,6 @@
reviewer = reindexAndCopy(existing.reviewer);
ccer = reindexAndCopy(existing.ccer);
starrer = reindexAndCopy(existing.starrer);
- assignee = reindexAndCopy(existing.assignee);
watchingProjectOwner = reindexAndCopy(existing.watchingProjectOwner);
watchers.putAll(existing.watchers);
return;
@@ -381,7 +379,6 @@
uploader = testAccount("uploader");
ccer = testAccount("ccer");
starrer = testAccount("starrer");
- assignee = testAccount("assignee");
watchingProjectOwner = testAccount("watchingProjectOwner", "Administrators");
requestScopeOperations.setApiUser(watchingProjectOwner.id());
diff --git a/java/com/google/gerrit/acceptance/AbstractPluginFieldsTest.java b/java/com/google/gerrit/acceptance/AbstractPluginFieldsTest.java
index 91fbf9e..fe845c0 100644
--- a/java/com/google/gerrit/acceptance/AbstractPluginFieldsTest.java
+++ b/java/com/google/gerrit/acceptance/AbstractPluginFieldsTest.java
@@ -303,6 +303,7 @@
return pluginInfoFromChangeInfo(changeInfos.get(0));
}
+ @Nullable
protected static List<PluginDefinedInfo> pluginInfoFromChangeInfo(ChangeInfo changeInfo) {
List<PluginDefinedInfo> pluginInfo = changeInfo.plugins;
if (pluginInfo == null) {
@@ -331,6 +332,7 @@
* @param plugins list of {@code MyInfo} objects, each as a raw map returned from Gson.
* @return decoded list of {@code MyInfo}s.
*/
+ @Nullable
protected static List<PluginDefinedInfo> decodeRawPluginsList(
Gson gson, @Nullable Object plugins) {
if (plugins == null) {
diff --git a/java/com/google/gerrit/acceptance/AccountCreator.java b/java/com/google/gerrit/acceptance/AccountCreator.java
index c67991d..ff5bc00 100644
--- a/java/com/google/gerrit/acceptance/AccountCreator.java
+++ b/java/com/google/gerrit/acceptance/AccountCreator.java
@@ -141,6 +141,10 @@
return create(username, null, username, null, (String[]) null);
}
+ public TestAccount createValid(String username) throws Exception {
+ return create(username, username + "@example.com", username, username);
+ }
+
public TestAccount admin() throws Exception {
return create("admin", "admin@example.com", "Administrator", "Adminny", "Administrators");
}
diff --git a/java/com/google/gerrit/acceptance/BUILD b/java/com/google/gerrit/acceptance/BUILD
index 2cf279f..8b2160c 100644
--- a/java/com/google/gerrit/acceptance/BUILD
+++ b/java/com/google/gerrit/acceptance/BUILD
@@ -76,6 +76,8 @@
"//java/com/google/gerrit/gpg/testing:gpg-test-util",
"//java/com/google/gerrit/git/testing",
"//java/com/google/gerrit/index/testing",
+ "//java/com/google/gerrit/testing:test-ref-update-context",
+ "//lib/errorprone:annotations",
]
PGM_DEPLOY_ENV = [
diff --git a/java/com/google/gerrit/acceptance/DisabledAccountIndex.java b/java/com/google/gerrit/acceptance/DisabledAccountIndex.java
index 7bd0c73..7660948 100644
--- a/java/com/google/gerrit/acceptance/DisabledAccountIndex.java
+++ b/java/com/google/gerrit/acceptance/DisabledAccountIndex.java
@@ -55,6 +55,11 @@
}
@Override
+ public void deleteByValue(AccountState value) {
+ throw new UnsupportedOperationException("AccountIndex is disabled");
+ }
+
+ @Override
public void delete(Account.Id key) {
throw new UnsupportedOperationException("AccountIndex is disabled");
}
diff --git a/java/com/google/gerrit/acceptance/DisabledChangeIndex.java b/java/com/google/gerrit/acceptance/DisabledChangeIndex.java
index 7671ad4..c028a8e 100644
--- a/java/com/google/gerrit/acceptance/DisabledChangeIndex.java
+++ b/java/com/google/gerrit/acceptance/DisabledChangeIndex.java
@@ -62,6 +62,11 @@
}
@Override
+ public void deleteByValue(ChangeData value) {
+ throw new UnsupportedOperationException("ChangeIndex is disabled");
+ }
+
+ @Override
public void delete(Change.Id key) {
throw new UnsupportedOperationException("ChangeIndex is disabled");
}
diff --git a/java/com/google/gerrit/acceptance/DisabledProjectIndex.java b/java/com/google/gerrit/acceptance/DisabledProjectIndex.java
index 2e3dd90..f2aad4a 100644
--- a/java/com/google/gerrit/acceptance/DisabledProjectIndex.java
+++ b/java/com/google/gerrit/acceptance/DisabledProjectIndex.java
@@ -60,6 +60,11 @@
}
@Override
+ public void deleteByValue(ProjectData value) {
+ throw new UnsupportedOperationException("ProjectIndex is disabled");
+ }
+
+ @Override
public void delete(Project.NameKey key) {
throw new UnsupportedOperationException("ProjectIndex is disabled");
}
diff --git a/java/com/google/gerrit/acceptance/GerritServer.java b/java/com/google/gerrit/acceptance/GerritServer.java
index a9ad3f2..1199bf9 100644
--- a/java/com/google/gerrit/acceptance/GerritServer.java
+++ b/java/com/google/gerrit/acceptance/GerritServer.java
@@ -70,6 +70,7 @@
import com.google.gerrit.server.util.ReplicaUtil;
import com.google.gerrit.server.util.SocketUtil;
import com.google.gerrit.server.util.SystemLog;
+import com.google.gerrit.testing.FakeAccountPatchReviewStore.FakeAccountPatchReviewStoreModule;
import com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule;
import com.google.gerrit.testing.InMemoryRepositoryManager;
import com.google.gerrit.testing.SshMode;
@@ -431,6 +432,7 @@
}
},
site);
+ daemon.setAccountPatchReviewStoreModuleForTesting(new FakeAccountPatchReviewStoreModule());
daemon.setEmailModuleForTesting(new FakeEmailSenderModule());
daemon.setAuditEventModuleForTesting(
MoreObjects.firstNonNull(testAuditModule, new FakeGroupAuditServiceModule()));
diff --git a/java/com/google/gerrit/acceptance/HttpResponse.java b/java/com/google/gerrit/acceptance/HttpResponse.java
index 88079a4..76c0f04 100644
--- a/java/com/google/gerrit/acceptance/HttpResponse.java
+++ b/java/com/google/gerrit/acceptance/HttpResponse.java
@@ -19,6 +19,7 @@
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.common.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -59,6 +60,7 @@
return getHeader("X-FYI-Content-Type");
}
+ @Nullable
public String getHeader(String name) {
Header hdr = response.getFirstHeader(name);
return hdr != null ? hdr.getValue() : null;
diff --git a/java/com/google/gerrit/acceptance/ProjectResetter.java b/java/com/google/gerrit/acceptance/ProjectResetter.java
index 46f7496..c8ab1a9 100644
--- a/java/com/google/gerrit/acceptance/ProjectResetter.java
+++ b/java/com/google/gerrit/acceptance/ProjectResetter.java
@@ -16,6 +16,7 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.entities.RefNames.REFS_USERS;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
import static java.util.stream.Collectors.toSet;
import com.google.common.collect.ImmutableList;
@@ -202,10 +203,12 @@
keptRefsByProject = MultimapBuilder.hashKeys().arrayListValues().build();
restoredRefsByProject = MultimapBuilder.hashKeys().arrayListValues().build();
deletedRefsByProject = MultimapBuilder.hashKeys().arrayListValues().build();
-
- restoreRefs();
- deleteNewlyCreatedRefs();
- evictCachesAndReindex();
+ testRefAction(
+ () -> {
+ restoreRefs();
+ deleteNewlyCreatedRefs();
+ evictCachesAndReindex();
+ });
}
/** Read the states of all matching refs. */
diff --git a/java/com/google/gerrit/acceptance/PushOneCommit.java b/java/com/google/gerrit/acceptance/PushOneCommit.java
index 99db40a..9f38fcb 100644
--- a/java/com/google/gerrit/acceptance/PushOneCommit.java
+++ b/java/com/google/gerrit/acceptance/PushOneCommit.java
@@ -24,6 +24,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.UsedAt;
import com.google.gerrit.common.UsedAt.Project;
@@ -40,6 +41,7 @@
import com.google.inject.assistedinject.AssistedInject;
import java.util.Arrays;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jgit.api.TagCommand;
@@ -280,6 +282,12 @@
return this;
}
+ @CanIgnoreReturnValue
+ public PushOneCommit setTopLevelTreeId(ObjectId treeId) throws Exception {
+ commitBuilder.setTopLevelTree(treeId);
+ return this;
+ }
+
public PushOneCommit setParent(RevCommit parent) throws Exception {
commitBuilder.noParents();
commitBuilder.parent(parent);
@@ -291,6 +299,19 @@
return this;
}
+ public PushOneCommit addFile(String path, String content, int fileMode) throws Exception {
+ RevBlob blobId = testRepo.blob(content);
+ commitBuilder.edit(
+ new PathEdit(path) {
+ @Override
+ public void apply(DirCacheEntry ent) {
+ ent.setFileMode(FileMode.fromBits(fileMode));
+ ent.setObjectId(blobId);
+ }
+ });
+ return this;
+ }
+
public PushOneCommit addSymlink(String path, String target) throws Exception {
RevBlob blobId = testRepo.blob(target);
commitBuilder.edit(
@@ -470,12 +491,14 @@
public void assertMessage(String expectedMessage) {
RemoteRefUpdate refUpdate = result.getRemoteUpdate(ref);
assertThat(refUpdate).isNotNull();
- assertThat(message(refUpdate).toLowerCase()).contains(expectedMessage.toLowerCase());
+ assertThat(message(refUpdate).toLowerCase(Locale.US))
+ .contains(expectedMessage.toLowerCase(Locale.US));
}
public void assertNotMessage(String message) {
RemoteRefUpdate refUpdate = result.getRemoteUpdate(ref);
- assertThat(message(refUpdate).toLowerCase()).doesNotContain(message.toLowerCase());
+ assertThat(message(refUpdate).toLowerCase(Locale.US))
+ .doesNotContain(message.toLowerCase(Locale.US));
}
public String getMessage() {
diff --git a/java/com/google/gerrit/acceptance/TestMetricMaker.java b/java/com/google/gerrit/acceptance/TestMetricMaker.java
index 881f389..85233f2 100644
--- a/java/com/google/gerrit/acceptance/TestMetricMaker.java
+++ b/java/com/google/gerrit/acceptance/TestMetricMaker.java
@@ -14,13 +14,19 @@
package com.google.gerrit.acceptance;
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.UsedAt;
import com.google.gerrit.metrics.Counter0;
+import com.google.gerrit.metrics.Counter1;
+import com.google.gerrit.metrics.Counter2;
+import com.google.gerrit.metrics.Counter3;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.DisabledMetricMaker;
import com.google.gerrit.metrics.Field;
import com.google.gerrit.metrics.Timer1;
import com.google.inject.Singleton;
+import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.mutable.MutableLong;
@@ -28,11 +34,9 @@
/**
* {@link com.google.gerrit.metrics.MetricMaker} to be bound in tests.
*
- * <p>Records how often {@link Counter0} and {@link Timer1} metrics are invoked. Metrics for other
- * types are not recorded.
+ * <p>Records how often counter metrics are invoked. Metrics of other types are not recorded.
*
- * <p>Allows test to check how much a {@link Counter0} and {@link Timer1} metric is increased by an
- * operation.
+ * <p>Allows test to check how much a counter metrics is increased by an operation.
*
* <p>Example:
*
@@ -53,15 +57,15 @@
*/
@Singleton
public class TestMetricMaker extends DisabledMetricMaker {
- private final ConcurrentHashMap<String, MutableLong> counts = new ConcurrentHashMap<>();
- private final ConcurrentHashMap<String, MutableLong> timers = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap<CounterKey, MutableLong> counts = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap<CounterKey, MutableLong> timers = new ConcurrentHashMap<>();
- public long getCount(String counter0Name) {
- return getCounterValue(counter0Name).longValue();
+ public long getCount(String counterName, Object... fieldValues) {
+ return getCounterValue(CounterKey.create(counterName, fieldValues)).longValue();
}
public long getTimer(String timerName) {
- return getTimerValue(timerName).longValue();
+ return getTimerValue(CounterKey.create(timerName)).longValue();
}
public void reset() {
@@ -69,11 +73,11 @@
timers.clear();
}
- private MutableLong getCounterValue(String counter0Name) {
- return counts.computeIfAbsent(counter0Name, name -> new MutableLong(0));
+ private MutableLong getCounterValue(CounterKey counterKey) {
+ return counts.computeIfAbsent(counterKey, name -> new MutableLong(0));
}
- private MutableLong getTimerValue(String timerName) {
+ private MutableLong getTimerValue(CounterKey timerName) {
return counts.computeIfAbsent(timerName, name -> new MutableLong(0));
}
@@ -82,7 +86,7 @@
return new Counter0() {
@Override
public void incrementBy(long value) {
- getCounterValue(name).add(value);
+ getCounterValue(CounterKey.create(name)).add(value);
}
@Override
@@ -96,11 +100,64 @@
return new Timer1<>(name, field1) {
@Override
protected void doRecord(F1 field1, long value, TimeUnit unit) {
- getTimerValue(name).add(value);
+ getTimerValue(CounterKey.create(name)).add(value);
}
@Override
public void remove() {}
};
}
+
+ @Override
+ public <F1> Counter1<F1> newCounter(String name, Description desc, Field<F1> field1) {
+ return new Counter1<>() {
+ @Override
+ public void incrementBy(F1 field1, long value) {
+ getCounterValue(CounterKey.create(name, field1)).add(value);
+ }
+
+ @Override
+ public void remove() {}
+ };
+ }
+
+ @Override
+ public <F1, F2> Counter2<F1, F2> newCounter(
+ String name, Description desc, Field<F1> field1, Field<F2> field2) {
+ return new Counter2<>() {
+ @Override
+ public void incrementBy(F1 field1, F2 field2, long value) {
+ getCounterValue(CounterKey.create(name, field1, field2)).add(value);
+ }
+
+ @Override
+ public void remove() {}
+ };
+ }
+
+ @Override
+ public <F1, F2, F3> Counter3<F1, F2, F3> newCounter(
+ String name, Description desc, Field<F1> field1, Field<F2> field2, Field<F3> field3) {
+ return new Counter3<>() {
+ @Override
+ public void incrementBy(F1 field1, F2 field2, F3 field3, long value) {
+ getCounterValue(CounterKey.create(name, field1, field2, field3)).add(value);
+ }
+
+ @Override
+ public void remove() {}
+ };
+ }
+
+ @AutoValue
+ abstract static class CounterKey {
+ abstract String name();
+
+ abstract ImmutableList<Object> fieldValues();
+
+ static CounterKey create(String name, Object... fieldValues) {
+ return new AutoValue_TestMetricMaker_CounterKey(
+ name, ImmutableList.copyOf(Arrays.asList(fieldValues)));
+ }
+ }
}
diff --git a/java/com/google/gerrit/acceptance/config/BUILD b/java/com/google/gerrit/acceptance/config/BUILD
index a8ccc1f..0da68b0 100644
--- a/java/com/google/gerrit/acceptance/config/BUILD
+++ b/java/com/google/gerrit/acceptance/config/BUILD
@@ -7,6 +7,7 @@
srcs = glob(["*.java"]),
visibility = ["//visibility:public"],
deps = [
+ "//java/com/google/gerrit/common:annotations",
"//lib:guava",
"//lib:jgit",
"//lib/auto:auto-value",
diff --git a/java/com/google/gerrit/acceptance/config/ConfigAnnotationParser.java b/java/com/google/gerrit/acceptance/config/ConfigAnnotationParser.java
index 32dfa83..fc6be03 100644
--- a/java/com/google/gerrit/acceptance/config/ConfigAnnotationParser.java
+++ b/java/com/google/gerrit/acceptance/config/ConfigAnnotationParser.java
@@ -18,6 +18,7 @@
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
+import com.google.gerrit.common.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -27,6 +28,7 @@
public class ConfigAnnotationParser {
private static Splitter splitter = Splitter.on(".").trimResults();
+ @Nullable
public static Config parse(Config base, GerritConfigs annotation) {
if (annotation == null) {
return null;
@@ -55,6 +57,7 @@
System.setProperty(annotation.name(), annotation.value());
}
+ @Nullable
public static Map<String, Config> parse(GlobalPluginConfigs annotation) {
if (annotation == null || annotation.value().length < 1) {
return null;
@@ -77,6 +80,7 @@
return result;
}
+ @Nullable
public static Map<String, Config> parse(GlobalPluginConfig annotation) {
if (annotation == null) {
return null;
diff --git a/java/com/google/gerrit/acceptance/testsuite/account/TestSshKeys.java b/java/com/google/gerrit/acceptance/testsuite/account/TestSshKeys.java
index 277d219..e510ba3 100644
--- a/java/com/google/gerrit/acceptance/testsuite/account/TestSshKeys.java
+++ b/java/com/google/gerrit/acceptance/testsuite/account/TestSshKeys.java
@@ -15,6 +15,7 @@
package com.google.gerrit.acceptance.testsuite.account;
import static com.google.common.base.Preconditions.checkState;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
import static java.nio.charset.StandardCharsets.US_ASCII;
import com.google.gerrit.acceptance.SshEnabled;
@@ -88,7 +89,8 @@
private KeyPair createKeyPair(Account.Id accountId, String username, @Nullable String email)
throws Exception {
KeyPair keyPair = SshSessionFactory.genSshKey();
- authorizedKeys.addKey(accountId, publicKey(keyPair, email));
+ testRefAction(() -> authorizedKeys.addKey(accountId, publicKey(keyPair, email)));
+
sshKeyCache.evict(username);
return keyPair;
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/change/ChangeOperationsImpl.java b/java/com/google/gerrit/acceptance/testsuite/change/ChangeOperationsImpl.java
index c1029be..5efcfc6 100644
--- a/java/com/google/gerrit/acceptance/testsuite/change/ChangeOperationsImpl.java
+++ b/java/com/google/gerrit/acceptance/testsuite/change/ChangeOperationsImpl.java
@@ -16,10 +16,12 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.openTestRefUpdateContext;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.PatchSet;
@@ -43,6 +45,7 @@
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.UpdateException;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import com.google.gerrit.server.util.CommitMessageUtil;
import com.google.gerrit.server.util.time.TimeUtil;
import com.google.inject.Inject;
@@ -131,29 +134,33 @@
}
private Change.Id createChange(TestChangeCreation changeCreation) throws Exception {
- Change.Id changeId = Change.id(seq.nextChangeId());
- Project.NameKey project = getTargetProject(changeCreation);
+ try (RefUpdateContext ctx = openTestRefUpdateContext()) {
+ Change.Id changeId = Change.id(seq.nextChangeId());
+ Project.NameKey project = getTargetProject(changeCreation);
- try (Repository repository = repositoryManager.openRepository(project);
- ObjectInserter objectInserter = repository.newObjectInserter();
- RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
- Instant now = TimeUtil.now();
- IdentifiedUser changeOwner = getChangeOwner(changeCreation);
- PersonIdent authorAndCommitter = changeOwner.newCommitterIdent(now, serverIdent.getZoneId());
- ObjectId commitId =
- createCommit(repository, revWalk, objectInserter, changeCreation, authorAndCommitter);
+ try (Repository repository = repositoryManager.openRepository(project);
+ ObjectInserter objectInserter = repository.newObjectInserter();
+ RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
+ Instant now = TimeUtil.now();
+ IdentifiedUser changeOwner = getChangeOwner(changeCreation);
+ PersonIdent author = getAuthorIdent(now, changeCreation);
+ PersonIdent committer = getCommitterIdent(now, changeCreation);
+ ObjectId commitId =
+ createCommit(repository, revWalk, objectInserter, changeCreation, author, committer);
- String refName = RefNames.fullName(changeCreation.branch());
- ChangeInserter inserter = getChangeInserter(changeId, refName, commitId);
- changeCreation.topic().ifPresent(t -> inserter.setTopic(t));
- inserter.setApprovals(changeCreation.approvals());
+ String refName = RefNames.fullName(changeCreation.branch());
+ ChangeInserter inserter = getChangeInserter(changeId, refName, commitId);
+ inserter.setGroups(getGroups(changeCreation));
+ changeCreation.topic().ifPresent(t -> inserter.setTopic(t));
+ inserter.setApprovals(changeCreation.approvals());
- try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, changeOwner, now)) {
- batchUpdate.setRepository(repository, revWalk, objectInserter);
- batchUpdate.insertChange(inserter);
- batchUpdate.execute();
+ try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, changeOwner, now)) {
+ batchUpdate.setRepository(repository, revWalk, objectInserter);
+ batchUpdate.insertChange(inserter);
+ batchUpdate.execute();
+ }
+ return changeId;
}
- return changeId;
}
}
@@ -189,6 +196,30 @@
return getArbitraryUser();
}
+ private PersonIdent getAuthorIdent(Instant when, TestChangeCreation changeCreation)
+ throws IOException, ConfigInvalidException {
+ if (changeCreation.authorIdent().isPresent()) {
+ return new PersonIdent(changeCreation.authorIdent().get(), when);
+ }
+
+ return (changeCreation.author().isPresent()
+ ? userFactory.create(changeCreation.author().get())
+ : getChangeOwner(changeCreation))
+ .newCommitterIdent(when, serverIdent.getZoneId());
+ }
+
+ private PersonIdent getCommitterIdent(Instant when, TestChangeCreation changeCreation)
+ throws IOException, ConfigInvalidException {
+ if (changeCreation.committerIdent().isPresent()) {
+ return new PersonIdent(changeCreation.committerIdent().get(), when);
+ }
+
+ return (changeCreation.committer().isPresent()
+ ? userFactory.create(changeCreation.committer().get())
+ : getChangeOwner(changeCreation))
+ .newCommitterIdent(when, serverIdent.getZoneId());
+ }
+
private IdentifiedUser getArbitraryUser() throws ConfigInvalidException, IOException {
ImmutableSet<Account.Id> foundAccounts = resolver.resolveIgnoreVisibility("").asIdSet();
checkState(
@@ -202,20 +233,84 @@
RevWalk revWalk,
ObjectInserter objectInserter,
TestChangeCreation changeCreation,
- PersonIdent authorAndCommitter)
+ PersonIdent author,
+ PersonIdent committer)
throws IOException, BadRequestException {
ImmutableList<ObjectId> parentCommits = getParentCommits(repository, revWalk, changeCreation);
TreeCreator treeCreator =
getTreeCreator(objectInserter, parentCommits, changeCreation.mergeStrategy());
ObjectId tree = createNewTree(repository, treeCreator, changeCreation.treeModifications());
String commitMessage = correctCommitMessage(changeCreation.commitMessage());
- return createCommit(
- objectInserter, tree, parentCommits, authorAndCommitter, authorAndCommitter, commitMessage);
+ return createCommit(objectInserter, tree, parentCommits, author, committer, commitMessage);
+ }
+
+ private ImmutableList<String> getGroups(TestChangeCreation changeCreation) {
+ return changeCreation
+ .parents()
+ .map(parents -> getGroups(parents))
+ .orElseGet(() -> ImmutableList.of());
+ }
+
+ private ImmutableList<String> getGroups(ImmutableList<TestCommitIdentifier> parents) {
+ return parents.stream()
+ .map(parent -> getGroups(parent))
+ .flatMap(groups -> groups.stream())
+ .collect(toImmutableList());
+ }
+
+ private ImmutableList<String> getGroups(TestCommitIdentifier parentCommit) {
+ switch (parentCommit.getKind()) {
+ case BRANCH:
+ return ImmutableList.of();
+ case CHANGE_ID:
+ return getGroupsFromChange(parentCommit.changeId());
+ case COMMIT_SHA_1:
+ return ImmutableList.of();
+ case PATCHSET_ID:
+ return getGroupsFromPatchset(parentCommit.patchsetId());
+ default:
+ throw new IllegalStateException(
+ String.format("No parent behavior implemented for %s.", parentCommit.getKind()));
+ }
+ }
+
+ private ImmutableList<String> getGroupsFromChange(Change.Id changeId) {
+ Optional<ChangeNotes> changeNotes = changeFinder.findOne(changeId);
+
+ if (changeNotes.isPresent() && changeNotes.get().getChange().isClosed()) {
+ return ImmutableList.of();
+ }
+
+ return changeNotes
+ .map(ChangeNotes::getCurrentPatchSet)
+ .map(PatchSet::groups)
+ .orElseThrow(
+ () ->
+ new IllegalStateException(
+ String.format(
+ "Change %s not found and hence can't be used as parent.", changeId)));
+ }
+
+ private ImmutableList<String> getGroupsFromPatchset(PatchSet.Id patchsetId) {
+ Optional<ChangeNotes> changeNotes = changeFinder.findOne(patchsetId.changeId());
+
+ if (changeNotes.isPresent() && changeNotes.get().getChange().isClosed()) {
+ return ImmutableList.of();
+ }
+
+ return changeNotes
+ .map(ChangeNotes::getPatchSets)
+ .map(patchsets -> patchsets.get(patchsetId))
+ .map(PatchSet::groups)
+ .orElseThrow(
+ () ->
+ new IllegalStateException(
+ String.format(
+ "Patchset %s not found and hence can't be used as parent.", patchsetId)));
}
private ImmutableList<ObjectId> getParentCommits(
Repository repository, RevWalk revWalk, TestChangeCreation changeCreation) {
-
return changeCreation
.parents()
.map(parents -> resolveParents(repository, revWalk, parents))
@@ -426,37 +521,82 @@
private PatchSet.Id createPatchset(TestPatchsetCreation patchsetCreation)
throws IOException, RestApiException, UpdateException {
- ChangeNotes changeNotes = getChangeNotes();
- Project.NameKey project = changeNotes.getProjectName();
- try (Repository repository = repositoryManager.openRepository(project);
- ObjectInserter objectInserter = repository.newObjectInserter();
- RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
- Instant now = TimeUtil.now();
- ObjectId newPatchsetCommit =
- createPatchsetCommit(
- repository, revWalk, objectInserter, changeNotes, patchsetCreation, now);
+ try (RefUpdateContext ctx = openTestRefUpdateContext()) {
+ ChangeNotes changeNotes = getChangeNotes();
+ Project.NameKey project = changeNotes.getProjectName();
+ try (Repository repository = repositoryManager.openRepository(project);
+ ObjectInserter objectInserter = repository.newObjectInserter();
+ RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
+ Instant now = TimeUtil.now();
+ PersonIdent authorIdent = getAuthorIdent(now, patchsetCreation);
+ PersonIdent committerIdent = getCommitterIdent(now, patchsetCreation);
+ ObjectId newPatchsetCommit =
+ createPatchsetCommit(
+ repository,
+ revWalk,
+ objectInserter,
+ changeNotes,
+ patchsetCreation,
+ authorIdent,
+ committerIdent,
+ now);
- PatchSet.Id patchsetId =
- ChangeUtil.nextPatchSetId(repository, changeNotes.getCurrentPatchSet().id());
- PatchSetInserter patchSetInserter =
- getPatchSetInserter(changeNotes, newPatchsetCommit, patchsetId);
+ PatchSet.Id patchsetId =
+ ChangeUtil.nextPatchSetId(repository, changeNotes.getCurrentPatchSet().id());
+ PatchSetInserter patchSetInserter =
+ getPatchSetInserter(changeNotes, newPatchsetCommit, patchsetId);
- IdentifiedUser changeOwner = userFactory.create(changeNotes.getChange().getOwner());
- try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, changeOwner, now)) {
- batchUpdate.setRepository(repository, revWalk, objectInserter);
- batchUpdate.addOp(changeId, patchSetInserter);
- batchUpdate.execute();
+ Account.Id uploaderId =
+ patchsetCreation.uploader().orElse(changeNotes.getChange().getOwner());
+ IdentifiedUser uploader = userFactory.create(uploaderId);
+ try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, uploader, now)) {
+ batchUpdate.setRepository(repository, revWalk, objectInserter);
+ batchUpdate.addOp(changeId, patchSetInserter);
+ batchUpdate.execute();
+ }
+ return patchsetId;
}
- return patchsetId;
}
}
+ @Nullable
+ private PersonIdent getAuthorIdent(Instant when, TestPatchsetCreation patchsetCreation) {
+ if (patchsetCreation.authorIdent().isPresent()) {
+ return new PersonIdent(patchsetCreation.authorIdent().get(), when);
+ }
+
+ if (patchsetCreation.author().isPresent()) {
+ return userFactory
+ .create(patchsetCreation.author().get())
+ .newCommitterIdent(when, serverIdent.getZoneId());
+ }
+
+ return null;
+ }
+
+ @Nullable
+ private PersonIdent getCommitterIdent(Instant when, TestPatchsetCreation patchsetCreation) {
+ if (patchsetCreation.committerIdent().isPresent()) {
+ return new PersonIdent(patchsetCreation.committerIdent().get(), when);
+ }
+
+ if (patchsetCreation.committer().isPresent()) {
+ return userFactory
+ .create(patchsetCreation.committer().get())
+ .newCommitterIdent(when, serverIdent.getZoneId());
+ }
+
+ return null;
+ }
+
private ObjectId createPatchsetCommit(
Repository repository,
RevWalk revWalk,
ObjectInserter objectInserter,
ChangeNotes changeNotes,
TestPatchsetCreation patchsetCreation,
+ @Nullable PersonIdent author,
+ @Nullable PersonIdent committer,
Instant now)
throws IOException, BadRequestException {
ObjectId oldPatchsetCommitId = changeNotes.getCurrentPatchSet().commitId();
@@ -472,9 +612,13 @@
changeNotes.getChange().getKey().get(),
patchsetCreation.commitMessage().orElseGet(oldPatchsetCommit::getFullMessage));
- PersonIdent author = getAuthor(oldPatchsetCommit);
- PersonIdent committer = getCommitter(oldPatchsetCommit, now);
- return createCommit(objectInserter, tree, parentCommitIds, author, committer, commitMessage);
+ return createCommit(
+ objectInserter,
+ tree,
+ parentCommitIds,
+ Optional.ofNullable(author).orElse(getAuthor(oldPatchsetCommit)),
+ Optional.ofNullable(committer).orElse(getCommitter(oldPatchsetCommit, now)),
+ commitMessage);
}
private String correctCommitMessage(String oldChangeId, String desiredCommitMessage)
diff --git a/java/com/google/gerrit/acceptance/testsuite/change/FileContentBuilder.java b/java/com/google/gerrit/acceptance/testsuite/change/FileContentBuilder.java
index d0ccd5b..1971c57 100644
--- a/java/com/google/gerrit/acceptance/testsuite/change/FileContentBuilder.java
+++ b/java/com/google/gerrit/acceptance/testsuite/change/FileContentBuilder.java
@@ -28,13 +28,18 @@
public class FileContentBuilder<T> {
private final T builder;
private final String filePath;
+ private final int newGitFileMode;
private final Consumer<TreeModification> modificationToBuilderAdder;
FileContentBuilder(
- T builder, String filePath, Consumer<TreeModification> modificationToBuilderAdder) {
+ T builder,
+ String filePath,
+ int newGitFileMode,
+ Consumer<TreeModification> modificationToBuilderAdder) {
checkNotNull(Strings.emptyToNull(filePath), "File path must not be null or empty.");
this.builder = builder;
this.filePath = filePath;
+ this.newGitFileMode = newGitFileMode;
this.modificationToBuilderAdder = modificationToBuilderAdder;
}
@@ -44,7 +49,7 @@
Strings.emptyToNull(content),
"Empty file content is not supported. Adjust test API if necessary.");
modificationToBuilderAdder.accept(
- new ChangeFileContentModification(filePath, RawInputUtil.create(content)));
+ new ChangeFileContentModification(filePath, RawInputUtil.create(content), newGitFileMode));
return builder;
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/change/PerPatchsetOperationsImpl.java b/java/com/google/gerrit/acceptance/testsuite/change/PerPatchsetOperationsImpl.java
index 9b393ef..3bd355b 100644
--- a/java/com/google/gerrit/acceptance/testsuite/change/PerPatchsetOperationsImpl.java
+++ b/java/com/google/gerrit/acceptance/testsuite/change/PerPatchsetOperationsImpl.java
@@ -14,6 +14,8 @@
package com.google.gerrit.acceptance.testsuite.change;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.openTestRefUpdateContext;
+
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Comment.Status;
import com.google.gerrit.entities.HumanComment;
@@ -34,6 +36,7 @@
import com.google.gerrit.server.update.BatchUpdateOp;
import com.google.gerrit.server.update.ChangeContext;
import com.google.gerrit.server.update.UpdateException;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import com.google.gerrit.server.util.time.TimeUtil;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -101,21 +104,23 @@
private String createComment(TestCommentCreation commentCreation)
throws IOException, RestApiException, UpdateException {
+
Project.NameKey project = changeNotes.getProjectName();
+ try (RefUpdateContext ctx = openTestRefUpdateContext()) {
+ try (Repository repository = repositoryManager.openRepository(project);
+ ObjectInserter objectInserter = repository.newObjectInserter();
+ RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
+ Instant now = TimeUtil.now();
- try (Repository repository = repositoryManager.openRepository(project);
- ObjectInserter objectInserter = repository.newObjectInserter();
- RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
- Instant now = TimeUtil.now();
-
- IdentifiedUser author = getAuthor(commentCreation);
- CommentAdditionOp commentAdditionOp = new CommentAdditionOp(commentCreation);
- try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, author, now)) {
- batchUpdate.setRepository(repository, revWalk, objectInserter);
- batchUpdate.addOp(changeNotes.getChangeId(), commentAdditionOp);
- batchUpdate.execute();
+ IdentifiedUser author = getAuthor(commentCreation);
+ CommentAdditionOp commentAdditionOp = new CommentAdditionOp(commentCreation);
+ try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, author, now)) {
+ batchUpdate.setRepository(repository, revWalk, objectInserter);
+ batchUpdate.addOp(changeNotes.getChangeId(), commentAdditionOp);
+ batchUpdate.execute();
+ }
+ return commentAdditionOp.createdCommentUuid;
}
- return commentAdditionOp.createdCommentUuid;
}
}
@@ -197,21 +202,22 @@
private String createRobotComment(TestRobotCommentCreation robotCommentCreation)
throws IOException, RestApiException, UpdateException {
Project.NameKey project = changeNotes.getProjectName();
+ try (RefUpdateContext ctx = openTestRefUpdateContext()) {
+ try (Repository repository = repositoryManager.openRepository(project);
+ ObjectInserter objectInserter = repository.newObjectInserter();
+ RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
+ Instant now = TimeUtil.now();
- try (Repository repository = repositoryManager.openRepository(project);
- ObjectInserter objectInserter = repository.newObjectInserter();
- RevWalk revWalk = new RevWalk(objectInserter.newReader())) {
- Instant now = TimeUtil.now();
-
- IdentifiedUser author = getAuthor(robotCommentCreation);
- RobotCommentAdditionOp robotCommentAdditionOp =
- new RobotCommentAdditionOp(robotCommentCreation);
- try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, author, now)) {
- batchUpdate.setRepository(repository, revWalk, objectInserter);
- batchUpdate.addOp(changeNotes.getChangeId(), robotCommentAdditionOp);
- batchUpdate.execute();
+ IdentifiedUser author = getAuthor(robotCommentCreation);
+ RobotCommentAdditionOp robotCommentAdditionOp =
+ new RobotCommentAdditionOp(robotCommentCreation);
+ try (BatchUpdate batchUpdate = batchUpdateFactory.create(project, author, now)) {
+ batchUpdate.setRepository(repository, revWalk, objectInserter);
+ batchUpdate.addOp(changeNotes.getChangeId(), robotCommentAdditionOp);
+ batchUpdate.execute();
+ }
+ return robotCommentAdditionOp.createdRobotCommentUuid;
}
- return robotCommentAdditionOp.createdRobotCommentUuid;
}
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/change/TestChangeCreation.java b/java/com/google/gerrit/acceptance/testsuite/change/TestChangeCreation.java
index a064d02..a0746e2 100644
--- a/java/com/google/gerrit/acceptance/testsuite/change/TestChangeCreation.java
+++ b/java/com/google/gerrit/acceptance/testsuite/change/TestChangeCreation.java
@@ -14,6 +14,8 @@
package com.google.gerrit.acceptance.testsuite.change;
+import static com.google.common.base.Preconditions.checkState;
+
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -24,6 +26,7 @@
import com.google.gerrit.server.edit.tree.TreeModification;
import java.util.Optional;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.merge.MergeStrategy;
/** Initial attributes of the change. If not provided, arbitrary values will be used. */
@@ -35,6 +38,14 @@
public abstract Optional<Account.Id> owner();
+ public abstract Optional<Account.Id> author();
+
+ public abstract Optional<PersonIdent> authorIdent();
+
+ public abstract Optional<Account.Id> committer();
+
+ public abstract Optional<PersonIdent> committerIdent();
+
public abstract Optional<String> topic();
public abstract ImmutableMap<String, Short> approvals();
@@ -69,9 +80,65 @@
*/
public abstract Builder branch(String branch);
- /** The change owner. Must be an existing user account. */
+ /**
+ * The change owner.
+ *
+ * <p>Must be an existing user account.
+ */
public abstract Builder owner(Account.Id owner);
+ /**
+ * The author of the commit for which the change is created.
+ *
+ * <p>Must be an existing user account.
+ *
+ * <p>Cannot be set together with {@link #authorIdent()} is set.
+ *
+ * <p>If neither {@link #author()} nor {@link #authorIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the author.
+ */
+ public abstract Builder author(Account.Id author);
+
+ /**
+ * The author ident of the commit for which the change is created.
+ *
+ * <p>Cannot be set together with {@link #author()} is set.
+ *
+ * <p>If neither {@link #author()} nor {@link #authorIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the author.
+ */
+ public abstract Builder authorIdent(PersonIdent authorIdent);
+
+ public abstract Optional<Account.Id> author();
+
+ public abstract Optional<PersonIdent> authorIdent();
+
+ /**
+ * The committer of the commit for which the change is created.
+ *
+ * <p>Must be an existing user account.
+ *
+ * <p>Cannot be set together with {@link #committerIdent()} is set.
+ *
+ * <p>If neither {@link #committer()} nor {@link #committerIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the committer.
+ */
+ public abstract Builder committer(Account.Id committer);
+
+ /**
+ * The committer ident of the commit for which the change is created.
+ *
+ * <p>Cannot be set together with {@link #committer()} is set.
+ *
+ * <p>If neither {@link #committer()} nor {@link #committerIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the committer.
+ */
+ public abstract Builder committerIdent(PersonIdent committerIdent);
+
+ public abstract Optional<Account.Id> committer();
+
+ public abstract Optional<PersonIdent> committerIdent();
+
/** The topic to add this change to. */
public abstract Builder topic(String topic);
@@ -89,7 +156,18 @@
/** Modified file of the change. The file content is specified via the returned builder. */
public FileContentBuilder<Builder> file(String filePath) {
- return new FileContentBuilder<>(this, filePath, treeModificationsBuilder()::add);
+ return new FileContentBuilder<>(this, filePath, 0, treeModificationsBuilder()::add);
+ }
+
+ /**
+ * Modified file of the change. The file content is specified via the returned builder. The
+ * second parameter indicates the git file mode for the modified file if it has been changed.
+ *
+ * @see org.eclipse.jgit.lib.FileMode
+ */
+ public FileContentBuilder<Builder> file(String filePath, int newGitFileMode) {
+ return new FileContentBuilder<>(
+ this, filePath, newGitFileMode, treeModificationsBuilder()::add);
}
abstract ImmutableList.Builder<TreeModification> treeModificationsBuilder();
@@ -145,13 +223,23 @@
abstract TestChangeCreation autoBuild();
+ public TestChangeCreation build() {
+ checkState(
+ author().isEmpty() || authorIdent().isEmpty(),
+ "author and authorIdent cannot be set together");
+ checkState(
+ committer().isEmpty() || committerIdent().isEmpty(),
+ "committer and committerIdent cannot be set together");
+ return autoBuild();
+ }
+
/**
* Creates the change.
*
* @return the {@code Change.Id} of the created change
*/
public Change.Id create() {
- TestChangeCreation changeUpdate = autoBuild();
+ TestChangeCreation changeUpdate = build();
return changeUpdate.changeCreator().applyAndThrowSilently(changeUpdate);
}
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/change/TestPatchsetCreation.java b/java/com/google/gerrit/acceptance/testsuite/change/TestPatchsetCreation.java
index fe9d909..f8ca977 100644
--- a/java/com/google/gerrit/acceptance/testsuite/change/TestPatchsetCreation.java
+++ b/java/com/google/gerrit/acceptance/testsuite/change/TestPatchsetCreation.java
@@ -14,17 +14,31 @@
package com.google.gerrit.acceptance.testsuite.change;
+import static com.google.common.base.Preconditions.checkState;
+
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
+import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.server.edit.tree.TreeModification;
import java.util.Optional;
+import org.eclipse.jgit.lib.PersonIdent;
/** Initial attributes of the patchset. If not provided, arbitrary values will be used. */
@AutoValue
public abstract class TestPatchsetCreation {
+ public abstract Optional<Account.Id> uploader();
+
+ public abstract Optional<Account.Id> author();
+
+ public abstract Optional<PersonIdent> authorIdent();
+
+ public abstract Optional<Account.Id> committer();
+
+ public abstract Optional<PersonIdent> committerIdent();
+
public abstract Optional<String> commitMessage();
public abstract ImmutableList<TreeModification> treeModifications();
@@ -40,12 +54,78 @@
@AutoValue.Builder
public abstract static class Builder {
+ /**
+ * The uploader for the new patch set.
+ *
+ * <p>Must be an existing user account.
+ *
+ * <p>If not set the new patch set is uploaded by the change owner.
+ */
+ public abstract Builder uploader(Account.Id uploader);
+
+ /**
+ * The author of the commit for which the change is created.
+ *
+ * <p>Must be an existing user account.
+ *
+ * <p>Cannot be set together with {@link #authorIdent()} is set.
+ *
+ * <p>If neither {@link #author()} nor {@link #authorIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the author.
+ */
+ public abstract Builder author(Account.Id author);
+
+ /**
+ * The author ident of the commit for which the change is created.
+ *
+ * <p>Cannot be set together with {@link #author()} is set.
+ *
+ * <p>If neither {@link #author()} nor {@link #authorIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the author.
+ */
+ public abstract Builder authorIdent(PersonIdent authorIdent);
+
+ public abstract Optional<Account.Id> author();
+
+ public abstract Optional<PersonIdent> authorIdent();
+
+ /**
+ * The committer of the commit for which the change is created.
+ *
+ * <p>Must be an existing user account.
+ *
+ * <p>Cannot be set together with {@link #committerIdent()} is set.
+ *
+ * <p>If neither {@link #committer()} nor {@link #committerIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the committer.
+ */
+ public abstract Builder committer(Account.Id committer);
+
+ /**
+ * The committer ident of the commit for which the change is created.
+ *
+ * <p>Cannot be set together with {@link #committer()} is set.
+ *
+ * <p>If neither {@link #committer()} nor {@link #committerIdent()} is set the {@link
+ * TestChangeCreation#owner()} is used as the committer.
+ */
+ public abstract Builder committerIdent(PersonIdent committerIdent);
+
+ public abstract Optional<Account.Id> committer();
+
+ public abstract Optional<PersonIdent> committerIdent();
public abstract Builder commitMessage(String commitMessage);
/** Modified file of the patchset. The file content is specified via the returned builder. */
public FileContentBuilder<Builder> file(String filePath) {
- return new FileContentBuilder<>(this, filePath, treeModificationsBuilder()::add);
+ return new FileContentBuilder<>(this, filePath, 0, treeModificationsBuilder()::add);
+ }
+
+ /** Modified file of the patchset. The file content is specified via the returned builder. */
+ public FileContentBuilder<Builder> file(String filePath, int newGitFileMode) {
+ return new FileContentBuilder<>(
+ this, filePath, newGitFileMode, treeModificationsBuilder()::add);
}
abstract ImmutableList.Builder<TreeModification> treeModificationsBuilder();
@@ -86,13 +166,23 @@
abstract TestPatchsetCreation autoBuild();
+ public TestPatchsetCreation build() {
+ checkState(
+ author().isEmpty() || authorIdent().isEmpty(),
+ "author and authorIdent cannot be set together");
+ checkState(
+ committer().isEmpty() || committerIdent().isEmpty(),
+ "committer and committerIdent cannot be set together");
+ return autoBuild();
+ }
+
/**
* Creates the patchset.
*
* @return the {@code PatchSet.Id} of the created patchset
*/
public PatchSet.Id create() {
- TestPatchsetCreation patchsetCreation = autoBuild();
+ TestPatchsetCreation patchsetCreation = build();
return patchsetCreation.patchsetCreator().applyAndThrowSilently(patchsetCreation);
}
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/group/BUILD b/java/com/google/gerrit/acceptance/testsuite/group/BUILD
index d4f1175..2052105 100644
--- a/java/com/google/gerrit/acceptance/testsuite/group/BUILD
+++ b/java/com/google/gerrit/acceptance/testsuite/group/BUILD
@@ -14,6 +14,7 @@
"//java/com/google/gerrit/exceptions",
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/server",
+ "//java/com/google/gerrit/testing:test-ref-update-context",
"//lib:guava",
"//lib:jgit",
"//lib:jgit-junit",
diff --git a/java/com/google/gerrit/acceptance/testsuite/group/TestGroupCreation.java b/java/com/google/gerrit/acceptance/testsuite/group/TestGroupCreation.java
index 8bb7b23..99899cf 100644
--- a/java/com/google/gerrit/acceptance/testsuite/group/TestGroupCreation.java
+++ b/java/com/google/gerrit/acceptance/testsuite/group/TestGroupCreation.java
@@ -14,6 +14,8 @@
package com.google.gerrit.acceptance.testsuite.group;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
+
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@@ -106,7 +108,7 @@
*/
public AccountGroup.UUID create() {
TestGroupCreation groupCreation = autoBuild();
- return groupCreation.groupCreator().applyAndThrowSilently(groupCreation);
+ return testRefAction(() -> groupCreation.groupCreator().applyAndThrowSilently(groupCreation));
}
}
}
diff --git a/java/com/google/gerrit/acceptance/testsuite/project/BUILD b/java/com/google/gerrit/acceptance/testsuite/project/BUILD
index 850a133..4ac2705 100644
--- a/java/com/google/gerrit/acceptance/testsuite/project/BUILD
+++ b/java/com/google/gerrit/acceptance/testsuite/project/BUILD
@@ -4,14 +4,17 @@
java_library(
name = "project",
+ testonly = True,
srcs = glob(["*.java"]),
visibility = ["//visibility:public"],
deps = [
"//java/com/google/gerrit/acceptance:function",
+ "//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/common:server",
"//java/com/google/gerrit/entities",
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/server",
+ "//java/com/google/gerrit/testing:test-ref-update-context",
"//lib:guava",
"//lib:jgit",
"//lib:jgit-junit",
diff --git a/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java b/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java
index deeb843..bd3d656 100644
--- a/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java
+++ b/java/com/google/gerrit/acceptance/testsuite/project/ProjectOperationsImpl.java
@@ -17,6 +17,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.gerrit.entities.RefNames.REFS_CONFIG;
import static com.google.gerrit.server.project.ProjectConfig.PROJECT_CONFIG;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.openTestRefUpdateContext;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
@@ -26,6 +27,7 @@
import com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.TestCapability;
import com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.TestLabelPermission;
import com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.TestPermission;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.AccessSection;
import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.entities.GroupReference;
@@ -40,6 +42,7 @@
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectConfig;
import com.google.gerrit.server.project.ProjectCreator;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import com.google.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
@@ -135,19 +138,21 @@
private void updateProject(TestProjectUpdate projectUpdate)
throws IOException, ConfigInvalidException {
- try (MetaDataUpdate metaDataUpdate = metaDataUpdateFactory.create(nameKey)) {
- ProjectConfig projectConfig = projectConfigFactory.read(metaDataUpdate);
- if (projectUpdate.removeAllAccessSections()) {
- projectConfig.getAccessSections().forEach(as -> projectConfig.remove(as));
+ try (RefUpdateContext ctx = openTestRefUpdateContext()) {
+ try (MetaDataUpdate metaDataUpdate = metaDataUpdateFactory.create(nameKey)) {
+ ProjectConfig projectConfig = projectConfigFactory.read(metaDataUpdate);
+ if (projectUpdate.removeAllAccessSections()) {
+ projectConfig.getAccessSections().forEach(as -> projectConfig.remove(as));
+ }
+ removePermissions(projectConfig, projectUpdate.removedPermissions());
+ addCapabilities(projectConfig, projectUpdate.addedCapabilities());
+ addPermissions(projectConfig, projectUpdate.addedPermissions());
+ addLabelPermissions(projectConfig, projectUpdate.addedLabelPermissions());
+ setExclusiveGroupPermissions(projectConfig, projectUpdate.exclusiveGroupPermissions());
+ projectConfig.commit(metaDataUpdate);
}
- removePermissions(projectConfig, projectUpdate.removedPermissions());
- addCapabilities(projectConfig, projectUpdate.addedCapabilities());
- addPermissions(projectConfig, projectUpdate.addedPermissions());
- addLabelPermissions(projectConfig, projectUpdate.addedLabelPermissions());
- setExclusiveGroupPermissions(projectConfig, projectUpdate.exclusiveGroupPermissions());
- projectConfig.commit(metaDataUpdate);
+ projectCache.evictAndReindex(nameKey);
}
- projectCache.evictAndReindex(nameKey);
}
private void removePermissions(
@@ -196,8 +201,13 @@
PermissionRule.Builder rule = newRule(projectConfig, p.group());
rule.setAction(p.action());
rule.setRange(p.min(), p.max());
- String permissionName =
- p.impersonation() ? Permission.forLabelAs(p.name()) : Permission.forLabel(p.name());
+ String permissionName;
+ if (p.isAddPermission()) {
+ permissionName =
+ p.impersonation() ? Permission.forLabelAs(p.name()) : Permission.forLabel(p.name());
+ } else {
+ permissionName = Permission.forRemoveLabel(p.name());
+ }
projectConfig.upsertAccessSection(
p.ref(), as -> as.upsertPermission(permissionName).add(rule));
}
@@ -213,6 +223,7 @@
as -> as.upsertPermission(key.name()).setExclusiveGroup(exclusive)));
}
+ @Nullable
private RevCommit headOrNull(String branch) {
branch = RefNames.fullName(branch);
diff --git a/java/com/google/gerrit/acceptance/testsuite/project/TestProjectUpdate.java b/java/com/google/gerrit/acceptance/testsuite/project/TestProjectUpdate.java
index 9a9a21a..5634c78 100644
--- a/java/com/google/gerrit/acceptance/testsuite/project/TestProjectUpdate.java
+++ b/java/com/google/gerrit/acceptance/testsuite/project/TestProjectUpdate.java
@@ -162,12 +162,34 @@
/** Starts a builder for allowing a label permission. */
public static TestLabelPermission.Builder allowLabel(String name) {
- return TestLabelPermission.builder().name(name).action(PermissionRule.Action.ALLOW);
+ return TestLabelPermission.builder()
+ .name(name)
+ .isAddPermission(true)
+ .action(PermissionRule.Action.ALLOW);
}
/** Starts a builder for denying a label permission. */
public static TestLabelPermission.Builder blockLabel(String name) {
- return TestLabelPermission.builder().name(name).action(PermissionRule.Action.BLOCK);
+ return TestLabelPermission.builder()
+ .name(name)
+ .isAddPermission(true)
+ .action(PermissionRule.Action.BLOCK);
+ }
+
+ /** Starts a builder for allowing a remove-label permission. */
+ public static TestLabelPermission.Builder allowLabelRemoval(String name) {
+ return TestLabelPermission.builder()
+ .name(name)
+ .isAddPermission(false)
+ .action(PermissionRule.Action.ALLOW);
+ }
+
+ /** Starts a builder for denying a remove-label permission. */
+ public static TestLabelPermission.Builder blockLabelRemoval(String name) {
+ return TestLabelPermission.builder()
+ .name(name)
+ .isAddPermission(false)
+ .action(PermissionRule.Action.BLOCK);
}
/** Records a label permission to be updated. */
@@ -191,6 +213,8 @@
abstract boolean impersonation();
+ abstract boolean isAddPermission();
+
/** Builder for {@link TestLabelPermission}. */
@AutoValue.Builder
public abstract static class Builder {
@@ -208,6 +232,8 @@
abstract Builder max(int max);
+ abstract Builder isAddPermission(boolean isAddPermission);
+
/** Sets the minimum and maximum values for the permission. */
public Builder range(int min, int max) {
checkArgument(min != 0 || max != 0, "empty range");
@@ -243,6 +269,12 @@
return TestPermissionKey.builder().name(Permission.forLabel(name));
}
+ /** Starts a builder for describing a label removal permission key for deletion. */
+ public static TestPermissionKey.Builder labelRemovalPermissionKey(String name) {
+ checkLabelName(name);
+ return TestPermissionKey.builder().name(Permission.forRemoveLabel(name));
+ }
+
/** Starts a builder for describing a capability key for deletion. */
public static TestPermissionKey.Builder capabilityKey(String name) {
return TestPermissionKey.builder().name(name).section(GLOBAL_CAPABILITIES);
diff --git a/java/com/google/gerrit/auth/ldap/FakeLdapGroupBackend.java b/java/com/google/gerrit/auth/ldap/FakeLdapGroupBackend.java
index 8fb4d35..c40baba 100644
--- a/java/com/google/gerrit/auth/ldap/FakeLdapGroupBackend.java
+++ b/java/com/google/gerrit/auth/ldap/FakeLdapGroupBackend.java
@@ -39,6 +39,7 @@
return uuid.get().startsWith(LDAP_UUID);
}
+ @Nullable
@Override
public GroupDescription.Basic get(AccountGroup.UUID uuid) {
if (!handles(uuid)) {
diff --git a/java/com/google/gerrit/auth/ldap/Helper.java b/java/com/google/gerrit/auth/ldap/Helper.java
index a939c72..c11d045 100644
--- a/java/com/google/gerrit/auth/ldap/Helper.java
+++ b/java/com/google/gerrit/auth/ldap/Helper.java
@@ -18,6 +18,7 @@
import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.metrics.Description;
@@ -224,6 +225,7 @@
return ctx;
}
+ @Nullable
private DirContext kerberosOpen(Properties env)
throws IOException, LoginException, NamingException {
LoginContext ctx = new LoginContext("KerberosLogin");
diff --git a/java/com/google/gerrit/auth/ldap/LdapGroupBackend.java b/java/com/google/gerrit/auth/ldap/LdapGroupBackend.java
index c3870f4..bb6480a 100644
--- a/java/com/google/gerrit/auth/ldap/LdapGroupBackend.java
+++ b/java/com/google/gerrit/auth/ldap/LdapGroupBackend.java
@@ -117,6 +117,7 @@
return isLdapUUID(uuid);
}
+ @Nullable
@Override
public GroupDescription.Basic get(AccountGroup.UUID uuid) {
if (!handles(uuid)) {
diff --git a/java/com/google/gerrit/auth/ldap/LdapQuery.java b/java/com/google/gerrit/auth/ldap/LdapQuery.java
index 409c9f5..71dc141 100644
--- a/java/com/google/gerrit/auth/ldap/LdapQuery.java
+++ b/java/com/google/gerrit/auth/ldap/LdapQuery.java
@@ -14,6 +14,7 @@
package com.google.gerrit.auth.ldap;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.metrics.Timer0;
import java.util.ArrayList;
@@ -114,6 +115,7 @@
return get("dn");
}
+ @Nullable
String get(String attName) throws NamingException {
final Attribute att = getAll(attName);
return att != null && 0 < att.size() ? String.valueOf(att.get(0)) : null;
diff --git a/java/com/google/gerrit/auth/ldap/LdapRealm.java b/java/com/google/gerrit/auth/ldap/LdapRealm.java
index 7699799..7dc2b1b 100644
--- a/java/com/google/gerrit/auth/ldap/LdapRealm.java
+++ b/java/com/google/gerrit/auth/ldap/LdapRealm.java
@@ -20,6 +20,7 @@
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AccountGroup;
@@ -162,6 +163,7 @@
return vlist;
}
+ @Nullable
static String optdef(Config c, String n, String d) {
final String[] v = c.getStringList("ldap", null, n);
if (v == null || v.length == 0) {
@@ -184,6 +186,7 @@
return v;
}
+ @Nullable
static ParameterizedString paramString(Config c, String n, String d) {
String expression = optdef(c, n, d);
if (expression == null) {
@@ -209,6 +212,7 @@
return !readOnlyAccountFields.contains(field);
}
+ @Nullable
static String apply(ParameterizedString p, LdapQuery.Result m) throws NamingException {
if (p == null) {
return null;
@@ -306,6 +310,7 @@
usernameCache.put(who.getLocalUser(), Optional.of(account.id()));
}
+ @Nullable
@Override
public Account.Id lookup(String accountName) {
if (Strings.isNullOrEmpty(accountName)) {
diff --git a/java/com/google/gerrit/auth/oauth/OAuthTokenCache.java b/java/com/google/gerrit/auth/oauth/OAuthTokenCache.java
index b0c1f51..ab53cde 100644
--- a/java/com/google/gerrit/auth/oauth/OAuthTokenCache.java
+++ b/java/com/google/gerrit/auth/oauth/OAuthTokenCache.java
@@ -20,6 +20,7 @@
import com.google.common.base.Converter;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.auth.oauth.OAuthToken;
import com.google.gerrit.extensions.auth.oauth.OAuthTokenEncrypter;
@@ -109,6 +110,7 @@
this.encrypter = encrypter;
}
+ @Nullable
public OAuthToken get(Account.Id id) {
OAuthToken accessToken = cache.getIfPresent(id);
if (accessToken == null) {
diff --git a/java/com/google/gerrit/common/PageLinks.java b/java/com/google/gerrit/common/PageLinks.java
index 38de5b1..836eb32 100644
--- a/java/com/google/gerrit/common/PageLinks.java
+++ b/java/com/google/gerrit/common/PageLinks.java
@@ -106,10 +106,6 @@
return toChangeQuery(op("owner", fullname) + " " + status(status));
}
- public static String toAssigneeQuery(String fullname) {
- return toChangeQuery(op("assignee", fullname));
- }
-
public static String toCustomDashboard(String params) {
return "/dashboard/?" + params;
}
diff --git a/java/com/google/gerrit/common/RawInputUtil.java b/java/com/google/gerrit/common/RawInputUtil.java
index 4a676e6..23e4a23 100644
--- a/java/com/google/gerrit/common/RawInputUtil.java
+++ b/java/com/google/gerrit/common/RawInputUtil.java
@@ -14,7 +14,6 @@
package com.google.gerrit.common;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
@@ -31,7 +30,6 @@
public static RawInput create(byte[] bytes, String contentType) {
requireNonNull(bytes);
- checkArgument(bytes.length > 0);
return new RawInput() {
@Override
public InputStream getInputStream() throws IOException {
diff --git a/java/com/google/gerrit/common/UsedAt.java b/java/com/google/gerrit/common/UsedAt.java
index 6a482fb..46b43c6 100644
--- a/java/com/google/gerrit/common/UsedAt.java
+++ b/java/com/google/gerrit/common/UsedAt.java
@@ -46,7 +46,8 @@
PLUGIN_SERVICEUSER,
PLUGIN_PULL_REPLICATION,
PLUGIN_WEBSESSION_FLATFILE,
- MODULE_GIT_REFS_FILTER
+ MODULE_GIT_REFS_FILTER,
+ MODULE_VIRTUALHOST
}
/** Reference to the project that uses the method annotated with this annotation. */
diff --git a/java/com/google/gerrit/common/data/GlobalCapability.java b/java/com/google/gerrit/common/data/GlobalCapability.java
index 253266d..23151c2 100644
--- a/java/com/google/gerrit/common/data/GlobalCapability.java
+++ b/java/com/google/gerrit/common/data/GlobalCapability.java
@@ -14,6 +14,7 @@
package com.google.gerrit.common.data;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Permission;
import com.google.gerrit.entities.PermissionRange;
import java.util.ArrayList;
@@ -21,6 +22,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
/**
* Server wide capabilities. Represented as {@link Permission} objects.
@@ -127,6 +129,9 @@
/** Can view all pending tasks in the queue (not just the filtered set). */
public static final String VIEW_QUEUE = "viewQueue";
+ /** Can view secondary emails of other accounts. */
+ public static final String VIEW_SECONDARY_EMAILS = "viewSecondaryEmails";
+
private static final List<String> NAMES_ALL;
private static final List<String> NAMES_LC;
private static final String[] RANGE_NAMES = {
@@ -158,10 +163,11 @@
NAMES_ALL.add(VIEW_CONNECTIONS);
NAMES_ALL.add(VIEW_PLUGINS);
NAMES_ALL.add(VIEW_QUEUE);
+ NAMES_ALL.add(VIEW_SECONDARY_EMAILS);
NAMES_LC = new ArrayList<>(NAMES_ALL.size());
for (String name : NAMES_ALL) {
- NAMES_LC.add(name.toLowerCase());
+ NAMES_LC.add(name.toLowerCase(Locale.US));
}
}
@@ -172,7 +178,7 @@
/** Returns true if the name is recognized as a capability name. */
public static boolean isGlobalCapability(String varName) {
- return NAMES_LC.contains(varName.toLowerCase());
+ return NAMES_LC.contains(varName.toLowerCase(Locale.US));
}
/** Returns true if the capability should have a range attached. */
@@ -190,6 +196,7 @@
}
/** Returns the valid range for the capability if it has one, otherwise null. */
+ @Nullable
public static PermissionRange.WithDefaults getRange(String varName) {
if (QUERY_LIMIT.equalsIgnoreCase(varName)) {
return new PermissionRange.WithDefaults(
diff --git a/java/com/google/gerrit/common/data/ParameterizedString.java b/java/com/google/gerrit/common/data/ParameterizedString.java
index 84bb535..c8c2b2b 100644
--- a/java/com/google/gerrit/common/data/ParameterizedString.java
+++ b/java/com/google/gerrit/common/data/ParameterizedString.java
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
/** Performs replacements on strings such as <code>Hello ${user}</code>. */
@@ -213,7 +214,7 @@
new Function() {
@Override
String apply(String a) {
- return a.toLowerCase();
+ return a.toLowerCase(Locale.US);
}
});
m.put(
@@ -221,7 +222,7 @@
new Function() {
@Override
String apply(String a) {
- return a.toUpperCase();
+ return a.toUpperCase(Locale.US);
}
});
m.put(
diff --git a/java/com/google/gerrit/entities/Account.java b/java/com/google/gerrit/entities/Account.java
index 85dbdeb..699acc0 100644
--- a/java/com/google/gerrit/entities/Account.java
+++ b/java/com/google/gerrit/entities/Account.java
@@ -62,6 +62,7 @@
return Optional.ofNullable(Ints.tryParse(str)).map(Account::id);
}
+ @Nullable
public static Id fromRef(String name) {
if (name == null) {
return null;
@@ -82,11 +83,13 @@
* @param name a ref name with the following syntax: {@code "34/1234..."}. We assume that the
* caller has trimmed any prefix.
*/
+ @Nullable
public static Id fromRefPart(String name) {
Integer id = RefNames.parseShardedRefPart(name);
return id != null ? Account.id(id) : null;
}
+ @Nullable
public static Id parseAfterShardedRefPart(String name) {
Integer id = RefNames.parseAfterShardedRefPart(name);
return id != null ? Account.id(id) : null;
@@ -102,6 +105,7 @@
* @param name ref name
* @return account ID, or null if not numeric.
*/
+ @Nullable
public static Id fromRefSuffix(String name) {
Integer id = RefNames.parseRefSuffix(name);
return id != null ? Account.id(id) : null;
diff --git a/java/com/google/gerrit/entities/AccountGroup.java b/java/com/google/gerrit/entities/AccountGroup.java
index 001a544..b5c97da 100644
--- a/java/com/google/gerrit/entities/AccountGroup.java
+++ b/java/com/google/gerrit/entities/AccountGroup.java
@@ -15,6 +15,7 @@
package com.google.gerrit.entities;
import com.google.auto.value.AutoValue;
+import com.google.gerrit.common.Nullable;
public final class AccountGroup {
public static NameKey nameKey(String n) {
@@ -65,6 +66,7 @@
}
/** Parse an {@link AccountGroup.UUID} out of a ref-name. */
+ @Nullable
public static UUID fromRef(String ref) {
if (ref == null) {
return null;
@@ -81,6 +83,7 @@
* @param refPart a ref name with the following syntax: {@code "12/1234..."}. We assume that the
* caller has trimmed any prefix.
*/
+ @Nullable
public static UUID fromRefPart(String refPart) {
String uuid = RefNames.parseShardedUuidFromRefPart(refPart);
return uuid != null ? AccountGroup.uuid(uuid) : null;
diff --git a/java/com/google/gerrit/entities/Address.java b/java/com/google/gerrit/entities/Address.java
index 5d63476..eb1da46 100644
--- a/java/com/google/gerrit/entities/Address.java
+++ b/java/com/google/gerrit/entities/Address.java
@@ -46,6 +46,7 @@
throw new IllegalArgumentException("Invalid email address: " + in);
}
+ @Nullable
public static Address tryParse(String in) {
try {
return parse(in);
diff --git a/java/com/google/gerrit/entities/BooleanProjectConfig.java b/java/com/google/gerrit/entities/BooleanProjectConfig.java
index 5201f6d..09f63d4 100644
--- a/java/com/google/gerrit/entities/BooleanProjectConfig.java
+++ b/java/com/google/gerrit/entities/BooleanProjectConfig.java
@@ -14,6 +14,8 @@
package com.google.gerrit.entities;
+import com.google.gerrit.common.Nullable;
+
/**
* Contains all inheritable boolean project configs and maps internal representations to API
* objects.
@@ -41,7 +43,9 @@
ENABLE_REVIEWER_BY_EMAIL("reviewer", "enableByEmail"),
MATCH_AUTHOR_TO_COMMITTER_DATE("submit", "matchAuthorToCommitterDate"),
REJECT_EMPTY_COMMIT("submit", "rejectEmptyCommit"),
- WORK_IN_PROGRESS_BY_DEFAULT("change", "workInProgressByDefault");
+ WORK_IN_PROGRESS_BY_DEFAULT("change", "workInProgressByDefault"),
+ SKIP_ADDING_AUTHOR_AND_COMMITTER_AS_REVIEWERS(
+ "reviewer", "skipAddingAuthorAndCommitterAsReviewers");
// Git config
private final String section;
@@ -56,6 +60,7 @@
return section;
}
+ @Nullable
public String getSubSection() {
return null;
}
diff --git a/java/com/google/gerrit/entities/Change.java b/java/com/google/gerrit/entities/Change.java
index 66e1a96..56fb748 100644
--- a/java/com/google/gerrit/entities/Change.java
+++ b/java/com/google/gerrit/entities/Change.java
@@ -117,6 +117,7 @@
return id != null ? Optional.of(Change.id(id)) : Optional.empty();
}
+ @Nullable
public static Id fromRef(String ref) {
if (RefNames.isRefsEdit(ref)) {
return fromEditRefPart(ref);
@@ -134,6 +135,7 @@
return null;
}
+ @Nullable
public static Id fromAllUsersRef(String ref) {
if (ref == null) {
return null;
@@ -169,6 +171,7 @@
return true;
}
+ @Nullable
public static Id fromEditRefPart(String ref) {
int startChangeId = ref.indexOf(RefNames.EDIT_PREFIX) + RefNames.EDIT_PREFIX.length();
int endChangeId = nextNonDigit(ref, startChangeId);
@@ -179,6 +182,7 @@
return null;
}
+ @Nullable
public static Id fromRefPart(String ref) {
Integer id = RefNames.parseShardedRefPart(ref);
return id != null ? Change.id(id) : null;
@@ -404,6 +408,7 @@
return changeStatus;
}
+ @Nullable
public static Status forCode(char c) {
for (Status s : Status.values()) {
if (s.code == c) {
@@ -414,6 +419,7 @@
return null;
}
+ @Nullable
public static Status forChangeStatus(ChangeStatus cs) {
for (Status s : Status.values()) {
if (s.changeStatus == cs) {
@@ -471,9 +477,6 @@
*/
@Nullable private String submissionId;
- /** Allows assigning a change to a user. */
- @Nullable private Account.Id assignee;
-
/** Whether the change is private. */
private boolean isPrivate;
@@ -503,7 +506,6 @@
}
public Change(Change other) {
- assignee = other.assignee;
changeId = other.changeId;
changeKey = other.changeKey;
createdOn = other.createdOn;
@@ -542,14 +544,6 @@
changeKey = k;
}
- public Account.Id getAssignee() {
- return assignee;
- }
-
- public void setAssignee(Account.Id a) {
- assignee = a;
- }
-
public Instant getCreatedOn() {
return createdOn;
}
@@ -599,6 +593,7 @@
}
/** Get the id of the most current {@link PatchSet} in this change. */
+ @Nullable
public PatchSet.Id currentPatchSetId() {
if (currentPatchSetId > 0) {
return PatchSet.id(changeId, currentPatchSetId);
diff --git a/java/com/google/gerrit/entities/Comment.java b/java/com/google/gerrit/entities/Comment.java
index 65a1559..e1e143c 100644
--- a/java/com/google/gerrit/entities/Comment.java
+++ b/java/com/google/gerrit/entities/Comment.java
@@ -49,6 +49,7 @@
return code;
}
+ @Nullable
public static Status forCode(char c) {
for (Status s : Status.values()) {
if (s.code == c) {
@@ -263,7 +264,7 @@
public void setLineNbrAndRange(
Integer lineNbr, com.google.gerrit.extensions.client.Comment.Range range) {
- this.lineNbr = lineNbr != null ? lineNbr : range != null ? range.endLine : 0;
+ this.lineNbr = range != null ? range.endLine : lineNbr != null ? lineNbr : 0;
if (range != null) {
this.range = new Comment.Range(range);
}
diff --git a/java/com/google/gerrit/entities/EmailHeader.java b/java/com/google/gerrit/entities/EmailHeader.java
index e43b6a3..d3710c4 100644
--- a/java/com/google/gerrit/entities/EmailHeader.java
+++ b/java/com/google/gerrit/entities/EmailHeader.java
@@ -115,8 +115,8 @@
byte[] buf = new String(Character.toChars(cp)).getBytes(UTF_8);
for (byte b : buf) {
r.append('=');
- r.append(Integer.toHexString((b >>> 4) & 0x0f).toUpperCase());
- r.append(Integer.toHexString(b & 0x0f).toUpperCase());
+ r.append(Integer.toHexString((b >>> 4) & 0x0f).toUpperCase(Locale.US));
+ r.append(Integer.toHexString(b & 0x0f).toUpperCase(Locale.US));
}
} else {
diff --git a/java/com/google/gerrit/entities/KeyUtil.java b/java/com/google/gerrit/entities/KeyUtil.java
index 0f14cd9..4aec7ac 100644
--- a/java/com/google/gerrit/entities/KeyUtil.java
+++ b/java/com/google/gerrit/entities/KeyUtil.java
@@ -66,7 +66,13 @@
return r.toString();
}
- public static String decode(final String key) {
+ public static String decode(String key) {
+ // URLs use percentage encoding which replaces unsafe ASCII characters with a '%' followed by
+ // two hexadecimal digits. If there is '%' that is not followed by two hexadecimal digits
+ // the code below fails with an IllegalArgumentException. To prevent this replace any '%'
+ // that is not followed by two hexadecimal digits by "%25", which is the URL encoding for '%'.
+ key = key.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
+
if (key.indexOf('%') < 0) {
return key.replace('+', ' ');
}
diff --git a/java/com/google/gerrit/entities/LabelFunction.java b/java/com/google/gerrit/entities/LabelFunction.java
index f361741..d49ab0f 100644
--- a/java/com/google/gerrit/entities/LabelFunction.java
+++ b/java/com/google/gerrit/entities/LabelFunction.java
@@ -14,6 +14,7 @@
package com.google.gerrit.entities;
+import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.SubmitRecord.Label;
import java.util.Collections;
@@ -48,6 +49,16 @@
ALL = Collections.unmodifiableMap(all);
}
+ public static final Map<String, LabelFunction> ALL_NON_DEPRECATED;
+
+ static {
+ Map<String, LabelFunction> allNonDeprecated = new LinkedHashMap<>();
+ for (LabelFunction f : ImmutableSet.of(NO_BLOCK, NO_OP, PATCH_SET_LOCK)) {
+ allNonDeprecated.put(f.getFunctionName(), f);
+ }
+ ALL_NON_DEPRECATED = Collections.unmodifiableMap(allNonDeprecated);
+ }
+
public static Optional<LabelFunction> parse(@Nullable String str) {
return Optional.ofNullable(ALL.get(str));
}
diff --git a/java/com/google/gerrit/entities/LabelType.java b/java/com/google/gerrit/entities/LabelType.java
index 0349a73..7a3266ecc 100644
--- a/java/com/google/gerrit/entities/LabelType.java
+++ b/java/com/google/gerrit/entities/LabelType.java
@@ -132,6 +132,7 @@
return psa.labelId().get().equalsIgnoreCase(getName());
}
+ @Nullable
public LabelValue getMin() {
if (getValues().isEmpty()) {
return null;
@@ -139,6 +140,7 @@
return getValues().get(0);
}
+ @Nullable
public LabelValue getMax() {
if (getValues().isEmpty()) {
return null;
diff --git a/java/com/google/gerrit/entities/LabelTypes.java b/java/com/google/gerrit/entities/LabelTypes.java
index a2f2e0b..fa7b741 100644
--- a/java/com/google/gerrit/entities/LabelTypes.java
+++ b/java/com/google/gerrit/entities/LabelTypes.java
@@ -19,6 +19,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
@@ -38,11 +39,11 @@
}
public Optional<LabelType> byLabel(LabelId labelId) {
- return Optional.ofNullable(byLabel().get(labelId.get().toLowerCase()));
+ return Optional.ofNullable(byLabel().get(labelId.get().toLowerCase(Locale.US)));
}
public Optional<LabelType> byLabel(String labelName) {
- return Optional.ofNullable(byLabel().get(labelName.toLowerCase()));
+ return Optional.ofNullable(byLabel().get(labelName.toLowerCase(Locale.US)));
}
private Map<String, LabelType> byLabel() {
@@ -52,7 +53,7 @@
Map<String, LabelType> l = new HashMap<>();
if (labelTypes != null) {
for (LabelType t : labelTypes) {
- l.put(t.getName().toLowerCase(), t);
+ l.put(t.getName().toLowerCase(Locale.US), t);
}
}
byLabel = l;
diff --git a/java/com/google/gerrit/entities/Patch.java b/java/com/google/gerrit/entities/Patch.java
index 2d28046..bef6580 100644
--- a/java/com/google/gerrit/entities/Patch.java
+++ b/java/com/google/gerrit/entities/Patch.java
@@ -19,6 +19,7 @@
import com.google.auto.value.AutoValue;
import com.google.common.base.Splitter;
import com.google.common.primitives.Ints;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.UsedAt;
import java.util.List;
@@ -112,6 +113,7 @@
}
@UsedAt(UsedAt.Project.COLLABNET)
+ @Nullable
public static ChangeType forCode(char c) {
for (ChangeType s : ChangeType.values()) {
if (s.code == c) {
@@ -168,33 +170,40 @@
*/
public enum FileMode implements CodedEnum {
/** Mode indicating an entry is a tree (aka directory). */
- TREE('T'),
+ TREE('T', 0040000),
/** Mode indicating an entry is a symbolic link. */
- SYMLINK('S'),
+ SYMLINK('S', 0120000),
/** Mode indicating an entry is a non-executable file. */
- REGULAR_FILE('R'),
+ REGULAR_FILE('R', 0100644),
/** Mode indicating an entry is an executable file. */
- EXECUTABLE_FILE('E'),
+ EXECUTABLE_FILE('E', 0100755),
/** Mode indicating an entry is a submodule commit in another repository. */
- GITLINK('G'),
+ GITLINK('G', 0160000),
/** Mode indicating an entry is missing during parallel walks. */
- MISSING('M');
+ MISSING('M', 0000000);
private final char code;
- FileMode(char c) {
+ private final int mode;
+
+ FileMode(char c, int m) {
code = c;
+ mode = m;
}
@Override
public char getCode() {
return code;
}
+
+ public int getMode() {
+ return mode;
+ }
}
private Patch() {}
diff --git a/java/com/google/gerrit/entities/PatchSet.java b/java/com/google/gerrit/entities/PatchSet.java
index 6c52368..8784437 100644
--- a/java/com/google/gerrit/entities/PatchSet.java
+++ b/java/com/google/gerrit/entities/PatchSet.java
@@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.InlineMe;
+import com.google.gerrit.common.Nullable;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
@@ -66,7 +67,7 @@
}
@AutoValue
- public abstract static class Id {
+ public abstract static class Id implements Comparable<Id> {
/** Parse a PatchSet.Id out of a string representation. */
public static Id parse(String str) {
List<String> parts = Splitter.on(',').splitToList(str);
@@ -83,6 +84,7 @@
}
/** Parse a PatchSet.Id from a {@link #refName()} result. */
+ @Nullable
public static Id fromRef(String ref) {
int cs = Change.Id.startIndex(ref);
if (cs < 0) {
@@ -145,6 +147,11 @@
public final String toString() {
return getCommaSeparatedChangeAndPatchSetId();
}
+
+ @Override
+ public int compareTo(Id other) {
+ return Ints.compare(get(), other.get());
+ }
}
public static Builder builder() {
@@ -163,6 +170,8 @@
public abstract Builder uploader(Account.Id uploader);
+ public abstract Builder realUploader(Account.Id realUploader);
+
public abstract Builder createdOn(Instant createdOn);
public abstract Builder groups(Iterable<String> groups);
@@ -197,6 +206,9 @@
/**
* Account that uploaded the patch set.
*
+ * <p>If the upload was done on behalf of another user, the impersonated user on whom's behalf the
+ * patch set was uploaded.
+ *
* <p>If this is a deserialized instance that was originally serialized by an older version of
* Gerrit, and the old data erroneously did not include an {@code uploader}, then this method will
* return an account ID of 0.
@@ -204,6 +216,15 @@
public abstract Account.Id uploader();
/**
+ * The real account that uploaded the patch set.
+ *
+ * <p>If this is a deserialized instance that was originally serialized by an older version of
+ * Gerrit, and the old data did not include an {@code realUploader}, then this method will return
+ * the {@code uploader}.
+ */
+ public abstract Account.Id realUploader();
+
+ /**
* When this patch set was first introduced onto the change.
*
* <p>If this is a deserialized instance that was originally serialized by an older version of
diff --git a/java/com/google/gerrit/entities/Permission.java b/java/com/google/gerrit/entities/Permission.java
index 95164bd..2a34579 100644
--- a/java/com/google/gerrit/entities/Permission.java
+++ b/java/com/google/gerrit/entities/Permission.java
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.function.Consumer;
/** A single permission within an {@link AccessSection} of a project. */
@@ -35,7 +36,6 @@
public static final String DELETE = "delete";
public static final String DELETE_CHANGES = "deleteChanges";
public static final String DELETE_OWN_CHANGES = "deleteOwnChanges";
- public static final String EDIT_ASSIGNEE = "editAssignee";
public static final String EDIT_HASHTAGS = "editHashtags";
public static final String EDIT_TOPIC_NAME = "editTopicName";
public static final String FORGE_AUTHOR = "forgeAuthor";
@@ -43,6 +43,7 @@
public static final String FORGE_SERVER = "forgeServerAsCommitter";
public static final String LABEL = "label-";
public static final String LABEL_AS = "labelAs-";
+ public static final String REMOVE_LABEL = "removeLabel-";
public static final String OWNER = "owner";
public static final String PUSH = "push";
public static final String PUSH_MERGE = "pushMerge";
@@ -60,48 +61,53 @@
private static final List<String> NAMES_LC;
private static final int LABEL_INDEX;
private static final int LABEL_AS_INDEX;
+ private static final int REMOVE_LABEL_INDEX;
static {
NAMES_LC = new ArrayList<>();
- NAMES_LC.add(ABANDON.toLowerCase());
- NAMES_LC.add(ADD_PATCH_SET.toLowerCase());
- NAMES_LC.add(CREATE.toLowerCase());
- NAMES_LC.add(CREATE_SIGNED_TAG.toLowerCase());
- NAMES_LC.add(CREATE_TAG.toLowerCase());
- NAMES_LC.add(DELETE.toLowerCase());
- NAMES_LC.add(DELETE_CHANGES.toLowerCase());
- NAMES_LC.add(DELETE_OWN_CHANGES.toLowerCase());
- NAMES_LC.add(EDIT_ASSIGNEE.toLowerCase());
- NAMES_LC.add(EDIT_HASHTAGS.toLowerCase());
- NAMES_LC.add(EDIT_TOPIC_NAME.toLowerCase());
- NAMES_LC.add(FORGE_AUTHOR.toLowerCase());
- NAMES_LC.add(FORGE_COMMITTER.toLowerCase());
- NAMES_LC.add(FORGE_SERVER.toLowerCase());
- NAMES_LC.add(LABEL.toLowerCase());
- NAMES_LC.add(LABEL_AS.toLowerCase());
- NAMES_LC.add(OWNER.toLowerCase());
- NAMES_LC.add(PUSH.toLowerCase());
- NAMES_LC.add(PUSH_MERGE.toLowerCase());
- NAMES_LC.add(READ.toLowerCase());
- NAMES_LC.add(REBASE.toLowerCase());
- NAMES_LC.add(REMOVE_REVIEWER.toLowerCase());
- NAMES_LC.add(REVERT.toLowerCase());
- NAMES_LC.add(SUBMIT.toLowerCase());
- NAMES_LC.add(SUBMIT_AS.toLowerCase());
- NAMES_LC.add(TOGGLE_WORK_IN_PROGRESS_STATE.toLowerCase());
- NAMES_LC.add(VIEW_PRIVATE_CHANGES.toLowerCase());
+ NAMES_LC.add(ABANDON.toLowerCase(Locale.US));
+ NAMES_LC.add(ADD_PATCH_SET.toLowerCase(Locale.US));
+ NAMES_LC.add(CREATE.toLowerCase(Locale.US));
+ NAMES_LC.add(CREATE_SIGNED_TAG.toLowerCase(Locale.US));
+ NAMES_LC.add(CREATE_TAG.toLowerCase(Locale.US));
+ NAMES_LC.add(DELETE.toLowerCase(Locale.US));
+ NAMES_LC.add(DELETE_CHANGES.toLowerCase(Locale.US));
+ NAMES_LC.add(DELETE_OWN_CHANGES.toLowerCase(Locale.US));
+ NAMES_LC.add(EDIT_HASHTAGS.toLowerCase(Locale.US));
+ NAMES_LC.add(EDIT_TOPIC_NAME.toLowerCase(Locale.US));
+ NAMES_LC.add(FORGE_AUTHOR.toLowerCase(Locale.US));
+ NAMES_LC.add(FORGE_COMMITTER.toLowerCase(Locale.US));
+ NAMES_LC.add(FORGE_SERVER.toLowerCase(Locale.US));
+ NAMES_LC.add(LABEL.toLowerCase(Locale.US));
+ NAMES_LC.add(LABEL_AS.toLowerCase(Locale.US));
+ NAMES_LC.add(REMOVE_LABEL.toLowerCase(Locale.US));
+ NAMES_LC.add(OWNER.toLowerCase(Locale.US));
+ NAMES_LC.add(PUSH.toLowerCase(Locale.US));
+ NAMES_LC.add(PUSH_MERGE.toLowerCase(Locale.US));
+ NAMES_LC.add(READ.toLowerCase(Locale.US));
+ NAMES_LC.add(REBASE.toLowerCase(Locale.US));
+ NAMES_LC.add(REMOVE_REVIEWER.toLowerCase(Locale.US));
+ NAMES_LC.add(REVERT.toLowerCase(Locale.US));
+ NAMES_LC.add(SUBMIT.toLowerCase(Locale.US));
+ NAMES_LC.add(SUBMIT_AS.toLowerCase(Locale.US));
+ NAMES_LC.add(TOGGLE_WORK_IN_PROGRESS_STATE.toLowerCase(Locale.US));
+ NAMES_LC.add(VIEW_PRIVATE_CHANGES.toLowerCase(Locale.US));
LABEL_INDEX = NAMES_LC.indexOf(Permission.LABEL);
- LABEL_AS_INDEX = NAMES_LC.indexOf(Permission.LABEL_AS.toLowerCase());
+ LABEL_AS_INDEX = NAMES_LC.indexOf(Permission.LABEL_AS.toLowerCase(Locale.US));
+ REMOVE_LABEL_INDEX = NAMES_LC.indexOf(Permission.REMOVE_LABEL.toLowerCase(Locale.US));
}
/** Returns true if the name is recognized as a permission name. */
public static boolean isPermission(String varName) {
- return isLabel(varName) || isLabelAs(varName) || NAMES_LC.contains(varName.toLowerCase());
+ return isLabel(varName)
+ || isLabelAs(varName)
+ || isRemoveLabel(varName)
+ || NAMES_LC.contains(varName.toLowerCase(Locale.US));
}
public static boolean hasRange(String varName) {
- return isLabel(varName) || isLabelAs(varName);
+ return isLabel(varName) || isLabelAs(varName) || isRemoveLabel(varName);
}
/** Returns true if the permission name is actually for a review label. */
@@ -114,6 +120,11 @@
return var.startsWith(LABEL_AS) && LABEL_AS.length() < var.length();
}
+ /** Returns true if the permission is for impersonated review labels. */
+ public static boolean isRemoveLabel(String var) {
+ return var.startsWith(REMOVE_LABEL) && REMOVE_LABEL.length() < var.length();
+ }
+
/** Returns permission name for the given review label. */
public static String forLabel(String labelName) {
return LABEL + labelName;
@@ -124,11 +135,19 @@
return LABEL_AS + labelName;
}
+ /** Returns permission name to remove a label for another user. */
+ public static String forRemoveLabel(String labelName) {
+ return REMOVE_LABEL + labelName;
+ }
+
+ @Nullable
public static String extractLabel(String varName) {
if (isLabel(varName)) {
return varName.substring(LABEL.length());
} else if (isLabelAs(varName)) {
return varName.substring(LABEL_AS.length());
+ } else if (isRemoveLabel(varName)) {
+ return varName.substring(REMOVE_LABEL.length());
}
return null;
}
@@ -204,9 +223,11 @@
return LABEL_INDEX;
} else if (isLabelAs(a.getName())) {
return LABEL_AS_INDEX;
+ } else if (isRemoveLabel(a.getName())) {
+ return REMOVE_LABEL_INDEX;
}
- int index = NAMES_LC.indexOf(a.getName().toLowerCase());
+ int index = NAMES_LC.indexOf(a.getName().toLowerCase(Locale.US));
return 0 <= index ? index : NAMES_LC.size();
}
@@ -277,7 +298,10 @@
public Permission build() {
setRules(
- rulesBuilders.stream().map(PermissionRule.Builder::build).collect(toImmutableList()));
+ rulesBuilders.stream()
+ .map(PermissionRule.Builder::build)
+ .distinct()
+ .collect(toImmutableList()));
return autoBuild();
}
diff --git a/java/com/google/gerrit/entities/PermissionRule.java b/java/com/google/gerrit/entities/PermissionRule.java
index 9a2d31e..1665c1c 100644
--- a/java/com/google/gerrit/entities/PermissionRule.java
+++ b/java/com/google/gerrit/entities/PermissionRule.java
@@ -202,6 +202,9 @@
int dotdot = range.indexOf("..");
int min = parseInt(range.substring(0, dotdot));
int max = parseInt(range.substring(dotdot + 2));
+ if (min > max) {
+ throw new IllegalArgumentException("Invalid range in rule: " + orig);
+ }
rule.setRange(min, max);
} else {
throw new IllegalArgumentException("Invalid range in rule: " + orig);
diff --git a/java/com/google/gerrit/entities/Project.java b/java/com/google/gerrit/entities/Project.java
index 617b827..72ca6a9 100644
--- a/java/com/google/gerrit/entities/Project.java
+++ b/java/com/google/gerrit/entities/Project.java
@@ -61,7 +61,7 @@
/** Parse a Project.NameKey out of a string representation. */
public static NameKey parse(String str) {
- return nameKey(KeyUtil.decode(str));
+ return nameKey(ProjectUtil.sanitizeProjectName(KeyUtil.decode(str)));
}
private final String name;
@@ -166,6 +166,7 @@
* @return name key of the parent project, {@code null} if this project is the All-Projects
* project
*/
+ @Nullable
public Project.NameKey getParent(Project.NameKey allProjectsName) {
if (getParent() != null) {
return getParent();
@@ -178,6 +179,7 @@
return allProjectsName;
}
+ @Nullable
public String getParentName() {
return getParent() != null ? getParent().get() : null;
}
diff --git a/java/com/google/gerrit/entities/ProjectUtil.java b/java/com/google/gerrit/entities/ProjectUtil.java
new file mode 100644
index 0000000..98ce67a
--- /dev/null
+++ b/java/com/google/gerrit/entities/ProjectUtil.java
@@ -0,0 +1,41 @@
+// Copyright (C) 2012 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.entities;
+
+public class ProjectUtil {
+ public static String sanitizeProjectName(String name) {
+ name = stripGitSuffix(name);
+ name = stripTrailingSlash(name);
+ return name;
+ }
+
+ public static String stripGitSuffix(String name) {
+ if (name.endsWith(".git")) {
+ // Be nice and drop the trailing ".git" suffix, which we never keep
+ // in our database, but clients might mistakenly provide anyway.
+ //
+ name = name.substring(0, name.length() - 4);
+ name = stripTrailingSlash(name);
+ }
+ return name;
+ }
+
+ private static String stripTrailingSlash(String name) {
+ while (name.endsWith("/")) {
+ name = name.substring(0, name.length() - 1);
+ }
+ return name;
+ }
+}
diff --git a/java/com/google/gerrit/entities/RefNames.java b/java/com/google/gerrit/entities/RefNames.java
index b9c1b3c..e79c530 100644
--- a/java/com/google/gerrit/entities/RefNames.java
+++ b/java/com/google/gerrit/entities/RefNames.java
@@ -16,6 +16,7 @@
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.UsedAt;
import java.util.List;
@@ -184,6 +185,21 @@
return ref.startsWith(REFS_CHANGES);
}
+ /** True if the provided ref is in {@code refs/sequences/*}. */
+ public static boolean isSequenceRef(String ref) {
+ return ref.startsWith(REFS_SEQUENCES);
+ }
+
+ /** True if the provided ref is in {@code refs/tags/*}. */
+ public static boolean isTagRef(String ref) {
+ return ref.startsWith(REFS_TAGS);
+ }
+
+ /** True if the provided ref is {@link #REFS_EXTERNAL_IDS}. */
+ public static boolean isExternalIdRef(String ref) {
+ return REFS_EXTERNAL_IDS.equals(ref);
+ }
+
public static String refsGroups(AccountGroup.UUID groupUuid) {
return REFS_GROUPS + shardUuid(groupUuid.get());
}
@@ -222,6 +238,7 @@
return REFS_CACHE_AUTOMERGE + hash.substring(0, 2) + '/' + hash.substring(2);
}
+ @Nullable
public static String shard(int id) {
if (id < 0) {
return null;
@@ -328,6 +345,21 @@
return REFS_CONFIG.equals(ref);
}
+ /** Whether the ref is the version branch, i.e. {@code refs/meta/version}. */
+ public static boolean isVersionRef(String ref) {
+ return REFS_VERSION.equals(ref);
+ }
+
+ /** Whether the ref is an auto-merge ref. */
+ public static boolean isAutoMergeRef(String ref) {
+ return ref.startsWith(REFS_CACHE_AUTOMERGE);
+ }
+
+ /** Whether the ref is an reject commit ref, i.e. {@code refs/meta/reject-commits} */
+ public static boolean isRejectCommitsRef(String ref) {
+ return REFS_REJECT_COMMITS.equals(ref);
+ }
+
/**
* Whether the ref is managed by Gerrit. Covers all Gerrit-internal refs like refs/cache-automerge
* and refs/meta as well as refs/changes. Does not cover user-created refs like branches or custom
@@ -343,6 +375,7 @@
return GERRIT_REFS.stream().anyMatch(internalRef -> ref.startsWith(internalRef));
}
+ @Nullable
static Integer parseShardedRefPart(String name) {
if (name == null) {
return null;
@@ -386,6 +419,7 @@
}
@UsedAt(UsedAt.Project.PLUGINS_ALL)
+ @Nullable
public static String parseShardedUuidFromRefPart(String name) {
if (name == null) {
return null;
@@ -420,6 +454,7 @@
* @return the rest of the name, {@code null} if the ref name part doesn't start with a valid
* sharded ID
*/
+ @Nullable
static String skipShardedRefPart(String name) {
if (name == null) {
return null;
@@ -473,6 +508,7 @@
* ref name part doesn't start with a valid sharded ID or if no valid ID follows the sharded
* ref part
*/
+ @Nullable
static Integer parseAfterShardedRefPart(String name) {
String rest = skipShardedRefPart(name);
if (rest == null || !rest.startsWith("/")) {
@@ -493,6 +529,7 @@
return Integer.parseInt(rest.substring(0, ie));
}
+ @Nullable
public static Integer parseRefSuffix(String name) {
if (name == null) {
return null;
diff --git a/java/com/google/gerrit/entities/StoredCommentLinkInfo.java b/java/com/google/gerrit/entities/StoredCommentLinkInfo.java
index 75bc034..5ee76da 100644
--- a/java/com/google/gerrit/entities/StoredCommentLinkInfo.java
+++ b/java/com/google/gerrit/entities/StoredCommentLinkInfo.java
@@ -31,7 +31,7 @@
public abstract String getMatch();
/**
- * The link to replace the match with. This can only be set if html is {@code null}.
+ * The link to replace the match with.
*
* <p>The constructed link is using {@link #getLink()} {@link #getPrefix()} {@link #getSuffix()}
* and {@link #getText()}, and has the shape of
@@ -41,31 +41,18 @@
@Nullable
public abstract String getLink();
- /**
- * The text before the link tag that the match is replaced with. This can only be set if link is
- * not {@code null}.
- */
+ /** The optional text before the link tag that the match is replaced with. */
@Nullable
public abstract String getPrefix();
- /**
- * The text after the link tag that the match is replaced with. This can only be set if link is
- * not {@code null}.
- */
+ /** The optional text after the link tag that the match is replaced with. */
@Nullable
public abstract String getSuffix();
- /**
- * The content of the link tag that the match is replaced with. This can only be set if link is
- * not {@code null}.
- */
+ /** The content of the link tag that the match is replaced with. If not set full match is used. */
@Nullable
public abstract String getText();
- /** The html to replace the match with. This can only be set if link is {@code null}. */
- @Nullable
- public abstract String getHtml();
-
/** Weather this comment link is active. {@code null} means true. */
@Nullable
public abstract Boolean getEnabled();
@@ -103,7 +90,6 @@
.setPrefix(src.prefix)
.setSuffix(src.suffix)
.setText(src.text)
- .setHtml(src.html)
.setEnabled(enabled)
.setOverrideOnly(false)
.build();
@@ -118,7 +104,6 @@
info.prefix = getPrefix();
info.suffix = getSuffix();
info.text = getText();
- info.html = getHtml();
info.enabled = getEnabled();
return info;
}
@@ -137,25 +122,21 @@
public abstract Builder setText(@Nullable String value);
- public abstract Builder setHtml(@Nullable String value);
-
public abstract Builder setEnabled(@Nullable Boolean value);
public abstract Builder setOverrideOnly(boolean value);
public StoredCommentLinkInfo build() {
checkArgument(getName() != null, "invalid commentlink.name");
- setLink(Strings.emptyToNull(getLink()));
setPrefix(Strings.emptyToNull(getPrefix()));
setSuffix(Strings.emptyToNull(getSuffix()));
setText(Strings.emptyToNull(getText()));
- setHtml(Strings.emptyToNull(getHtml()));
if (!getOverrideOnly()) {
checkArgument(
!Strings.isNullOrEmpty(getMatch()), "invalid commentlink.%s.match", getName());
checkArgument(
- (getLink() != null && getHtml() == null) || (getLink() == null && getHtml() != null),
- "commentlink.%s must have either link or html",
+ !Strings.isNullOrEmpty(getLink()),
+ "commentlink.%s must have link specified",
getName());
}
return autoBuild();
@@ -175,8 +156,6 @@
protected abstract String getText();
- protected abstract String getHtml();
-
protected abstract boolean getOverrideOnly();
}
}
diff --git a/java/com/google/gerrit/entities/SubmitRequirementExpressionResult.java b/java/com/google/gerrit/entities/SubmitRequirementExpressionResult.java
index c24227d..fbb2fd7 100644
--- a/java/com/google/gerrit/entities/SubmitRequirementExpressionResult.java
+++ b/java/com/google/gerrit/entities/SubmitRequirementExpressionResult.java
@@ -197,8 +197,6 @@
@AutoValue.Builder
public abstract static class Builder {
- public abstract Builder childPredicateResults(ImmutableList<PredicateResult> value);
-
protected abstract ImmutableList.Builder<PredicateResult> childPredicateResultsBuilder();
public abstract Builder predicateString(String value);
diff --git a/java/com/google/gerrit/entities/converter/ChangeProtoConverter.java b/java/com/google/gerrit/entities/converter/ChangeProtoConverter.java
index 4903364..3b772d0 100644
--- a/java/com/google/gerrit/entities/converter/ChangeProtoConverter.java
+++ b/java/com/google/gerrit/entities/converter/ChangeProtoConverter.java
@@ -71,10 +71,6 @@
if (submissionId != null) {
builder.setSubmissionId(submissionId);
}
- Account.Id assignee = change.getAssignee();
- if (assignee != null) {
- builder.setAssignee(accountIdConverter.toProto(assignee));
- }
Change.Id revertOf = change.getRevertOf();
if (revertOf != null) {
builder.setRevertOf(changeIdConverter.toProto(revertOf));
@@ -114,9 +110,6 @@
if (proto.hasSubmissionId()) {
change.setSubmissionId(proto.getSubmissionId());
}
- if (proto.hasAssignee()) {
- change.setAssignee(accountIdConverter.fromProto(proto.getAssignee()));
- }
change.setPrivate(proto.getIsPrivate());
change.setWorkInProgress(proto.getWorkInProgress());
change.setReviewStarted(proto.getReviewStarted());
diff --git a/java/com/google/gerrit/entities/converter/PatchSetProtoConverter.java b/java/com/google/gerrit/entities/converter/PatchSetProtoConverter.java
index 210972d..b32f09a 100644
--- a/java/com/google/gerrit/entities/converter/PatchSetProtoConverter.java
+++ b/java/com/google/gerrit/entities/converter/PatchSetProtoConverter.java
@@ -42,6 +42,7 @@
.setId(patchSetIdConverter.toProto(patchSet.id()))
.setCommitId(objectIdConverter.toProto(patchSet.commitId()))
.setUploaderAccountId(accountIdConverter.toProto(patchSet.uploader()))
+ .setRealUploaderAccountId(accountIdConverter.toProto(patchSet.realUploader()))
.setCreatedOn(patchSet.createdOn().toEpochMilli());
List<String> groups = patchSet.groups();
if (!groups.isEmpty()) {
@@ -75,15 +76,20 @@
// Callers that encounter one of these sentinels will likely fail, for example by failing to
// look up the zeroId. They would have also failed back when the fields were nullable, for
// example with NPE; the current behavior just fails slightly differently.
+ Account.Id uploader =
+ proto.hasUploaderAccountId()
+ ? accountIdConverter.fromProto(proto.getUploaderAccountId())
+ : Account.id(0);
builder
.commitId(
proto.hasCommitId()
? objectIdConverter.fromProto(proto.getCommitId())
: ObjectId.zeroId())
- .uploader(
- proto.hasUploaderAccountId()
- ? accountIdConverter.fromProto(proto.getUploaderAccountId())
- : Account.id(0))
+ .uploader(uploader)
+ .realUploader(
+ proto.hasRealUploaderAccountId()
+ ? accountIdConverter.fromProto(proto.getRealUploaderAccountId())
+ : uploader)
.createdOn(
proto.hasCreatedOn() ? Instant.ofEpochMilli(proto.getCreatedOn()) : Instant.EPOCH);
diff --git a/java/com/google/gerrit/extensions/api/changes/AssigneeInput.java b/java/com/google/gerrit/extensions/api/changes/ApplyPatchInput.java
similarity index 66%
rename from java/com/google/gerrit/extensions/api/changes/AssigneeInput.java
rename to java/com/google/gerrit/extensions/api/changes/ApplyPatchInput.java
index e17e1c9..493329c 100644
--- a/java/com/google/gerrit/extensions/api/changes/AssigneeInput.java
+++ b/java/com/google/gerrit/extensions/api/changes/ApplyPatchInput.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 The Android Open Source Project
+// Copyright (C) 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,8 +14,12 @@
package com.google.gerrit.extensions.api.changes;
-import com.google.gerrit.extensions.restapi.DefaultInput;
-
-public class AssigneeInput {
- @DefaultInput public String assignee;
+/** Information about a patch to apply. */
+public class ApplyPatchInput {
+ /**
+ * Required. The patch to be applied.
+ *
+ * <p>Must be compatible with `git diff` output. For example, Gerrit API `Get Patch` output.
+ */
+ public String patch;
}
diff --git a/java/com/google/gerrit/extensions/api/changes/ApplyPatchPatchSetInput.java b/java/com/google/gerrit/extensions/api/changes/ApplyPatchPatchSetInput.java
new file mode 100644
index 0000000..cf114df
--- /dev/null
+++ b/java/com/google/gerrit/extensions/api/changes/ApplyPatchPatchSetInput.java
@@ -0,0 +1,47 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.extensions.api.changes;
+
+import com.google.gerrit.common.Nullable;
+import com.google.gerrit.extensions.api.accounts.AccountInput;
+import com.google.gerrit.extensions.client.ListChangesOption;
+import java.util.List;
+
+/** Information for creating a new patch set from a given patch. */
+public class ApplyPatchPatchSetInput {
+
+ /** The patch to be applied. */
+ public ApplyPatchInput patch;
+
+ /**
+ * The commit message for the new patch set. If not specified, a predefined message will be used.
+ */
+ @Nullable public String commitMessage;
+
+ /**
+ * 40-hex digit SHA-1 of the commit which will be the parent commit of the newly created patch
+ * set. If set, it must be a merged commit or a change revision on the destination branch.
+ * Otherwise, the target change's branch tip will be used.
+ */
+ @Nullable public String base;
+
+ /**
+ * The author of the new patch set. Must include both {@link AccountInput#name} and {@link
+ * AccountInput#email} fields.
+ */
+ @Nullable public AccountInput author;
+
+ @Nullable public List<ListChangesOption> responseFormatOptions;
+}
diff --git a/java/com/google/gerrit/extensions/api/changes/ChangeApi.java b/java/com/google/gerrit/extensions/api/changes/ChangeApi.java
index 018a6cf..ef61b68 100644
--- a/java/com/google/gerrit/extensions/api/changes/ChangeApi.java
+++ b/java/com/google/gerrit/extensions/api/changes/ChangeApi.java
@@ -27,12 +27,14 @@
import com.google.gerrit.extensions.common.CommitMessageInput;
import com.google.gerrit.extensions.common.MergePatchSetInput;
import com.google.gerrit.extensions.common.PureRevertInfo;
+import com.google.gerrit.extensions.common.RebaseChainInfo;
import com.google.gerrit.extensions.common.RevertSubmissionInfo;
import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.common.SubmitRequirementInput;
import com.google.gerrit.extensions.common.SubmitRequirementResultInfo;
import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
import com.google.gerrit.extensions.restapi.NotImplementedException;
+import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import java.util.Arrays;
import java.util.Collection;
@@ -152,6 +154,8 @@
/** Create a merge patch set for the change. */
ChangeInfo createMergePatchSet(MergePatchSetInput in) throws RestApiException;
+ ChangeInfo applyPatch(ApplyPatchPatchSetInput in) throws RestApiException;
+
default List<ChangeInfo> submittedTogether() throws RestApiException {
SubmittedTogetherInfo info =
submittedTogether(
@@ -176,6 +180,24 @@
/** Rebase the current revision of a change. */
void rebase(RebaseInput in) throws RestApiException;
+ /**
+ * Rebase the current revisions of a change's chain using default options.
+ *
+ * @return a {@code RebaseChainInfo} contains the {@code ChangeInfo} data for the rebased the
+ * chain
+ */
+ default Response<RebaseChainInfo> rebaseChain() throws RestApiException {
+ return rebaseChain(new RebaseInput());
+ }
+
+ /**
+ * Rebase the current revisions of a change's chain.
+ *
+ * @return a {@code RebaseChainInfo} contains the {@code ChangeInfo} data for the rebased the
+ * chain
+ */
+ Response<RebaseChainInfo> rebaseChain(RebaseInput in) throws RestApiException;
+
/** Deletes a change. */
void delete() throws RestApiException;
@@ -325,22 +347,6 @@
/** Adds a user to the attention set. */
AccountInfo addToAttentionSet(AttentionSetInput input) throws RestApiException;
- /** Set the assignee of a change. */
- AccountInfo setAssignee(AssigneeInput input) throws RestApiException;
-
- /** Get the assignee of a change. */
- AccountInfo getAssignee() throws RestApiException;
-
- /** Get all past assignees. */
- List<AccountInfo> getPastAssignees() throws RestApiException;
-
- /**
- * Delete the assignee of a change.
- *
- * @return the assignee that was deleted, or null if there was no assignee.
- */
- AccountInfo deleteAssignee() throws RestApiException;
-
/**
* Get all published comments on a change.
*
@@ -632,6 +638,11 @@
}
@Override
+ public Response<RebaseChainInfo> rebaseChain(RebaseInput in) throws RestApiException {
+ throw new NotImplementedException();
+ }
+
+ @Override
public void delete() throws RestApiException {
throw new NotImplementedException();
}
@@ -719,26 +730,6 @@
}
@Override
- public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
- throw new NotImplementedException();
- }
-
- @Override
- public AccountInfo getAssignee() throws RestApiException {
- throw new NotImplementedException();
- }
-
- @Override
- public List<AccountInfo> getPastAssignees() throws RestApiException {
- throw new NotImplementedException();
- }
-
- @Override
- public AccountInfo deleteAssignee() throws RestApiException {
- throw new NotImplementedException();
- }
-
- @Override
@Deprecated
public Map<String, List<CommentInfo>> comments() throws RestApiException {
throw new NotImplementedException();
@@ -824,6 +815,11 @@
}
@Override
+ public ChangeInfo applyPatch(ApplyPatchPatchSetInput in) throws RestApiException {
+ throw new NotImplementedException();
+ }
+
+ @Override
public PureRevertInfo pureRevert() throws RestApiException {
throw new NotImplementedException();
}
diff --git a/java/com/google/gerrit/extensions/api/changes/FileContentInput.java b/java/com/google/gerrit/extensions/api/changes/FileContentInput.java
index 0cfe908..6349595 100644
--- a/java/com/google/gerrit/extensions/api/changes/FileContentInput.java
+++ b/java/com/google/gerrit/extensions/api/changes/FileContentInput.java
@@ -21,4 +21,5 @@
public class FileContentInput {
@DefaultInput public RawInput content;
public String binary_content;
+ public Integer fileMode;
}
diff --git a/java/com/google/gerrit/extensions/api/changes/RebaseInput.java b/java/com/google/gerrit/extensions/api/changes/RebaseInput.java
index e9b05cc..a85bc73 100644
--- a/java/com/google/gerrit/extensions/api/changes/RebaseInput.java
+++ b/java/com/google/gerrit/extensions/api/changes/RebaseInput.java
@@ -27,5 +27,21 @@
*/
public boolean allowConflicts;
+ /**
+ * Whether the rebase should be done on behalf of the uploader.
+ *
+ * <p>This means the uploader of the current patch set will also be the uploader of the rebased
+ * patch set. The calling user will be recorded as the real user.
+ *
+ * <p>Rebasing on behalf of the uploader is only supported for trivial rebases. This means this
+ * option cannot be combined with the {@link #allowConflicts} option.
+ *
+ * <p>In addition, rebasing on behalf of the uploader is only supported for the current patch set
+ * of a change and not when rebasing a chain.
+ *
+ * <p>Using this option is not supported when rebasing a chain via the Rebase Chain REST endpoint.
+ */
+ public boolean onBehalfOfUploader;
+
public Map<String, String> validationOptions;
}
diff --git a/java/com/google/gerrit/extensions/api/changes/ReviewInput.java b/java/com/google/gerrit/extensions/api/changes/ReviewInput.java
index 11999ab..8bfe468 100644
--- a/java/com/google/gerrit/extensions/api/changes/ReviewInput.java
+++ b/java/com/google/gerrit/extensions/api/changes/ReviewInput.java
@@ -14,8 +14,10 @@
package com.google.gerrit.extensions.api.changes;
+import static com.google.gerrit.extensions.client.ReviewerState.CC;
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gerrit.extensions.client.Comment;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.common.FixSuggestionInfo;
@@ -117,11 +119,13 @@
public List<FixSuggestionInfo> fixSuggestions;
}
+ @CanIgnoreReturnValue
public ReviewInput message(String msg) {
message = msg != null && !msg.isEmpty() ? msg : null;
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput patchSetLevelComment(String message) {
Objects.requireNonNull(message);
CommentInput comment = new CommentInput();
@@ -131,6 +135,7 @@
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput label(String name, short value) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException();
@@ -142,6 +147,7 @@
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput label(String name, int value) {
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw new IllegalArgumentException();
@@ -149,14 +155,22 @@
return label(name, (short) value);
}
+ @CanIgnoreReturnValue
public ReviewInput label(String name) {
return label(name, (short) 1);
}
+ @CanIgnoreReturnValue
public ReviewInput reviewer(String reviewer) {
- return reviewer(reviewer, REVIEWER, false);
+ return reviewer(reviewer, REVIEWER, /* confirmed= */ false);
}
+ @CanIgnoreReturnValue
+ public ReviewInput cc(String cc) {
+ return reviewer(cc, CC, /* confirmed= */ false);
+ }
+
+ @CanIgnoreReturnValue
public ReviewInput reviewer(String reviewer, ReviewerState state, boolean confirmed) {
ReviewerInput input = new ReviewerInput();
input.reviewer = reviewer;
@@ -169,6 +183,7 @@
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput addUserToAttentionSet(String user, String reason) {
AttentionSetInput input = new AttentionSetInput();
input.user = user;
@@ -180,6 +195,7 @@
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput removeUserFromAttentionSet(String user, String reason) {
AttentionSetInput input = new AttentionSetInput();
input.user = user;
@@ -191,17 +207,20 @@
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput blockAutomaticAttentionSetRules() {
ignoreAutomaticAttentionSetRules = true;
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput setWorkInProgress(boolean workInProgress) {
this.workInProgress = workInProgress;
ready = !workInProgress;
return this;
}
+ @CanIgnoreReturnValue
public ReviewInput setReady(boolean ready) {
this.ready = ready;
workInProgress = !ready;
diff --git a/java/com/google/gerrit/extensions/api/projects/CommentLinkInfo.java b/java/com/google/gerrit/extensions/api/projects/CommentLinkInfo.java
index b45fcee..5c47ac3 100644
--- a/java/com/google/gerrit/extensions/api/projects/CommentLinkInfo.java
+++ b/java/com/google/gerrit/extensions/api/projects/CommentLinkInfo.java
@@ -24,7 +24,6 @@
public String prefix;
public String suffix;
public String text;
- public String html;
public Boolean enabled; // null means true
public transient String name;
@@ -41,7 +40,6 @@
&& Objects.equals(this.prefix, that.prefix)
&& Objects.equals(this.suffix, that.suffix)
&& Objects.equals(this.text, that.text)
- && Objects.equals(this.html, that.html)
&& Objects.equals(this.enabled, that.enabled);
}
return false;
@@ -49,7 +47,7 @@
@Override
public int hashCode() {
- return Objects.hash(match, link, html, enabled);
+ return Objects.hash(match, link, prefix, suffix, text, enabled);
}
@Override
@@ -61,7 +59,6 @@
.add("prefix", prefix)
.add("suffix", suffix)
.add("text", text)
- .add("html", html)
.add("enabled", enabled)
.toString();
}
diff --git a/java/com/google/gerrit/extensions/api/projects/ConfigInfo.java b/java/com/google/gerrit/extensions/api/projects/ConfigInfo.java
index 3ba1277..1a51c15 100644
--- a/java/com/google/gerrit/extensions/api/projects/ConfigInfo.java
+++ b/java/com/google/gerrit/extensions/api/projects/ConfigInfo.java
@@ -40,6 +40,7 @@
public InheritedBooleanInfo enableReviewerByEmail;
public InheritedBooleanInfo matchAuthorToCommitterDate;
public InheritedBooleanInfo rejectEmptyCommit;
+ public InheritedBooleanInfo skipAddingAuthorAndCommitterAsReviewers;
public MaxObjectSizeLimitInfo maxObjectSizeLimit;
@Deprecated // Equivalent to defaultSubmitType.value
diff --git a/java/com/google/gerrit/extensions/api/projects/ConfigInput.java b/java/com/google/gerrit/extensions/api/projects/ConfigInput.java
index 8005fc5..906fc4c 100644
--- a/java/com/google/gerrit/extensions/api/projects/ConfigInput.java
+++ b/java/com/google/gerrit/extensions/api/projects/ConfigInput.java
@@ -34,6 +34,7 @@
public InheritableBoolean enableReviewerByEmail;
public InheritableBoolean matchAuthorToCommitterDate;
public InheritableBoolean rejectEmptyCommit;
+ public InheritableBoolean skipAddingAuthorAndCommitterAsReviewers;
public String maxObjectSizeLimit;
public SubmitType submitType;
public ProjectState state;
diff --git a/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java b/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
index 1ee2cd8..020351b 100644
--- a/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
+++ b/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
@@ -134,7 +134,6 @@
public DateFormat dateFormat;
public TimeFormat timeFormat;
public Boolean expandInlineDiffs;
- public Boolean highlightAssigneeInChangeTable;
public Boolean relativeDateInChangeTable;
public DiffView diffView;
public Boolean sizeBarInChangeTable;
@@ -195,7 +194,6 @@
p.dateFormat = DateFormat.STD;
p.timeFormat = TimeFormat.HHMM_12;
p.expandInlineDiffs = false;
- p.highlightAssigneeInChangeTable = true;
p.relativeDateInChangeTable = false;
p.diffView = DiffView.SIDE_BY_SIDE;
p.sizeBarInChangeTable = true;
diff --git a/java/com/google/gerrit/extensions/client/GerritTopMenu.java b/java/com/google/gerrit/extensions/client/GerritTopMenu.java
index b7e1a5a..b9a395e 100644
--- a/java/com/google/gerrit/extensions/client/GerritTopMenu.java
+++ b/java/com/google/gerrit/extensions/client/GerritTopMenu.java
@@ -14,6 +14,8 @@
package com.google.gerrit.extensions.client;
+import java.util.Locale;
+
public enum GerritTopMenu {
ALL,
MY,
@@ -25,6 +27,6 @@
public final String menuName;
GerritTopMenu() {
- menuName = name().substring(0, 1) + name().substring(1).toLowerCase();
+ menuName = name().substring(0, 1) + name().substring(1).toLowerCase(Locale.US);
}
}
diff --git a/java/com/google/gerrit/extensions/client/Side.java b/java/com/google/gerrit/extensions/client/Side.java
index e077df2..a87b37a 100644
--- a/java/com/google/gerrit/extensions/client/Side.java
+++ b/java/com/google/gerrit/extensions/client/Side.java
@@ -14,10 +14,13 @@
package com.google.gerrit.extensions.client;
+import com.google.gerrit.common.Nullable;
+
public enum Side {
PARENT,
REVISION;
+ @Nullable
public static Side fromShort(short s) {
if (s <= 0) {
return PARENT;
diff --git a/java/com/google/gerrit/extensions/common/ActionInfo.java b/java/com/google/gerrit/extensions/common/ActionInfo.java
index 2144ed5..f148444 100644
--- a/java/com/google/gerrit/extensions/common/ActionInfo.java
+++ b/java/com/google/gerrit/extensions/common/ActionInfo.java
@@ -15,6 +15,7 @@
package com.google.gerrit.extensions.common;
import com.google.gerrit.extensions.webui.UiAction;
+import java.util.List;
import java.util.Objects;
/**
@@ -50,11 +51,30 @@
*/
public Boolean enabled;
+ /**
+ * Optional list of enabled options.
+ *
+ * <p>For the {@code rebase} REST view the following options are supported:
+ *
+ * <ul>
+ * <li>{@code rebase}: Present if the user can rebase the change. This is the case for the
+ * change owner and users with the {@code Submit} or {@code Rebase} permission if they have
+ * the {@code Push} permission.
+ * <li>{@code rebase_on_behalf_of}: Present if the user can rebase the change on behalf of the
+ * uploader. This is the case for the change owner and users with the {@code Submit} or
+ * {@code Rebase} permission.
+ * </ul>
+ *
+ * <p>For all other REST views no options are returned.
+ */
+ public List<String> enabledOptions;
+
public ActionInfo(UiAction.Description d) {
method = d.getMethod();
label = d.getLabel();
title = d.getTitle();
enabled = d.isEnabled() ? true : null;
+ enabledOptions = d.getEnabledOptions();
}
@Override
@@ -64,14 +84,15 @@
return Objects.equals(method, actionInfo.method)
&& Objects.equals(label, actionInfo.label)
&& Objects.equals(title, actionInfo.title)
- && Objects.equals(enabled, actionInfo.enabled);
+ && Objects.equals(enabled, actionInfo.enabled)
+ && Objects.equals(enabledOptions, actionInfo.enabledOptions);
}
return false;
}
@Override
public int hashCode() {
- return Objects.hash(method, label, title, enabled);
+ return Objects.hash(method, label, title, enabled, enabledOptions);
}
protected ActionInfo() {}
diff --git a/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java b/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java
index 3bcd150..80bf130 100644
--- a/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java
+++ b/java/com/google/gerrit/extensions/common/ChangeConfigInfo.java
@@ -17,12 +17,10 @@
/** API response containing values from the {@code change} section of {@code gerrit.config}. */
public class ChangeConfigInfo {
public Boolean allowBlame;
- public Boolean showAssigneeInChangesTable;
public Boolean disablePrivateChanges;
public int updateDelay;
public Boolean submitWholeTopic;
public String mergeabilityComputationBehavior;
- public Boolean enableAttentionSet;
- public Boolean enableAssignee;
+ public Boolean enableRobotComments;
public Boolean conflictsPredicateEnabled;
}
diff --git a/java/com/google/gerrit/extensions/common/ChangeInfo.java b/java/com/google/gerrit/extensions/common/ChangeInfo.java
index 40ae2ec..dc9bc32 100644
--- a/java/com/google/gerrit/extensions/common/ChangeInfo.java
+++ b/java/com/google/gerrit/extensions/common/ChangeInfo.java
@@ -49,7 +49,6 @@
public Map<Integer, AttentionSetInfo> removedFromAttentionSet;
- public AccountInfo assignee;
public Collection<String> hashtags;
public String changeId;
public String subject;
@@ -105,6 +104,7 @@
public Map<String, ActionInfo> actions;
public Map<String, LabelInfo> labels;
public Map<String, Collection<String>> permittedLabels;
+ public Map<String, Map<String, List<AccountInfo>>> removableLabels;
public Collection<AccountInfo> removableReviewers;
public Map<ReviewerState, Collection<AccountInfo>> reviewers;
public Map<ReviewerState, Collection<AccountInfo>> pendingReviewers;
@@ -174,4 +174,14 @@
submitted = Timestamp.from(when);
submitter = who;
}
+
+ public RevisionInfo getCurrentRevision() {
+ RevisionInfo currentRevisionInfo = revisions.get(currentRevision);
+ if (currentRevisionInfo.commit != null) {
+ // If all revisions are requested the commit.commit field is not populated because the commit
+ // SHA1 is already present as the key in the revisions map.
+ currentRevisionInfo.commit.commit = currentRevision;
+ }
+ return currentRevisionInfo;
+ }
}
diff --git a/java/com/google/gerrit/extensions/common/ChangeInfoDiffer.java b/java/com/google/gerrit/extensions/common/ChangeInfoDiffer.java
index ad112d3..51c35dc 100644
--- a/java/com/google/gerrit/extensions/common/ChangeInfoDiffer.java
+++ b/java/com/google/gerrit/extensions/common/ChangeInfoDiffer.java
@@ -21,6 +21,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.gerrit.common.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.sql.Timestamp;
@@ -147,16 +148,19 @@
}
/** Returns {@code null} if nothing has been added to {@code oldCollection} */
+ @Nullable
private static ImmutableList<?> getAddedForCollection(
- Collection<?> oldCollection, Collection<?> newCollection) {
- ImmutableList<?> notInOldCollection = getAdditions(oldCollection, newCollection);
+ @Nullable Collection<?> oldCollection, Collection<?> newCollection) {
+ ImmutableList<?> notInOldCollection = getAdditionsForCollection(oldCollection, newCollection);
return notInOldCollection.isEmpty() ? null : notInOldCollection;
}
- private static ImmutableList<Object> getAdditions(
- Collection<?> oldCollection, Collection<?> newCollection) {
- if (oldCollection == null)
- return newCollection != null ? ImmutableList.copyOf(newCollection) : null;
+ @Nullable
+ private static ImmutableList<Object> getAdditionsForCollection(
+ @Nullable Collection<?> oldCollection, Collection<?> newCollection) {
+ if (oldCollection == null) {
+ return ImmutableList.copyOf(newCollection);
+ }
Map<Object, List<Object>> duplicatesMap = newCollection.stream().collect(groupingBy(v -> v));
oldCollection.forEach(
@@ -169,7 +173,19 @@
}
/** Returns {@code null} if nothing has been added to {@code oldMap} */
- private static ImmutableMap<Object, Object> getAddedForMap(Map<?, ?> oldMap, Map<?, ?> newMap) {
+ @Nullable
+ private static ImmutableMap<Object, Object> getAddedForMap(
+ @Nullable Map<?, ?> oldMap, Map<?, ?> newMap) {
+ ImmutableMap<Object, Object> notInOldMap = getAdditionsForMap(oldMap, newMap);
+ return notInOldMap.isEmpty() ? null : notInOldMap;
+ }
+
+ @Nullable
+ private static ImmutableMap<Object, Object> getAdditionsForMap(
+ @Nullable Map<?, ?> oldMap, Map<?, ?> newMap) {
+ if (oldMap == null) {
+ return ImmutableMap.copyOf(newMap);
+ }
ImmutableMap.Builder<Object, Object> additionsBuilder = ImmutableMap.builder();
for (Map.Entry<?, ?> entry : newMap.entrySet()) {
Object added = getAdded(oldMap.get(entry.getKey()), entry.getValue());
@@ -177,8 +193,7 @@
additionsBuilder.put(entry.getKey(), added);
}
}
- ImmutableMap<Object, Object> additions = additionsBuilder.build();
- return additions.isEmpty() ? null : additions;
+ return additionsBuilder.build();
}
private static Object get(Field field, Object obj) {
diff --git a/java/com/google/gerrit/extensions/common/ChangeInput.java b/java/com/google/gerrit/extensions/common/ChangeInput.java
index ea12ef1..6f9cff7 100644
--- a/java/com/google/gerrit/extensions/common/ChangeInput.java
+++ b/java/com/google/gerrit/extensions/common/ChangeInput.java
@@ -14,11 +14,15 @@
package com.google.gerrit.extensions.common;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.accounts.AccountInput;
+import com.google.gerrit.extensions.api.changes.ApplyPatchInput;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.api.changes.NotifyInfo;
import com.google.gerrit.extensions.api.changes.RecipientType;
import com.google.gerrit.extensions.client.ChangeStatus;
+import com.google.gerrit.extensions.client.ListChangesOption;
+import java.util.List;
import java.util.Map;
public class ChangeInput {
@@ -35,9 +39,12 @@
public Boolean newBranch;
public Map<String, String> validationOptions;
public MergeInput merge;
+ public ApplyPatchInput patch;
public AccountInput author;
+ @Nullable public List<ListChangesOption> responseFormatOptions;
+
public ChangeInput() {}
/**
diff --git a/java/com/google/gerrit/extensions/common/DiffWebLinkInfo.java b/java/com/google/gerrit/extensions/common/DiffWebLinkInfo.java
index 9bcf2cf..05029be 100644
--- a/java/com/google/gerrit/extensions/common/DiffWebLinkInfo.java
+++ b/java/com/google/gerrit/extensions/common/DiffWebLinkInfo.java
@@ -18,29 +18,26 @@
public Boolean showOnSideBySideDiffView;
public Boolean showOnUnifiedDiffView;
- public static DiffWebLinkInfo forSideBySideDiffView(
- String name, String imageUrl, String url, String target) {
- return new DiffWebLinkInfo(name, imageUrl, url, target, true, false);
+ public static DiffWebLinkInfo forSideBySideDiffView(String name, String imageUrl, String url) {
+ return new DiffWebLinkInfo(name, imageUrl, url, true, false);
}
- public static DiffWebLinkInfo forUnifiedDiffView(
- String name, String imageUrl, String url, String target) {
- return new DiffWebLinkInfo(name, imageUrl, url, target, false, true);
+ public static DiffWebLinkInfo forUnifiedDiffView(String name, String imageUrl, String url) {
+ return new DiffWebLinkInfo(name, imageUrl, url, false, true);
}
public static DiffWebLinkInfo forSideBySideAndUnifiedDiffView(
- String name, String imageUrl, String url, String target) {
- return new DiffWebLinkInfo(name, imageUrl, url, target, true, true);
+ String name, String imageUrl, String url) {
+ return new DiffWebLinkInfo(name, imageUrl, url, true, true);
}
private DiffWebLinkInfo(
String name,
String imageUrl,
String url,
- String target,
boolean showOnSideBySideDiffView,
boolean showOnUnifiedDiffView) {
- super(name, imageUrl, url, target);
+ super(name, imageUrl, url);
this.showOnSideBySideDiffView = showOnSideBySideDiffView ? true : null;
this.showOnUnifiedDiffView = showOnUnifiedDiffView ? true : null;
}
diff --git a/java/com/google/gerrit/extensions/common/FileInfo.java b/java/com/google/gerrit/extensions/common/FileInfo.java
index c732663..9526fbb 100644
--- a/java/com/google/gerrit/extensions/common/FileInfo.java
+++ b/java/com/google/gerrit/extensions/common/FileInfo.java
@@ -18,6 +18,8 @@
public class FileInfo {
public Character status;
+ public Integer oldMode;
+ public Integer newMode;
public Boolean binary;
public String oldPath;
public Integer linesInserted;
diff --git a/java/com/google/gerrit/extensions/common/RebaseChainInfo.java b/java/com/google/gerrit/extensions/common/RebaseChainInfo.java
new file mode 100644
index 0000000..b327007
--- /dev/null
+++ b/java/com/google/gerrit/extensions/common/RebaseChainInfo.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.extensions.common;
+
+import java.util.List;
+
+public class RebaseChainInfo {
+ public List<ChangeInfo> rebasedChanges;
+ /**
+ * Whether any of the changes contain conflicts.
+ *
+ * <p>If {@code true}, some of the rebased changes are marked with conflicts.
+ */
+ public Boolean containsGitConflicts;
+}
diff --git a/java/com/google/gerrit/extensions/common/RevisionInfo.java b/java/com/google/gerrit/extensions/common/RevisionInfo.java
index 7c52c8c..941dffe 100644
--- a/java/com/google/gerrit/extensions/common/RevisionInfo.java
+++ b/java/com/google/gerrit/extensions/common/RevisionInfo.java
@@ -32,6 +32,7 @@
public Timestamp created;
public AccountInfo uploader;
+ public AccountInfo realUploader;
public String ref;
public Map<String, FetchInfo> fetch;
public CommitInfo commit;
@@ -72,6 +73,7 @@
&& _number == revisionInfo._number
&& Objects.equals(created, revisionInfo.created)
&& Objects.equals(uploader, revisionInfo.uploader)
+ && Objects.equals(realUploader, revisionInfo.realUploader)
&& Objects.equals(ref, revisionInfo.ref)
&& Objects.equals(fetch, revisionInfo.fetch)
&& Objects.equals(commit, revisionInfo.commit)
@@ -92,6 +94,7 @@
_number,
created,
uploader,
+ realUploader,
ref,
fetch,
commit,
diff --git a/java/com/google/gerrit/extensions/common/WebLinkInfo.java b/java/com/google/gerrit/extensions/common/WebLinkInfo.java
index ba12be0..fbd8d2f 100644
--- a/java/com/google/gerrit/extensions/common/WebLinkInfo.java
+++ b/java/com/google/gerrit/extensions/common/WebLinkInfo.java
@@ -14,24 +14,18 @@
package com.google.gerrit.extensions.common;
-import com.google.gerrit.extensions.webui.WebLink.Target;
import java.util.Objects;
public class WebLinkInfo {
public String name;
+ public String tooltip;
public String imageUrl;
public String url;
- public String target;
- public WebLinkInfo(String name, String imageUrl, String url, String target) {
+ public WebLinkInfo(String name, String imageUrl, String url) {
this.name = name;
this.imageUrl = imageUrl;
this.url = url;
- this.target = target;
- }
-
- public WebLinkInfo(String name, String imageUrl, String url) {
- this(name, imageUrl, url, Target.SELF);
}
@Override
@@ -41,14 +35,14 @@
}
WebLinkInfo i = (WebLinkInfo) o;
return Objects.equals(name, i.name)
+ && Objects.equals(tooltip, i.tooltip)
&& Objects.equals(imageUrl, i.imageUrl)
- && Objects.equals(url, i.url)
- && Objects.equals(target, i.target);
+ && Objects.equals(url, i.url);
}
@Override
public int hashCode() {
- return Objects.hash(name, imageUrl, url, target);
+ return Objects.hash(name, tooltip, imageUrl, url);
}
@Override
@@ -56,12 +50,12 @@
return getClass().getSimpleName()
+ "{name="
+ name
+ + ", tooltip="
+ + tooltip
+ ", imageUrl="
+ imageUrl
+ ", url="
+ url
- + ", target"
- + target
+ "}";
}
diff --git a/java/com/google/gerrit/extensions/common/testing/FileInfoSubject.java b/java/com/google/gerrit/extensions/common/testing/FileInfoSubject.java
index d011d5d..180a94691 100644
--- a/java/com/google/gerrit/extensions/common/testing/FileInfoSubject.java
+++ b/java/com/google/gerrit/extensions/common/testing/FileInfoSubject.java
@@ -45,6 +45,16 @@
return check("linesDeleted").that(fileInfo.linesDeleted);
}
+ public IntegerSubject oldMode() {
+ isNotNull();
+ return check("oldMode").that(fileInfo.oldMode);
+ }
+
+ public IntegerSubject newMode() {
+ isNotNull();
+ return check("newMode").that(fileInfo.newMode);
+ }
+
public ComparableSubject<Character> status() {
isNotNull();
return check("status").that(fileInfo.status);
diff --git a/java/com/google/gerrit/extensions/events/AssigneeChangedListener.java b/java/com/google/gerrit/extensions/events/AssigneeChangedListener.java
deleted file mode 100644
index 7fc0f03..0000000
--- a/java/com/google/gerrit/extensions/events/AssigneeChangedListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.gerrit.extensions.events;
-
-import com.google.gerrit.common.Nullable;
-import com.google.gerrit.extensions.annotations.ExtensionPoint;
-import com.google.gerrit.extensions.common.AccountInfo;
-
-/** Notified whenever a change assignee is changed. */
-@ExtensionPoint
-public interface AssigneeChangedListener {
- interface Event extends ChangeEvent {
- @Nullable
- AccountInfo getOldAssignee();
- }
-
- void onAssigneeChanged(Event event);
-}
diff --git a/java/com/google/gerrit/extensions/registration/DynamicItemProvider.java b/java/com/google/gerrit/extensions/registration/DynamicItemProvider.java
index d8dd1f9..7ed7077 100644
--- a/java/com/google/gerrit/extensions/registration/DynamicItemProvider.java
+++ b/java/com/google/gerrit/extensions/registration/DynamicItemProvider.java
@@ -14,6 +14,7 @@
package com.google.gerrit.extensions.registration;
+import com.google.gerrit.common.Nullable;
import com.google.inject.Binding;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -39,6 +40,7 @@
return new DynamicItem<>(key, find(injector, type), PluginName.GERRIT);
}
+ @Nullable
private static <T> Provider<T> find(Injector src, TypeLiteral<T> type) {
List<Binding<T>> bindings = src.findBindingsByType(type);
if (bindings != null && bindings.size() == 1) {
diff --git a/java/com/google/gerrit/extensions/registration/DynamicSet.java b/java/com/google/gerrit/extensions/registration/DynamicSet.java
index a0b2c6a..6dc8c6a 100644
--- a/java/com/google/gerrit/extensions/registration/DynamicSet.java
+++ b/java/com/google/gerrit/extensions/registration/DynamicSet.java
@@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
+import com.google.gerrit.common.Nullable;
import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Provider;
@@ -313,6 +314,7 @@
return key;
}
+ @Nullable
@Override
public ReloadableHandle replace(Key<T> newKey, Provider<T> newItem) {
Extension<T> n = new Extension<>(item.getPluginName(), newItem);
diff --git a/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicMapImpl.java b/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicMapImpl.java
index fb520b4..67fc068 100644
--- a/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicMapImpl.java
+++ b/java/com/google/gerrit/extensions/registration/PrivateInternals_DynamicMapImpl.java
@@ -16,6 +16,7 @@
import static java.util.Objects.requireNonNull;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.annotations.Export;
import com.google.inject.Key;
import com.google.inject.Provider;
@@ -79,6 +80,7 @@
return key;
}
+ @Nullable
@Override
public ReloadableHandle replace(Key<T> newKey, Provider<T> newItem) {
if (items.replace(np, item, newItem)) {
diff --git a/java/com/google/gerrit/extensions/restapi/IdString.java b/java/com/google/gerrit/extensions/restapi/IdString.java
index b2538fa..a69919f 100644
--- a/java/com/google/gerrit/extensions/restapi/IdString.java
+++ b/java/com/google/gerrit/extensions/restapi/IdString.java
@@ -38,7 +38,16 @@
/** Returns the decoded value of the string. */
public String get() {
- return Url.decode(urlEncoded);
+ String data = urlEncoded;
+
+ // URLs use percentage encoding which replaces unsafe ASCII characters with a '%' followed by
+ // two hexadecimal digits. If there is '%' that is not followed by two hexadecimal digits
+ // Url.decode(String) fails with an IllegalArgumentException. To prevent this replace any '%'
+ // that is not followed by two hexadecimal digits by "%25", which is the URL encoding for '%',
+ // before calling Url.decode(String).
+ data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
+
+ return Url.decode(data);
}
/** Returns true if the string is the empty string. */
diff --git a/java/com/google/gerrit/extensions/restapi/Url.java b/java/com/google/gerrit/extensions/restapi/Url.java
index 9c69376..09def84 100644
--- a/java/com/google/gerrit/extensions/restapi/Url.java
+++ b/java/com/google/gerrit/extensions/restapi/Url.java
@@ -16,6 +16,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
+import com.google.gerrit.common.Nullable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
@@ -40,6 +41,7 @@
* @param component a string containing text to encode.
* @return a string with all invalid URL characters escaped.
*/
+ @Nullable
public static String encode(String component) {
if (component != null) {
try {
@@ -52,6 +54,7 @@
}
/** Decode a URL encoded string, e.g. from {@code "%2F"} to {@code "/"}. */
+ @Nullable
public static String decode(String str) {
if (str != null) {
try {
diff --git a/java/com/google/gerrit/extensions/webui/UiAction.java b/java/com/google/gerrit/extensions/webui/UiAction.java
index 2f21bf3..9da0642 100644
--- a/java/com/google/gerrit/extensions/webui/UiAction.java
+++ b/java/com/google/gerrit/extensions/webui/UiAction.java
@@ -14,10 +14,13 @@
package com.google.gerrit.extensions.webui;
+import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.conditions.BooleanCondition;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
+import java.util.ArrayList;
+import java.util.List;
public interface UiAction<R extends RestResource> extends RestView<R> {
/**
@@ -40,6 +43,7 @@
private String title;
private BooleanCondition visible = BooleanCondition.TRUE;
private BooleanCondition enabled = BooleanCondition.TRUE;
+ private List<String> enabledOptions = new ArrayList<>();
public String getMethod() {
return method;
@@ -122,5 +126,22 @@
this.enabled = enabled;
return this;
}
+
+ @Nullable
+ public ImmutableList<String> getEnabledOptions() {
+ if (enabledOptions.isEmpty()) {
+ return null;
+ }
+ return ImmutableList.copyOf(enabledOptions);
+ }
+
+ public Description setOption(String optionName, boolean enabled) {
+ if (enabled) {
+ enabledOptions.add(optionName);
+ } else {
+ enabledOptions.remove(optionName);
+ }
+ return this;
+ }
}
}
diff --git a/java/com/google/gerrit/extensions/webui/WebLink.java b/java/com/google/gerrit/extensions/webui/WebLink.java
index 7cbeff2..36ae50c 100644
--- a/java/com/google/gerrit/extensions/webui/WebLink.java
+++ b/java/com/google/gerrit/extensions/webui/WebLink.java
@@ -15,16 +15,4 @@
package com.google.gerrit.extensions.webui;
/** Marks that the implementor has a method that provides a weblinkInfo */
-public interface WebLink {
- /** Class that holds target defaults for WebLink anchors. */
- class Target {
- /** Opens the link in a new window or tab */
- public static final String BLANK = "_blank";
- /** Opens the link in the frame it was clicked. */
- public static final String SELF = "_self";
- /** Opens link in parent frame. */
- public static final String PARENT = "_parent";
- /** Opens link in the full body of the window. */
- public static final String TOP = "_top";
- }
-}
+public interface WebLink {}
diff --git a/java/com/google/gerrit/git/GitUpdateFailureException.java b/java/com/google/gerrit/git/GitUpdateFailureException.java
index 7fcb828..339339c 100644
--- a/java/com/google/gerrit/git/GitUpdateFailureException.java
+++ b/java/com/google/gerrit/git/GitUpdateFailureException.java
@@ -46,6 +46,11 @@
.collect(toImmutableList());
}
+ protected GitUpdateFailureException(String message, Throwable cause) {
+ super(message, cause);
+ this.failures = ImmutableList.of();
+ }
+
/** Returns the names of the refs for which the update failed. */
public ImmutableList<String> getFailedRefs() {
return failures.stream().map(GitUpdateFailure::ref).collect(toImmutableList());
diff --git a/java/com/google/gerrit/git/LockFailureException.java b/java/com/google/gerrit/git/LockFailureException.java
index 371488d..2908db2 100644
--- a/java/com/google/gerrit/git/LockFailureException.java
+++ b/java/com/google/gerrit/git/LockFailureException.java
@@ -14,6 +14,7 @@
package com.google.gerrit.git;
+import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.RefUpdate;
@@ -21,6 +22,9 @@
public class LockFailureException extends GitUpdateFailureException {
private static final long serialVersionUID = 1L;
+ private static final String REF_UPDATE_RETURN_CODE_WAS_LOCK_FAILURE =
+ "RefUpdate return code was: LOCK_FAILURE";
+
public LockFailureException(String message, RefUpdate refUpdate) {
super(message, refUpdate);
}
@@ -28,4 +32,15 @@
public LockFailureException(String message, BatchRefUpdate batchRefUpdate) {
super(message, batchRefUpdate);
}
+
+ protected LockFailureException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public static void throwIfLockFailure(ConcurrentRefUpdateException e)
+ throws LockFailureException {
+ if (e.getMessage().contains(REF_UPDATE_RETURN_CODE_WAS_LOCK_FAILURE)) {
+ throw new LockFailureException(e.getMessage(), e);
+ }
+ }
}
diff --git a/java/com/google/gerrit/gpg/BUILD b/java/com/google/gerrit/gpg/BUILD
index 0ee5212..b2173c4 100644
--- a/java/com/google/gerrit/gpg/BUILD
+++ b/java/com/google/gerrit/gpg/BUILD
@@ -5,6 +5,7 @@
srcs = glob(["**/*.java"]),
visibility = ["//visibility:public"],
deps = [
+ "//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/entities",
"//java/com/google/gerrit/exceptions",
"//java/com/google/gerrit/extensions:api",
diff --git a/java/com/google/gerrit/gpg/GerritPublicKeyChecker.java b/java/com/google/gerrit/gpg/GerritPublicKeyChecker.java
index 71dff97..fff4045 100644
--- a/java/com/google/gerrit/gpg/GerritPublicKeyChecker.java
+++ b/java/com/google/gerrit/gpg/GerritPublicKeyChecker.java
@@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -82,7 +83,7 @@
if (strs.length != 0) {
Map<Long, Fingerprint> fps = Maps.newHashMapWithExpectedSize(strs.length);
for (String str : strs) {
- str = CharMatcher.whitespace().removeFrom(str).toUpperCase();
+ str = CharMatcher.whitespace().removeFrom(str).toUpperCase(Locale.US);
Fingerprint fp = new Fingerprint(BaseEncoding.base16().decode(str));
fps.put(fp.getId(), fp);
}
diff --git a/java/com/google/gerrit/gpg/PublicKeyChecker.java b/java/com/google/gerrit/gpg/PublicKeyChecker.java
index 0a96212..5347398 100644
--- a/java/com/google/gerrit/gpg/PublicKeyChecker.java
+++ b/java/com/google/gerrit/gpg/PublicKeyChecker.java
@@ -30,6 +30,7 @@
import static org.bouncycastle.openpgp.PGPSignature.KEY_REVOCATION;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.common.GpgKeyInfo.Status;
import java.io.IOException;
import java.time.Instant;
@@ -229,6 +230,7 @@
|| PushCertificateChecker.getCreationTime(revocation).isBefore(now);
}
+ @Nullable
private PGPSignature scanRevocations(
PGPPublicKey key,
Instant now,
@@ -264,6 +266,7 @@
return null;
}
+ @Nullable
private RevocationKey getRevocationKey(PGPPublicKey key, PGPSignature sig) throws PGPException {
if (sig.getKeyID() != key.getKeyID()) {
return null;
@@ -320,6 +323,7 @@
}
}
+ @Nullable
private static RevocationReason getRevocationReason(PGPSignature sig) {
if (sig.getSignatureType() != KEY_REVOCATION) {
throw new IllegalArgumentException(
@@ -425,6 +429,7 @@
return CheckResult.create(OK, problems);
}
+ @Nullable
private static PGPPublicKey getSigner(
PublicKeyStore store,
PGPSignature sig,
@@ -455,6 +460,7 @@
}
}
+ @Nullable
private String checkTrustSubpacket(PGPSignature sig, int depth) {
SignatureSubpacket trustSub =
sig.getHashedSubPackets().getSubpacket(SignatureSubpacketTags.TRUST_SIG);
diff --git a/java/com/google/gerrit/gpg/PublicKeyStore.java b/java/com/google/gerrit/gpg/PublicKeyStore.java
index 2cce480..def35d6 100644
--- a/java/com/google/gerrit/gpg/PublicKeyStore.java
+++ b/java/com/google/gerrit/gpg/PublicKeyStore.java
@@ -15,14 +15,17 @@
package com.google.gerrit.gpg;
import static com.google.common.base.Preconditions.checkState;
+import static com.google.gerrit.server.update.context.RefUpdateContext.RefUpdateType.GPG_KEYS_MODIFICATION;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.EMPTY_TREE_ID;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteStreams;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.git.LockFailureException;
import com.google.gerrit.git.ObjectIds;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -92,6 +95,7 @@
* null} if none was found.
* @throws PGPException if an error occurred verifying the signature.
*/
+ @Nullable
public static PGPPublicKey getSigner(
Iterable<PGPPublicKeyRing> keyRings, PGPSignature sig, byte[] data) throws PGPException {
for (PGPPublicKeyRing kr : keyRings) {
@@ -126,6 +130,7 @@
* {@code null} if none was found.
* @throws PGPException if an error occurred verifying the certification.
*/
+ @Nullable
public static PGPPublicKey getSigner(
Iterable<PGPPublicKeyRing> keyRings, PGPSignature sig, String userId, PGPPublicKey key)
throws PGPException {
@@ -210,6 +215,7 @@
* @throws PGPException if an error occurred parsing the key data.
* @throws IOException if an error occurred reading the repository data.
*/
+ @Nullable
public PGPPublicKeyRing get(byte[] fingerprint) throws PGPException, IOException {
List<PGPPublicKeyRing> keyRings = get(Fingerprint.getId(fingerprint), fingerprint);
return !keyRings.isEmpty() ? keyRings.get(0) : null;
@@ -272,7 +278,7 @@
}
public void rebuildSubkeyMasterKeyMap()
- throws MissingObjectException, IncorrectObjectTypeException, IOException, PGPException {
+ throws MissingObjectException, IncorrectObjectTypeException, IOException {
if (reader == null) {
load();
}
@@ -373,35 +379,36 @@
newTip = ins.insert(cb);
ins.flush();
}
-
- RefUpdate ru = repo.updateRef(PublicKeyStore.REFS_GPG_KEYS);
- ru.setExpectedOldObjectId(tip);
- ru.setNewObjectId(newTip);
- ru.setRefLogIdent(cb.getCommitter());
- ru.setRefLogMessage("Store public keys", true);
- RefUpdate.Result result = ru.update();
- reset();
- switch (result) {
- case FAST_FORWARD:
- case NEW:
- case NO_CHANGE:
- toAdd.clear();
- toRemove.clear();
- break;
- case LOCK_FAILURE:
- throw new LockFailureException("Failed to store public keys", ru);
- case FORCED:
- case IO_FAILURE:
- case NOT_ATTEMPTED:
- case REJECTED:
- case REJECTED_CURRENT_BRANCH:
- case RENAMED:
- case REJECTED_MISSING_OBJECT:
- case REJECTED_OTHER_REASON:
- default:
- break;
+ try (RefUpdateContext ctx = RefUpdateContext.open(GPG_KEYS_MODIFICATION)) {
+ RefUpdate ru = repo.updateRef(PublicKeyStore.REFS_GPG_KEYS);
+ ru.setExpectedOldObjectId(tip);
+ ru.setNewObjectId(newTip);
+ ru.setRefLogIdent(cb.getCommitter());
+ ru.setRefLogMessage("Store public keys", true);
+ RefUpdate.Result result = ru.update();
+ reset();
+ switch (result) {
+ case FAST_FORWARD:
+ case NEW:
+ case NO_CHANGE:
+ toAdd.clear();
+ toRemove.clear();
+ break;
+ case LOCK_FAILURE:
+ throw new LockFailureException("Failed to store public keys", ru);
+ case FORCED:
+ case IO_FAILURE:
+ case NOT_ATTEMPTED:
+ case REJECTED:
+ case REJECTED_CURRENT_BRANCH:
+ case RENAMED:
+ case REJECTED_MISSING_OBJECT:
+ case REJECTED_OTHER_REASON:
+ default:
+ break;
+ }
+ return result;
}
- return result;
}
private void saveToNotes(ObjectInserter ins, PGPPublicKeyRing keyRing)
diff --git a/java/com/google/gerrit/gpg/PushCertificateChecker.java b/java/com/google/gerrit/gpg/PushCertificateChecker.java
index 17ca5a4..b9ff50b 100644
--- a/java/com/google/gerrit/gpg/PushCertificateChecker.java
+++ b/java/com/google/gerrit/gpg/PushCertificateChecker.java
@@ -22,6 +22,7 @@
import com.google.common.base.Joiner;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.common.GpgKeyInfo.Status;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -176,6 +177,7 @@
return CheckResult.ok();
}
+ @Nullable
private PGPSignature readSignature(PushCertificate cert) throws IOException {
ArmoredInputStream in =
new ArmoredInputStream(new ByteArrayInputStream(Constants.encode(cert.getSignature())));
diff --git a/java/com/google/gerrit/gpg/server/GpgKeys.java b/java/com/google/gerrit/gpg/server/GpgKeys.java
index b3a2f53..00a0f57 100644
--- a/java/com/google/gerrit/gpg/server/GpgKeys.java
+++ b/java/com/google/gerrit/gpg/server/GpgKeys.java
@@ -48,6 +48,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException;
@@ -106,7 +107,7 @@
static ExternalId findGpgKey(String str, Iterable<ExternalId> existingExtIds)
throws ResourceNotFoundException {
- str = CharMatcher.whitespace().removeFrom(str).toUpperCase();
+ str = CharMatcher.whitespace().removeFrom(str).toUpperCase(Locale.US);
if ((str.length() != 8 && str.length() != 40)
|| !CharMatcher.anyOf("0123456789ABCDEF").matchesAllOf(str)) {
throw new ResourceNotFoundException(str);
diff --git a/java/com/google/gerrit/gpg/server/PostGpgKeys.java b/java/com/google/gerrit/gpg/server/PostGpgKeys.java
index 3341806..d51ee6a 100644
--- a/java/com/google/gerrit/gpg/server/PostGpgKeys.java
+++ b/java/com/google/gerrit/gpg/server/PostGpgKeys.java
@@ -29,6 +29,7 @@
import com.google.common.collect.Maps;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.BaseEncoding;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.exceptions.EmailException;
import com.google.gerrit.exceptions.StorageException;
@@ -299,6 +300,7 @@
return externalIdKeyFactory.create(SCHEME_GPGKEY, BaseEncoding.base16().encode(fp));
}
+ @Nullable
private Account getAccountByExternalId(ExternalId.Key extIdKey) {
List<AccountState> accountStates = accountQueryProvider.get().byExternalId(extIdKey);
diff --git a/java/com/google/gerrit/httpd/BUILD b/java/com/google/gerrit/httpd/BUILD
index 1284829..0142031 100644
--- a/java/com/google/gerrit/httpd/BUILD
+++ b/java/com/google/gerrit/httpd/BUILD
@@ -38,9 +38,11 @@
"//lib/auto:auto-value",
"//lib/auto:auto-value-annotations",
"//lib/commons:lang3",
+ "//lib/errorprone:annotations",
"//lib/flogger:api",
"//lib/guice",
"//lib/guice:guice-assistedinject",
"//lib/guice:guice-servlet",
+ "//lib/jsoup",
],
)
diff --git a/java/com/google/gerrit/httpd/CacheBasedWebSession.java b/java/com/google/gerrit/httpd/CacheBasedWebSession.java
index 5b62f96..9625039 100644
--- a/java/com/google/gerrit/httpd/CacheBasedWebSession.java
+++ b/java/com/google/gerrit/httpd/CacheBasedWebSession.java
@@ -116,6 +116,7 @@
}
}
+ @Nullable
private static String readCookie(HttpServletRequest request) {
Cookie[] all = request.getCookies();
if (all != null) {
@@ -219,6 +220,7 @@
}
}
+ @Nullable
@Override
public String getSessionId() {
return val != null ? val.getSessionId() : null;
diff --git a/java/com/google/gerrit/httpd/GitOverHttpServlet.java b/java/com/google/gerrit/httpd/GitOverHttpServlet.java
index e1ead59..e513a72 100644
--- a/java/com/google/gerrit/httpd/GitOverHttpServlet.java
+++ b/java/com/google/gerrit/httpd/GitOverHttpServlet.java
@@ -22,6 +22,7 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.Capable;
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.registration.DynamicSet;
@@ -666,6 +667,7 @@
public void destroy() {}
}
+ @Nullable
private static String getSessionIdOrNull(Provider<WebSession> sessionProvider) {
WebSession session = sessionProvider.get();
if (session.isSignedIn()) {
diff --git a/java/com/google/gerrit/httpd/HtmlDomUtil.java b/java/com/google/gerrit/httpd/HtmlDomUtil.java
index 57f2664..16e0938 100644
--- a/java/com/google/gerrit/httpd/HtmlDomUtil.java
+++ b/java/com/google/gerrit/httpd/HtmlDomUtil.java
@@ -16,7 +16,9 @@
import static java.nio.charset.StandardCharsets.UTF_8;
+import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
+import com.google.gerrit.common.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -25,6 +27,8 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -39,6 +43,7 @@
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+import org.jsoup.parser.Parser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -47,6 +52,8 @@
/** Utility functions to deal with HTML using W3C DOM operations. */
public class HtmlDomUtil {
+ private static final FluentLogger logger = FluentLogger.forEnclosingClass();
+
/** Standard character encoding we prefer (UTF-8). */
public static final Charset ENC = UTF_8;
@@ -89,6 +96,7 @@
}
/** Find an element by its "id" attribute; null if no element is found. */
+ @Nullable
public static Element find(Node parent, String name) {
NodeList list = parent.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
@@ -139,6 +147,7 @@
}
/** Parse an XHTML file from our CLASSPATH and return the instance. */
+ @Nullable
public static Document parseFile(Class<?> context, String name) throws IOException {
try (InputStream in = context.getResourceAsStream(name)) {
if (in == null) {
@@ -168,6 +177,7 @@
}
/** Read a Read a UTF-8 text file from our CLASSPATH and return it. */
+ @Nullable
public static String readFile(Class<?> context, String name) throws IOException {
try (InputStream in = context.getResourceAsStream(name)) {
if (in == null) {
@@ -180,6 +190,7 @@
}
/** Parse an XHTML file from the local drive and return the instance. */
+ @Nullable
public static Document parseFile(Path path) throws IOException {
try (InputStream in = Files.newInputStream(path)) {
Document doc = newBuilder().parse(in);
@@ -193,6 +204,7 @@
}
/** Read a UTF-8 text file from the local drive. */
+ @Nullable
public static String readFile(Path parentDir, String name) throws IOException {
if (parentDir == null) {
return null;
@@ -215,4 +227,27 @@
factory.setCoalescing(true);
return factory.newDocumentBuilder();
}
+
+ /**
+ * Attaches nonce to all script elements in html.
+ *
+ * <p>The returned html is not guaranteed to have the same formatting as the input.
+ *
+ * @return Updated html or {#link Optional.empty()} if parsing failed.
+ */
+ public static Optional<String> attachNonce(String html, String nonce) {
+ Parser parser = Parser.htmlParser();
+ org.jsoup.nodes.Document document = parser.parseInput(html, "");
+ if (!parser.getErrors().isEmpty()) {
+ logger.atSevere().atMostEvery(5, TimeUnit.MINUTES).log(
+ "Html couldn't be parsed to attach nonce. Errors: %s", parser.getErrors());
+ return Optional.empty();
+ }
+ document.getElementsByTag("script").attr("nonce", nonce);
+ return Optional.of(
+ document
+ .outputSettings(
+ new org.jsoup.nodes.Document.OutputSettings().prettyPrint(false).indentAmount(0))
+ .outerHtml());
+ }
}
diff --git a/java/com/google/gerrit/httpd/HttpCanonicalWebUrlProvider.java b/java/com/google/gerrit/httpd/HttpCanonicalWebUrlProvider.java
index 6943faa..85dc200 100644
--- a/java/com/google/gerrit/httpd/HttpCanonicalWebUrlProvider.java
+++ b/java/com/google/gerrit/httpd/HttpCanonicalWebUrlProvider.java
@@ -14,6 +14,8 @@
package com.google.gerrit.httpd;
+import com.google.gerrit.common.UsedAt;
+import com.google.gerrit.common.UsedAt.Project;
import com.google.gerrit.server.config.CanonicalWebUrlProvider;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
@@ -30,7 +32,8 @@
private Provider<HttpServletRequest> requestProvider;
@Inject
- HttpCanonicalWebUrlProvider(@GerritServerConfig Config config) {
+ @UsedAt(Project.MODULE_VIRTUALHOST)
+ protected HttpCanonicalWebUrlProvider(@GerritServerConfig Config config) {
super(config);
}
diff --git a/java/com/google/gerrit/httpd/ProjectOAuthFilter.java b/java/com/google/gerrit/httpd/ProjectOAuthFilter.java
index de6ae50..5a99cab 100644
--- a/java/com/google/gerrit/httpd/ProjectOAuthFilter.java
+++ b/java/com/google/gerrit/httpd/ProjectOAuthFilter.java
@@ -23,6 +23,7 @@
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.BaseEncoding;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.auth.oauth.OAuthLoginProvider;
import com.google.gerrit.extensions.registration.DynamicItem;
@@ -226,6 +227,7 @@
}
}
+ @Nullable
private AuthInfo extractAuthInfo(String hdr, String encoding)
throws UnsupportedEncodingException {
byte[] decoded = BaseEncoding.base64().decode(hdr.substring(BASIC.length()));
@@ -241,6 +243,7 @@
defaultAuthProvider);
}
+ @Nullable
private AuthInfo extractAuthInfo(Cookie cookie) throws UnsupportedEncodingException {
String username =
URLDecoder.decode(cookie.getName().substring(GIT_COOKIE_PREFIX.length()), UTF_8.name());
@@ -272,6 +275,7 @@
return MoreObjects.firstNonNull(req.getCharacterEncoding(), UTF_8.name());
}
+ @Nullable
private static Cookie findGitCookie(HttpServletRequest req) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
diff --git a/java/com/google/gerrit/httpd/RemoteUserUtil.java b/java/com/google/gerrit/httpd/RemoteUserUtil.java
index 84954dc..6f3e9c4 100644
--- a/java/com/google/gerrit/httpd/RemoteUserUtil.java
+++ b/java/com/google/gerrit/httpd/RemoteUserUtil.java
@@ -19,6 +19,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.io.BaseEncoding;
+import com.google.gerrit.common.Nullable;
import javax.servlet.http.HttpServletRequest;
public class RemoteUserUtil {
@@ -62,6 +63,7 @@
* @param auth header value which is used for extracting.
* @return username if available or null.
*/
+ @Nullable
public static String extractUsername(String auth) {
auth = emptyToNull(auth);
diff --git a/java/com/google/gerrit/httpd/UrlModule.java b/java/com/google/gerrit/httpd/UrlModule.java
index 029efba..69adf82 100644
--- a/java/com/google/gerrit/httpd/UrlModule.java
+++ b/java/com/google/gerrit/httpd/UrlModule.java
@@ -92,11 +92,17 @@
// which is bound in HttpPluginModule. We cannot bind it here again although
// this means that plugins can't add REST views on PLUGIN_KIND.
serveRegex("^/(?:a/)?access/(.*)$").with(AccessRestApiServlet.class);
+ serveRegex("^/(?:a/)?access$").with(AccessRestApiServlet.class);
serveRegex("^/(?:a/)?accounts/(.*)$").with(AccountsRestApiServlet.class);
+ serveRegex("^/(?:a/)?accounts$").with(AccountsRestApiServlet.class);
serveRegex("^/(?:a/)?changes/(.*)$").with(ChangesRestApiServlet.class);
+ serveRegex("^/(?:a/)?changes$").with(ChangesRestApiServlet.class);
serveRegex("^/(?:a/)?config/(.*)$").with(ConfigRestApiServlet.class);
+ serveRegex("^/(?:a/)?config$").with(ConfigRestApiServlet.class);
serveRegex("^/(?:a/)?groups/(.*)?$").with(GroupsRestApiServlet.class);
+ serveRegex("^/(?:a/)?groups$").with(GroupsRestApiServlet.class);
serveRegex("^/(?:a/)?projects/(.*)?$").with(ProjectsRestApiServlet.class);
+ serveRegex("^/(?:a/)?projects$").with(ProjectsRestApiServlet.class);
serveRegex("^/Documentation$").with(redirectDocumentation());
serveRegex("^/Documentation/$").with(redirectDocumentation());
diff --git a/java/com/google/gerrit/httpd/WebSessionManager.java b/java/com/google/gerrit/httpd/WebSessionManager.java
index 87bf3a6..1137b65 100644
--- a/java/com/google/gerrit/httpd/WebSessionManager.java
+++ b/java/com/google/gerrit/httpd/WebSessionManager.java
@@ -30,6 +30,7 @@
import com.google.common.cache.Cache;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.server.account.externalids.ExternalId;
import com.google.gerrit.server.account.externalids.ExternalIdKeyFactory;
@@ -149,6 +150,7 @@
return -1;
}
+ @Nullable
Val get(Key key) {
Val val = self.getIfPresent(key.token);
if (val != null && val.expiresAt <= nowMs()) {
diff --git a/java/com/google/gerrit/httpd/auth/become/BecomeAnyAccountLoginServlet.java b/java/com/google/gerrit/httpd/auth/become/BecomeAnyAccountLoginServlet.java
index 2f760f0..bc8a01a 100644
--- a/java/com/google/gerrit/httpd/auth/become/BecomeAnyAccountLoginServlet.java
+++ b/java/com/google/gerrit/httpd/auth/become/BecomeAnyAccountLoginServlet.java
@@ -17,6 +17,7 @@
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_UUID;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.registration.DynamicItem;
@@ -185,6 +186,7 @@
return account.map(a -> new AuthResult(a.account().id(), null, false));
}
+ @Nullable
private AuthResult auth(Account.Id account) {
if (account != null) {
return new AuthResult(account, null, false);
@@ -192,6 +194,7 @@
return null;
}
+ @Nullable
private AuthResult byUserName(String userName) {
List<AccountState> accountStates = queryProvider.get().byExternalId(SCHEME_USERNAME, userName);
if (accountStates.isEmpty()) {
@@ -223,6 +226,7 @@
}
}
+ @Nullable
private AuthResult create() throws IOException {
try {
return accountManager.authenticate(
diff --git a/java/com/google/gerrit/httpd/auth/container/HttpAuthFilter.java b/java/com/google/gerrit/httpd/auth/container/HttpAuthFilter.java
index 5a5de0a..f0a8b89 100644
--- a/java/com/google/gerrit/httpd/auth/container/HttpAuthFilter.java
+++ b/java/com/google/gerrit/httpd/auth/container/HttpAuthFilter.java
@@ -21,6 +21,7 @@
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.httpd.HtmlDomUtil;
import com.google.gerrit.httpd.RemoteUserUtil;
@@ -143,6 +144,7 @@
: remoteUser;
}
+ @Nullable
String getRemoteDisplayname(HttpServletRequest req) {
if (displaynameHeader != null) {
String raw = emptyToNull(req.getHeader(displaynameHeader));
@@ -153,6 +155,7 @@
return null;
}
+ @Nullable
String getRemoteEmail(HttpServletRequest req) {
if (emailHeader != null) {
return emptyToNull(req.getHeader(emailHeader));
@@ -160,6 +163,7 @@
return null;
}
+ @Nullable
String getRemoteExternalIdToken(HttpServletRequest req) {
if (externalIdHeader != null) {
return emptyToNull(req.getHeader(externalIdHeader));
diff --git a/java/com/google/gerrit/httpd/auth/openid/LoginForm.java b/java/com/google/gerrit/httpd/auth/openid/LoginForm.java
index 0b6008c..e7057ad 100644
--- a/java/com/google/gerrit/httpd/auth/openid/LoginForm.java
+++ b/java/com/google/gerrit/httpd/auth/openid/LoginForm.java
@@ -334,6 +334,7 @@
form.appendChild(div);
}
+ @Nullable
private OAuthServiceProvider lookupOAuthServiceProvider(String providerId) {
if (providerId.startsWith("http://")) {
providerId = providerId.substring("http://".length());
@@ -350,6 +351,7 @@
return null;
}
+ @Nullable
private static String getLastId(HttpServletRequest req) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
diff --git a/java/com/google/gerrit/httpd/auth/openid/OpenIdServiceImpl.java b/java/com/google/gerrit/httpd/auth/openid/OpenIdServiceImpl.java
index fcd16ae..0c71d68 100644
--- a/java/com/google/gerrit/httpd/auth/openid/OpenIdServiceImpl.java
+++ b/java/com/google/gerrit/httpd/auth/openid/OpenIdServiceImpl.java
@@ -15,6 +15,7 @@
package com.google.gerrit.httpd.auth.openid;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.auth.openid.OpenIdUrls;
import com.google.gerrit.entities.Account;
@@ -518,6 +519,7 @@
rsp.sendRedirect(rdr.toString());
}
+ @Nullable
private State init(
HttpServletRequest req,
final String openidIdentifier,
diff --git a/java/com/google/gerrit/httpd/auth/restapi/BUILD b/java/com/google/gerrit/httpd/auth/restapi/BUILD
index d499768..9ab51c5 100644
--- a/java/com/google/gerrit/httpd/auth/restapi/BUILD
+++ b/java/com/google/gerrit/httpd/auth/restapi/BUILD
@@ -6,6 +6,7 @@
visibility = ["//visibility:public"],
deps = [
"//java/com/google/gerrit/auth",
+ "//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/server",
"//lib/flogger:api",
diff --git a/java/com/google/gerrit/httpd/auth/restapi/GetOAuthToken.java b/java/com/google/gerrit/httpd/auth/restapi/GetOAuthToken.java
index 3594c7c..2eee415 100644
--- a/java/com/google/gerrit/httpd/auth/restapi/GetOAuthToken.java
+++ b/java/com/google/gerrit/httpd/auth/restapi/GetOAuthToken.java
@@ -16,6 +16,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.auth.oauth.OAuthTokenCache;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.auth.oauth.OAuthToken;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -70,6 +71,7 @@
return Response.ok(accessTokenInfo);
}
+ @Nullable
private static String getHostName(String canonicalWebUrl) {
if (canonicalWebUrl == null) {
logger.atSevere().log(
diff --git a/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java b/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java
index 4c31253..d6718ca 100644
--- a/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java
+++ b/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java
@@ -79,6 +79,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -111,6 +112,7 @@
private final Provider<CurrentUser> userProvider;
private final EnvList _env;
+ @SuppressWarnings("CheckReturnValue")
@Inject
GitwebServlet(
GitRepositoryManager repoManager,
@@ -158,7 +160,7 @@
if (!_env.envMap.containsKey("SystemRoot")) {
String os = System.getProperty("os.name");
- if (os != null && os.toLowerCase().contains("windows")) {
+ if (os != null && os.toLowerCase(Locale.US).contains("windows")) {
String sysroot = System.getenv("SystemRoot");
if (sysroot == null || sysroot.isEmpty()) {
sysroot = "C:\\WINDOWS";
@@ -575,7 +577,7 @@
for (String name : getHeaderNames(req)) {
final String value = req.getHeader(name);
- env.set("HTTP_" + name.toUpperCase().replace('-', '_'), value);
+ env.set("HTTP_" + name.toUpperCase(Locale.US).replace('-', '_'), value);
}
Project.NameKey nameKey = projectState.getNameKey();
diff --git a/java/com/google/gerrit/httpd/init/WebAppInitializer.java b/java/com/google/gerrit/httpd/init/WebAppInitializer.java
index dcabac0..e3cc0a5 100644
--- a/java/com/google/gerrit/httpd/init/WebAppInitializer.java
+++ b/java/com/google/gerrit/httpd/init/WebAppInitializer.java
@@ -46,6 +46,7 @@
import com.google.gerrit.lucene.LuceneIndexModule;
import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker;
import com.google.gerrit.pgm.util.LogFileCompressor.LogFileCompressorModule;
+import com.google.gerrit.server.DefaultRefLogIdentityProvider;
import com.google.gerrit.server.LibModuleLoader;
import com.google.gerrit.server.LibModuleType;
import com.google.gerrit.server.ModuleOverloader;
@@ -55,6 +56,7 @@
import com.google.gerrit.server.account.externalids.ExternalIdCaseSensitivityMigrator;
import com.google.gerrit.server.api.GerritApiModule;
import com.google.gerrit.server.api.PluginApiModule;
+import com.google.gerrit.server.api.projects.ProjectQueryBuilderModule;
import com.google.gerrit.server.audit.AuditModule;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
@@ -308,6 +310,8 @@
modules.add(new MimeUtil2Module());
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new GerritApiModule());
+ modules.add(new ProjectQueryBuilderModule());
+ modules.add(new DefaultRefLogIdentityProvider.Module());
modules.add(new PluginApiModule());
modules.add(new ChangesByProjectCache.Module(ChangesByProjectCache.UseIndex.TRUE, config));
modules.add(new InternalAccountDirectoryModule());
diff --git a/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java b/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java
index a03aa36..9b8f4c6 100644
--- a/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java
+++ b/java/com/google/gerrit/httpd/plugins/HttpPluginServlet.java
@@ -35,6 +35,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import com.google.common.net.HttpHeaders;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.httpd.resources.Resource;
import com.google.gerrit.httpd.resources.ResourceKey;
import com.google.gerrit.httpd.resources.SmallResource;
@@ -174,6 +175,7 @@
plugins.put(name, holder);
}
+ @Nullable
private GuiceFilter load(Plugin plugin) {
if (plugin.getHttpInjector() != null) {
final String name = plugin.getName();
@@ -327,6 +329,7 @@
}
}
+ @Nullable
private static Pattern makeAllowOrigin(Config cfg) {
String[] allow = cfg.getStringList("site", null, "allowOriginRegex");
if (allow.length > 0) {
@@ -720,6 +723,7 @@
this.docPrefix = getPrefix(plugin, "Gerrit-HttpDocumentationPrefix", "Documentation/");
}
+ @Nullable
private static String getPrefix(Plugin plugin, String attr, String def) {
Path path = plugin.getSrcFile();
PluginContentScanner scanner = plugin.getContentScanner();
diff --git a/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java b/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java
index fc0ec39..ed29629 100644
--- a/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java
+++ b/java/com/google/gerrit/httpd/plugins/LfsPluginServlet.java
@@ -19,6 +19,7 @@
import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.httpd.resources.Resource;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.plugins.Plugin;
@@ -119,6 +120,7 @@
filter.set(guiceFilter);
}
+ @Nullable
private GuiceFilter load(Plugin plugin) {
if (plugin.getHttpInjector() != null) {
final String name = plugin.getName();
diff --git a/java/com/google/gerrit/httpd/raw/DirectoryDocServlet.java b/java/com/google/gerrit/httpd/raw/DirectoryDocServlet.java
index c13286e..3f59084 100644
--- a/java/com/google/gerrit/httpd/raw/DirectoryDocServlet.java
+++ b/java/com/google/gerrit/httpd/raw/DirectoryDocServlet.java
@@ -15,15 +15,17 @@
package com.google.gerrit.httpd.raw;
import com.google.common.cache.Cache;
+import com.google.gerrit.server.experiments.ExperimentFeatures;
import java.nio.file.Path;
-class DirectoryDocServlet extends ResourceServlet {
+class DirectoryDocServlet extends DocServlet {
private static final long serialVersionUID = 1L;
private final Path doc;
- DirectoryDocServlet(Cache<Path, Resource> cache, Path unpackedWar) {
- super(cache, true);
+ DirectoryDocServlet(
+ Cache<Path, Resource> cache, Path unpackedWar, ExperimentFeatures experimentFeatures) {
+ super(cache, true, experimentFeatures);
this.doc = unpackedWar.resolve("Documentation");
}
diff --git a/java/com/google/gerrit/httpd/raw/DocServlet.java b/java/com/google/gerrit/httpd/raw/DocServlet.java
new file mode 100644
index 0000000..d5027ba
--- /dev/null
+++ b/java/com/google/gerrit/httpd/raw/DocServlet.java
@@ -0,0 +1,65 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.httpd.raw;
+
+import static com.google.gerrit.server.experiments.ExperimentFeaturesConstants.GERRIT_BACKEND_FEATURE_ATTACH_NONCE_TO_DOCUMENTATION;
+
+import com.google.common.cache.Cache;
+import com.google.gerrit.httpd.HtmlDomUtil;
+import com.google.gerrit.server.experiments.ExperimentFeatures;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.Optional;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+abstract class DocServlet extends ResourceServlet {
+ private static final long serialVersionUID = 1L;
+
+ private final ExperimentFeatures experimentFeatures;
+
+ DocServlet(Cache<Path, Resource> cache, boolean refresh, ExperimentFeatures experimentFeatures) {
+ super(cache, refresh);
+ this.experimentFeatures = experimentFeatures;
+ }
+
+ @Override
+ protected boolean shouldProcessResourceBeforeServe(
+ HttpServletRequest req, HttpServletResponse rsp, Path p) {
+ String nonce = (String) req.getAttribute("nonce");
+ if (!experimentFeatures.isFeatureEnabled(GERRIT_BACKEND_FEATURE_ATTACH_NONCE_TO_DOCUMENTATION)
+ || nonce == null) {
+ return false;
+ }
+ return ResourceServlet.contentType(p.toString()).equals("text/html");
+ }
+
+ @Override
+ protected Resource processResourceBeforeServe(
+ HttpServletRequest req, HttpServletResponse rsp, Resource resource) {
+ // ResourceServlet doesn't set character encoding for a resource. Gerrit will
+ // default to setting charset to utf-8, if none provided. So we guess UTF_8 here.
+ Optional<String> updatedHtml =
+ HtmlDomUtil.attachNonce(
+ new String(resource.raw, StandardCharsets.UTF_8), (String) req.getAttribute("nonce"));
+ if (updatedHtml.isEmpty()) {
+ return resource;
+ }
+ return new Resource(
+ resource.lastModified,
+ resource.contentType,
+ updatedHtml.get().getBytes(StandardCharsets.UTF_8));
+ }
+}
diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
index 72bfe40..fb28d30 100644
--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
+++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
@@ -101,6 +101,7 @@
IndexPreloadingUtil.computeChangeRequestsPath(requestedPath, page).get());
data.put("changeNum", IndexPreloadingUtil.computeChangeNum(requestedPath, page).get());
break;
+ case PROFILE:
case DASHBOARD:
// Dashboard is preloaded queries are added later when we check user is authenticated.
case PAGE_WITHOUT_PRELOADING:
@@ -121,7 +122,7 @@
data.put("userIsAuthenticated", true);
if (page == RequestedPage.DASHBOARD) {
data.put("defaultDashboardHex", ListOption.toHex(IndexPreloadingUtil.DASHBOARD_OPTIONS));
- data.put("dashboardQuery", IndexPreloadingUtil.computeDashboardQueryList(serverApi));
+ data.put("dashboardQuery", IndexPreloadingUtil.computeDashboardQueryList());
}
} catch (AuthException e) {
logger.atFine().log("Can't inline account-related data because user is unauthenticated");
diff --git a/java/com/google/gerrit/httpd/raw/IndexPreloadingUtil.java b/java/com/google/gerrit/httpd/raw/IndexPreloadingUtil.java
index f7c3681..36fa61b 100644
--- a/java/com/google/gerrit/httpd/raw/IndexPreloadingUtil.java
+++ b/java/com/google/gerrit/httpd/raw/IndexPreloadingUtil.java
@@ -22,9 +22,7 @@
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.UsedAt;
import com.google.gerrit.common.UsedAt.Project;
-import com.google.gerrit.extensions.api.config.Server;
import com.google.gerrit.extensions.client.ListChangesOption;
-import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.Url;
import java.net.URI;
import java.net.URISyntaxException;
@@ -42,6 +40,7 @@
CHANGE,
DIFF,
DASHBOARD,
+ PROFILE,
PAGE_WITHOUT_PRELOADING,
}
@@ -52,31 +51,28 @@
public static final Pattern DIFF_URL_PATTERN =
Pattern.compile(CHANGE_CANONICAL_PATH + BASE_PATCH_NUM_PATH_PART + "(/(.+))" + "/?$");
public static final Pattern DASHBOARD_PATTERN = Pattern.compile("/dashboard/self$");
+ public static final Pattern PROFILE_PATTERN = Pattern.compile("/profile/self$");
public static final String ROOT_PATH = "/";
// These queries should be kept in sync with PolyGerrit:
// polygerrit-ui/app/elements/core/gr-navigation/gr-navigation.ts
public static final String DASHBOARD_HAS_UNPUBLISHED_DRAFTS_QUERY = "has:draft limit:10";
public static final String YOUR_TURN = "attention:${user} limit:25";
- public static final String DASHBOARD_ASSIGNED_QUERY =
- "assignee:${user} (-is:wip OR " + "owner:self OR assignee:self) is:open limit:25";
public static final String DASHBOARD_WORK_IN_PROGRESS_QUERY =
"is:open owner:${user} is:wip limit:25";
public static final String DASHBOARD_OUTGOING_QUERY = "is:open owner:${user} -is:wip limit:25";
public static final String DASHBOARD_INCOMING_QUERY =
- "is:open -owner:${user} -is:wip (reviewer:${user} OR assignee:${user}) limit:25";
+ "is:open -owner:${user} -is:wip reviewer:${user} limit:25";
public static final String CC_QUERY = "is:open -is:wip cc:${user} limit:10";
public static final String DASHBOARD_RECENTLY_CLOSED_QUERY =
"is:closed (-is:wip OR owner:self) "
- + "(owner:${user} OR reviewer:${user} OR assignee:${user} "
- + "OR cc:${user}) -age:4w limit:10";
+ + "(owner:${user} OR reviewer:${user} OR cc:${user}) "
+ + "-age:4w limit:10";
public static final String NEW_USER = "owner:${user} limit:1";
public static final String SELF_DASHBOARD_HAS_UNPUBLISHED_DRAFTS_QUERY =
DASHBOARD_HAS_UNPUBLISHED_DRAFTS_QUERY.replaceAll("\\$\\{user}", "self");
public static final String SELF_YOUR_TURN = YOUR_TURN.replaceAll("\\$\\{user}", "self");
- public static final String SELF_DASHBOARD_ASSIGNED_QUERY =
- DASHBOARD_ASSIGNED_QUERY.replaceAll("\\$\\{user}", "self");
public static final ImmutableList<String> SELF_DASHBOARD_QUERIES =
Stream.of(
DASHBOARD_WORK_IN_PROGRESS_QUERY,
@@ -107,6 +103,7 @@
ListChangesOption.SKIP_DIFFSTAT,
ListChangesOption.SUBMIT_REQUIREMENTS);
+ @Nullable
public static String getPath(@Nullable String requestedURL) throws URISyntaxException {
if (requestedURL == null) {
return null;
@@ -136,6 +133,11 @@
return RequestedPage.DASHBOARD;
}
+ Matcher profileMatcher = IndexPreloadingUtil.PROFILE_PATTERN.matcher(requestedPath);
+ if (profileMatcher.matches()) {
+ return RequestedPage.PROFILE;
+ }
+
if (ROOT_PATH.equals(requestedPath)) {
return RequestedPage.DASHBOARD;
}
@@ -154,6 +156,7 @@
matcher = DIFF_URL_PATTERN.matcher(requestedURL);
break;
case DASHBOARD:
+ case PROFILE:
case PAGE_WITHOUT_PRELOADING:
default:
return Optional.empty();
@@ -178,6 +181,7 @@
matcher = DIFF_URL_PATTERN.matcher(requestedURL);
break;
case DASHBOARD:
+ case PROFILE:
case PAGE_WITHOUT_PRELOADING:
default:
return Optional.empty();
@@ -192,34 +196,14 @@
return Optional.empty();
}
- public static List<String> computeDashboardQueryList(Server serverApi) throws RestApiException {
+ public static List<String> computeDashboardQueryList() {
List<String> queryList = new ArrayList<>();
queryList.add(SELF_DASHBOARD_HAS_UNPUBLISHED_DRAFTS_QUERY);
- if (isEnabledAttentionSet(serverApi)) {
- queryList.add(SELF_YOUR_TURN);
- }
- if (isEnabledAssignee(serverApi)) {
- queryList.add(SELF_DASHBOARD_ASSIGNED_QUERY);
- }
-
+ queryList.add(SELF_YOUR_TURN);
queryList.addAll(SELF_DASHBOARD_QUERIES);
return queryList;
}
- private static boolean isEnabledAttentionSet(Server serverApi) throws RestApiException {
- return serverApi.getInfo() != null
- && serverApi.getInfo().change != null
- && serverApi.getInfo().change.enableAttentionSet != null
- && serverApi.getInfo().change.enableAttentionSet;
- }
-
- private static boolean isEnabledAssignee(Server serverApi) throws RestApiException {
- return serverApi.getInfo() != null
- && serverApi.getInfo().change != null
- && serverApi.getInfo().change.enableAssignee != null
- && serverApi.getInfo().change.enableAssignee;
- }
-
private IndexPreloadingUtil() {}
}
diff --git a/java/com/google/gerrit/httpd/raw/ResourceServlet.java b/java/com/google/gerrit/httpd/raw/ResourceServlet.java
index 8be4abc..871ec78 100644
--- a/java/com/google/gerrit/httpd/raw/ResourceServlet.java
+++ b/java/com/google/gerrit/httpd/raw/ResourceServlet.java
@@ -126,6 +126,34 @@
*/
protected abstract Path getResourcePath(String pathInfo) throws IOException;
+ /**
+ * Indicates that resource requires some processing before being served.
+ *
+ * <p>If true, the caching headers in response are set to not cache. Additionally, streaming
+ * option is disabled.
+ *
+ * @param req the HTTP servlet request
+ * @param rsp the HTTP servlet response
+ * @param p URL path
+ * @return true if the {@link #processResourceBeforeServe(HttpServletRequest, HttpServletResponse,
+ * Resource)} should be called.
+ */
+ protected boolean shouldProcessResourceBeforeServe(
+ HttpServletRequest req, HttpServletResponse rsp, Path p) {
+ return false;
+ }
+
+ /**
+ * Edits the resource before adding it to the response.
+ *
+ * @param req the HTTP servlet request
+ * @param rsp the HTTP servlet response
+ */
+ protected Resource processResourceBeforeServe(
+ HttpServletRequest req, HttpServletResponse rsp, Resource resource) {
+ return resource;
+ }
+
protected FileTime getLastModifiedTime(Path p) throws IOException {
return Files.getLastModifiedTime(p);
}
@@ -148,10 +176,11 @@
return;
}
+ boolean requiresPostProcess = shouldProcessResourceBeforeServe(req, rsp, p);
Resource r = cache.getIfPresent(p);
try {
if (r == null) {
- if (maybeStream(p, req, rsp)) {
+ if (!requiresPostProcess && maybeStream(p, req, rsp)) {
return; // Bypass cache for large resource.
}
r = cache.get(p, newLoader(p));
@@ -176,11 +205,16 @@
CacheHeaders.setNotCacheable(rsp);
rsp.setStatus(SC_NOT_FOUND);
return;
- } else if (cacheOnClient && r.etag.equals(req.getHeader(IF_NONE_MATCH))) {
+ } else if (!requiresPostProcess
+ && cacheOnClient
+ && r.etag.equals(req.getHeader(IF_NONE_MATCH))) {
rsp.setStatus(SC_NOT_MODIFIED);
return;
}
+ if (requiresPostProcess) {
+ r = processResourceBeforeServe(req, rsp, r);
+ }
byte[] tosend = r.raw;
if (!r.contentType.equals(JS) && RequestUtil.acceptsGzipEncoding(req)) {
byte[] gz = HtmlDomUtil.compress(tosend);
@@ -190,7 +224,7 @@
}
}
- if (cacheOnClient) {
+ if (!requiresPostProcess && cacheOnClient) {
rsp.setHeader(ETAG, r.etag);
} else {
CacheHeaders.setNotCacheable(rsp);
diff --git a/java/com/google/gerrit/httpd/raw/StaticModule.java b/java/com/google/gerrit/httpd/raw/StaticModule.java
index 15dcf42..8319d9d 100644
--- a/java/com/google/gerrit/httpd/raw/StaticModule.java
+++ b/java/com/google/gerrit/httpd/raw/StaticModule.java
@@ -77,9 +77,9 @@
"/x/*",
"/admin/*",
"/dashboard/*",
+ "/profile/*",
"/groups/self",
"/settings/*",
- "/topic/*",
"/Documentation/q/*");
/**
@@ -144,12 +144,13 @@
@Provides
@Singleton
@Named(DOC_SERVLET)
- HttpServlet getDocServlet(@Named(CACHE) Cache<Path, Resource> cache) {
+ HttpServlet getDocServlet(
+ @Named(CACHE) Cache<Path, Resource> cache, ExperimentFeatures experimentFeatures) {
Paths p = getPaths();
if (p.warFs != null) {
- return new WarDocServlet(cache, p.warFs);
+ return new WarDocServlet(cache, p.warFs, experimentFeatures);
} else if (p.unpackedWar != null && !p.isDev()) {
- return new DirectoryDocServlet(cache, p.unpackedWar);
+ return new DirectoryDocServlet(cache, p.unpackedWar, experimentFeatures);
} else {
return new HttpServlet() {
private static final long serialVersionUID = 1L;
@@ -305,6 +306,7 @@
sourceRoot = getSourceRootOrNull();
}
+ @Nullable
private static Path getSourceRootOrNull() {
try {
return GerritLauncher.resolveInSourceRoot(".");
@@ -313,6 +315,7 @@
}
}
+ @Nullable
private FileSystem getDistributionArchive(File war) throws IOException {
if (war == null) {
return null;
@@ -320,6 +323,7 @@
return GerritLauncher.getZipFileSystem(war.toPath());
}
+ @Nullable
private File getLauncherLoadedFrom() {
File war;
try {
@@ -441,6 +445,7 @@
super(req);
}
+ @Nullable
@Override
public String getPathInfo() {
String uri = getRequestURI();
diff --git a/java/com/google/gerrit/httpd/raw/WarDocServlet.java b/java/com/google/gerrit/httpd/raw/WarDocServlet.java
index 27520e3..718d46d 100644
--- a/java/com/google/gerrit/httpd/raw/WarDocServlet.java
+++ b/java/com/google/gerrit/httpd/raw/WarDocServlet.java
@@ -15,20 +15,22 @@
package com.google.gerrit.httpd.raw;
import com.google.common.cache.Cache;
+import com.google.gerrit.server.experiments.ExperimentFeatures;
import com.google.gerrit.server.util.time.TimeUtil;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
-class WarDocServlet extends ResourceServlet {
+class WarDocServlet extends DocServlet {
private static final long serialVersionUID = 1L;
private static final FileTime NOW = FileTime.fromMillis(TimeUtil.nowMs());
private final FileSystem warFs;
- WarDocServlet(Cache<Path, Resource> cache, FileSystem warFs) {
- super(cache, false);
+ WarDocServlet(
+ Cache<Path, Resource> cache, FileSystem warFs, ExperimentFeatures experimentFeatures) {
+ super(cache, false, experimentFeatures);
this.warFs = warFs;
}
diff --git a/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
index 543e794..44e7854 100644
--- a/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
+++ b/java/com/google/gerrit/httpd/restapi/RestApiServlet.java
@@ -30,7 +30,6 @@
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static com.google.common.net.HttpHeaders.ORIGIN;
import static com.google.common.net.HttpHeaders.VARY;
-import static com.google.gerrit.server.experiments.ExperimentFeaturesConstants.GERRIT_BACKEND_REQUEST_FEATURE_REMOVE_REVISION_ETAG;
import static java.math.RoundingMode.CEILING;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -120,9 +119,7 @@
import com.google.gerrit.server.cancellation.RequestStateContext;
import com.google.gerrit.server.cancellation.RequestStateProvider;
import com.google.gerrit.server.change.ChangeFinder;
-import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.config.GerritServerConfig;
-import com.google.gerrit.server.experiments.ExperimentFeatures;
import com.google.gerrit.server.group.GroupAuditService;
import com.google.gerrit.server.logging.Metadata;
import com.google.gerrit.server.logging.PerformanceLogContext;
@@ -270,7 +267,6 @@
final PluginSetContext<ExceptionHook> exceptionHooks;
final Injector injector;
final DynamicMap<DynamicOptions.DynamicBean> dynamicBeans;
- final ExperimentFeatures experimentFeatures;
final DeadlineChecker.Factory deadlineCheckerFactory;
final CancellationMetrics cancellationMetrics;
@@ -291,7 +287,6 @@
PluginSetContext<ExceptionHook> exceptionHooks,
Injector injector,
DynamicMap<DynamicOptions.DynamicBean> dynamicBeans,
- ExperimentFeatures experimentFeatures,
DeadlineChecker.Factory deadlineCheckerFactory,
CancellationMetrics cancellationMetrics) {
this.currentUser = currentUser;
@@ -310,11 +305,11 @@
allowOrigin = makeAllowOrigin(config);
this.injector = injector;
this.dynamicBeans = dynamicBeans;
- this.experimentFeatures = experimentFeatures;
this.deadlineCheckerFactory = deadlineCheckerFactory;
this.cancellationMetrics = cancellationMetrics;
}
+ @Nullable
private static Pattern makeAllowOrigin(Config cfg) {
String[] allow = cfg.getStringList("site", null, "allowOriginRegex");
if (allow.length > 0) {
@@ -854,17 +849,13 @@
}
}
+ @Nullable
private String getEtagWithRetry(
HttpServletRequest req, TraceContext traceContext, RestResource.HasETag rsrc) {
try (TraceTimer ignored =
TraceContext.newTimer(
"RestApiServlet#getEtagWithRetry:resource",
Metadata.builder().restViewName(rsrc.getClass().getSimpleName()).build())) {
- if (rsrc instanceof RevisionResource
- && globals.experimentFeatures.isFeatureEnabled(
- GERRIT_BACKEND_REQUEST_FEATURE_REMOVE_REVISION_ETAG)) {
- return null;
- }
return invokeRestEndpointWithRetry(
req,
traceContext,
@@ -1277,6 +1268,7 @@
return ((ParameterizedType) supertype).getActualTypeArguments()[2];
}
+ @Nullable
private Object parseRequest(HttpServletRequest req, Type type)
throws IOException, BadRequestException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IllegalAccessException, InstantiationException,
@@ -1394,22 +1386,21 @@
throw new BadRequestException("Expected JSON object");
}
- @SuppressWarnings("unchecked")
private static Object createInstance(Type type)
throws NoSuchMethodException, InstantiationException, IllegalAccessException,
InvocationTargetException {
if (type instanceof Class) {
- Class<Object> clazz = (Class<Object>) type;
- Constructor<Object> c = clazz.getDeclaredConstructor();
+ Class<?> clazz = (Class<?>) type;
+ Constructor<?> c = clazz.getDeclaredConstructor();
c.setAccessible(true);
return c.newInstance();
}
if (type instanceof ParameterizedType) {
Type rawType = ((ParameterizedType) type).getRawType();
- if (rawType instanceof Class && List.class.isAssignableFrom((Class<Object>) rawType)) {
+ if (rawType instanceof Class && List.class.isAssignableFrom((Class<?>) rawType)) {
return new ArrayList<>();
}
- if (rawType instanceof Class && Map.class.isAssignableFrom((Class<Object>) rawType)) {
+ if (rawType instanceof Class && Map.class.isAssignableFrom((Class<?>) rawType)) {
return new HashMap<>();
}
}
diff --git a/java/com/google/gerrit/httpd/template/SiteHeaderFooter.java b/java/com/google/gerrit/httpd/template/SiteHeaderFooter.java
index 655f4ca..2065a31 100644
--- a/java/com/google/gerrit/httpd/template/SiteHeaderFooter.java
+++ b/java/com/google/gerrit/httpd/template/SiteHeaderFooter.java
@@ -18,6 +18,7 @@
import com.google.common.base.Strings;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.httpd.HtmlDomUtil;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
@@ -125,6 +126,7 @@
return cssFile.isStale() || headerFile.isStale() || footerFile.isStale();
}
+ @Nullable
private static Element readXml(FileInfo src) throws IOException {
Document d = HtmlDomUtil.parseFile(src.path);
return d != null ? d.getDocumentElement() : null;
diff --git a/java/com/google/gerrit/index/FieldDef.java b/java/com/google/gerrit/index/FieldDef.java
deleted file mode 100644
index 1c2074b..0000000
--- a/java/com/google/gerrit/index/FieldDef.java
+++ /dev/null
@@ -1,215 +0,0 @@
-// Copyright (C) 2013 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.gerrit.index;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.CharMatcher;
-import com.google.gerrit.common.Nullable;
-import com.google.gerrit.exceptions.StorageException;
-import com.google.gerrit.index.SchemaFieldDefs.Getter;
-import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
-import com.google.gerrit.index.SchemaFieldDefs.Setter;
-import java.io.IOException;
-import java.sql.Timestamp;
-import java.util.Optional;
-
-/**
- * Definition of a field stored in the secondary index.
- *
- * <p>{@link FieldDef}-s must not be changed once introduced to the codebase. Instead, a new
- * FieldDef must be added and the old one removed from the schema (in two upgrade steps, see {@code
- * com.google.gerrit.index.IndexUpgradeValidator}).
- *
- * <p>Note that {@link FieldDef} does not override {@link Object#equals(Object)}. It relies on
- * instances being singletons so that the default (i.e. reference) comparison works.
- *
- * @param <I> input type from which documents are created and search results are returned.
- * @param <T> type that should be extracted from the input object when converting to an index
- * document.
- */
-public final class FieldDef<I, T> implements SchemaField<I, T> {
- public static FieldDef.Builder<String> exact(String name) {
- return new FieldDef.Builder<>(FieldType.EXACT, name);
- }
-
- public static FieldDef.Builder<String> fullText(String name) {
- return new FieldDef.Builder<>(FieldType.FULL_TEXT, name);
- }
-
- public static FieldDef.Builder<Integer> intRange(String name) {
- return new FieldDef.Builder<>(FieldType.INTEGER_RANGE, name).stored();
- }
-
- public static FieldDef.Builder<Integer> integer(String name) {
- return new FieldDef.Builder<>(FieldType.INTEGER, name);
- }
-
- public static FieldDef.Builder<String> prefix(String name) {
- return new FieldDef.Builder<>(FieldType.PREFIX, name);
- }
-
- public static FieldDef.Builder<byte[]> storedOnly(String name) {
- return new FieldDef.Builder<>(FieldType.STORED_ONLY, name).stored();
- }
-
- public static FieldDef.Builder<Timestamp> timestamp(String name) {
- return new FieldDef.Builder<>(FieldType.TIMESTAMP, name);
- }
-
- public static class Builder<T> {
- private final FieldType<T> type;
- private final String name;
- private boolean stored;
-
- public Builder(FieldType<T> type, String name) {
- this.type = requireNonNull(type);
- this.name = requireNonNull(name);
- }
-
- public Builder<T> stored() {
- this.stored = true;
- return this;
- }
-
- public <I> FieldDef<I, T> build(Getter<I, T> getter) {
- return new FieldDef<>(name, type, stored, false, getter, null);
- }
-
- public <I> FieldDef<I, T> build(Getter<I, T> getter, Setter<I, T> setter) {
- return new FieldDef<>(name, type, stored, false, getter, setter);
- }
-
- public <I> FieldDef<I, Iterable<T>> buildRepeatable(Getter<I, Iterable<T>> getter) {
- return new FieldDef<>(name, type, stored, true, getter, null);
- }
-
- public <I> FieldDef<I, Iterable<T>> buildRepeatable(
- Getter<I, Iterable<T>> getter, Setter<I, Iterable<T>> setter) {
- return new FieldDef<>(name, type, stored, true, getter, setter);
- }
- }
-
- private final String name;
- private final FieldType<?> type;
- /** Allow reading the actual data from the index. */
- private final boolean stored;
-
- private final boolean repeatable;
- private final Getter<I, T> getter;
- private final Optional<Setter<I, T>> setter;
-
- private FieldDef(
- String name,
- FieldType<?> type,
- boolean stored,
- boolean repeatable,
- Getter<I, T> getter,
- @Nullable Setter<I, T> setter) {
- checkArgument(
- !(repeatable && type == FieldType.INTEGER_RANGE),
- "Range queries against repeated fields are unsupported");
- this.name = checkName(name);
- this.type = requireNonNull(type);
- this.stored = stored;
- this.repeatable = repeatable;
- this.getter = requireNonNull(getter);
- this.setter = Optional.ofNullable(setter);
- }
-
- private static String checkName(String name) {
- CharMatcher m = CharMatcher.anyOf("abcdefghijklmnopqrstuvwxyz0123456789_");
- checkArgument(name != null && m.matchesAllOf(name), "illegal field name: %s", name);
- return name;
- }
-
- /** Returns name of the field. */
- @Override
- public String getName() {
- return name;
- }
-
- /** Returns type of the field; for repeatable fields, the inner type, not the iterable type. */
- @Override
- public FieldType<?> getType() {
- return type;
- }
-
- /** Returns whether the field should be stored in the index. */
- @Override
- public boolean isStored() {
- return stored;
- }
-
- /**
- * Get the field contents from the input object.
- *
- * @param input input object.
- * @return the field value(s) to index.
- */
- @Override
- @Nullable
- public T get(I input) {
- try {
- return getter.get(input);
- } catch (IOException e) {
- throw new StorageException(e);
- }
- }
-
- /**
- * Set the field contents back to an object. Used to reconstruct fields from indexed values. No-op
- * if the field can't be reconstructed.
- *
- * @param object input object.
- * @param doc indexed document
- * @return {@code true} if the field was set, {@code false} otherwise
- */
- @SuppressWarnings("unchecked")
- @Override
- public boolean setIfPossible(I object, StoredValue doc) {
- if (!setter.isPresent()) {
- return false;
- }
-
- if (FieldType.STRING_TYPES.stream().anyMatch(t -> t.getName().equals(getType().getName()))) {
- setter.get().set(object, (T) (isRepeatable() ? doc.asStrings() : doc.asString()));
- return true;
- } else if (FieldType.INTEGER_TYPES.stream()
- .anyMatch(t -> t.getName().equals(getType().getName()))) {
- setter.get().set(object, (T) (isRepeatable() ? doc.asIntegers() : doc.asInteger()));
- return true;
- } else if (FieldType.LONG.getName().equals(getType().getName())) {
- setter.get().set(object, (T) (isRepeatable() ? doc.asLongs() : doc.asLong()));
- return true;
- } else if (FieldType.STORED_ONLY.getName().equals(getType().getName())) {
- setter.get().set(object, (T) (isRepeatable() ? doc.asByteArrays() : doc.asByteArray()));
- return true;
- } else if (FieldType.TIMESTAMP.getName().equals(getType().getName())) {
- checkState(!isRepeatable(), "can't repeat timestamp values");
- setter.get().set(object, (T) doc.asTimestamp());
- return true;
- }
- return false;
- }
-
- /** Returns whether the field is repeatable. */
- @Override
- public boolean isRepeatable() {
- return repeatable;
- }
-}
diff --git a/java/com/google/gerrit/index/Index.java b/java/com/google/gerrit/index/Index.java
index cc3117d..870d827 100644
--- a/java/com/google/gerrit/index/Index.java
+++ b/java/com/google/gerrit/index/Index.java
@@ -60,6 +60,9 @@
*/
void replace(V obj);
+ /** Delete a document from the index by value */
+ void deleteByValue(V value);
+
/**
* Delete a document from the index by key.
*
@@ -153,4 +156,14 @@
default boolean isEnabled() {
return true;
}
+
+ /**
+ * Rewriter that should be invoked on queries to this index.
+ *
+ * <p>The default implementation does not do anything. Should be overridden by implementation, if
+ * needed.
+ */
+ default IndexRewriter<V> getIndexRewriter() {
+ return (in, opts) -> in;
+ }
}
diff --git a/java/com/google/gerrit/index/IndexType.java b/java/com/google/gerrit/index/IndexType.java
index 75f8351..d8c8f6a 100644
--- a/java/com/google/gerrit/index/IndexType.java
+++ b/java/com/google/gerrit/index/IndexType.java
@@ -19,6 +19,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
+import java.util.Locale;
import java.util.Optional;
/**
@@ -51,7 +52,7 @@
if (Strings.isNullOrEmpty(value)) {
return Optional.empty();
}
- value = value.toUpperCase().replace("-", "_");
+ value = value.toUpperCase(Locale.US).replace("-", "_");
IndexType type = new IndexType(value);
if (!Strings.isNullOrEmpty(System.getenv(ENV_VAR))) {
checkArgument(
@@ -67,7 +68,7 @@
}
public IndexType(@Nullable String type) {
- this.type = type == null ? getDefault() : type.toLowerCase();
+ this.type = type == null ? getDefault() : type.toLowerCase(Locale.US);
}
public static String getDefault() {
diff --git a/java/com/google/gerrit/index/IndexedField.java b/java/com/google/gerrit/index/IndexedField.java
index e44f562..94943d6 100644
--- a/java/com/google/gerrit/index/IndexedField.java
+++ b/java/com/google/gerrit/index/IndexedField.java
@@ -36,6 +36,7 @@
import java.lang.reflect.Type;
import java.sql.Timestamp;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.stream.StreamSupport;
@@ -118,7 +119,7 @@
/**
* Defines how {@link IndexedField} can be searched and how the index tokens are generated.
*
- * <p>Multiple {@link SearchSpec} can be defined on single {@link IndexedField}.
+ * <p>Multiple {@link SearchSpec} can be defined on a single {@link IndexedField}.
*
* <p>Depending on the implementation, indexes can choose to store {@link IndexedField} and {@link
* SearchSpec} separately. The searches are issues to {@link SearchSpec}.
@@ -249,6 +250,8 @@
public SearchSpec integerRange(String name) {
checkState(fieldType().equals(INTEGER_TYPE));
+ // we currently store all integer range fields, this may change in the future
+ checkState(stored());
return addSearchSpec(name, SearchOption.RANGE);
}
@@ -349,7 +352,8 @@
private static String checkName(String name) {
String allowedCharacters = "abcdefghijklmnopqrstuvwxyz0123456789_";
- CharMatcher m = CharMatcher.anyOf(allowedCharacters + allowedCharacters.toUpperCase());
+ CharMatcher m =
+ CharMatcher.anyOf(allowedCharacters + allowedCharacters.toUpperCase(Locale.US));
checkArgument(name != null && m.matchesAllOf(name), "illegal field name: %s", name);
return name;
}
@@ -357,13 +361,22 @@
private Map<String, SearchSpec> searchSpecs = new HashMap<>();
- /** The name to store this field under. */
+ /**
+ * The name to store this field under.
+ *
+ * <p>The name should use the UpperCamelCase format, see {@link Builder#checkName}.
+ */
public abstract String name();
/** Optional description of the field data. */
public abstract Optional<String> description();
- /** True if this field is mandatory. Default is false. */
+ /**
+ * True if this field is mandatory. Default is false.
+ *
+ * <p>This property is not enforced by the common indexing logic. It is up to the index
+ * implementations to enforce that the field is required.
+ */
public abstract boolean required();
/** Allow reading the actual data from the index. Default is false. */
@@ -375,6 +388,11 @@
/**
* Optional size constrain on the field. The size is not constrained if this property is {@link
* Optional#empty()}
+ *
+ * <p>This property is not enforced by the common indexing logic. It is up to the index
+ * implementations to enforce the size.
+ *
+ * <p>If the field is {@link #repeatable()}, the constraint applies to each element separately.
*/
public abstract Optional<Integer> size();
diff --git a/java/com/google/gerrit/index/Schema.java b/java/com/google/gerrit/index/Schema.java
index dda9ce5..974bb74 100644
--- a/java/com/google/gerrit/index/Schema.java
+++ b/java/com/google/gerrit/index/Schema.java
@@ -63,22 +63,6 @@
}
@SafeVarargs
- public final Builder<T> add(FieldDef<T, ?>... fields) {
- return add(ImmutableList.copyOf(fields));
- }
-
- public final Builder<T> add(ImmutableList<FieldDef<T, ?>> fields) {
- this.searchFields.addAll(fields);
- return this;
- }
-
- @SafeVarargs
- public final Builder<T> remove(FieldDef<T, ?>... fields) {
- this.searchFields.removeAll(Arrays.asList(fields));
- return this;
- }
-
- @SafeVarargs
public final Builder<T> addSearchSpecs(IndexedField<T, ?>.SearchSpec... searchSpecs) {
return addSearchSpecs(ImmutableList.copyOf(searchSpecs));
}
@@ -202,14 +186,17 @@
* @return all fields in this schema indexed by name.
*/
public final ImmutableMap<String, SchemaField<T, ?>> getSchemaFields() {
- return ImmutableMap.copyOf(schemaFields);
+ return schemaFields;
}
public final ImmutableMap<String, IndexedField<T, ?>> getIndexFields() {
return indexedFields;
}
- /** Returns all fields in this schema where {@link FieldDef#isStored()} is true. */
+ /**
+ * Returns names of {@link SchemaField} fields in this schema where {@link SchemaField#isStored()}
+ * is true.
+ */
public final ImmutableSet<String> getStoredFields() {
return storedFields;
}
diff --git a/java/com/google/gerrit/index/SchemaFieldDefs.java b/java/com/google/gerrit/index/SchemaFieldDefs.java
index e0b5dd2..36173c7 100644
--- a/java/com/google/gerrit/index/SchemaFieldDefs.java
+++ b/java/com/google/gerrit/index/SchemaFieldDefs.java
@@ -24,8 +24,8 @@
* Definition of a field stored in the secondary index.
*
* <p>{@link SchemaField}-s must not be changed once introduced to the codebase. Instead, a new
- * FieldDef must be added and the old one removed from the schema (in two upgrade steps, see
- * {@code com.google.gerrit.index.IndexUpgradeValidator}).
+ * {@link SchemaField} must be added and the old one removed from the schema (in two upgrade
+ * steps, see {@code com.google.gerrit.index.IndexUpgradeValidator}).
*
* @param <I> input type from which documents are created and search results are returned.
* @param <T> type that should be extracted from the input object when converting to an index
@@ -100,4 +100,12 @@
public interface Setter<I, T> {
void set(I object, T value);
}
+
+ public static boolean isProtoField(SchemaField<?, ?> schemaField) {
+ if (!(schemaField instanceof IndexedField<?, ?>.SearchSpec)) {
+ return false;
+ }
+ IndexedField<?, ?> indexedField = ((IndexedField<?, ?>.SearchSpec) schemaField).getField();
+ return indexedField.isProtoType() || indexedField.isProtoIterableType();
+ }
}
diff --git a/java/com/google/gerrit/index/SchemaUtil.java b/java/com/google/gerrit/index/SchemaUtil.java
index 8f47cf5..b358c63 100644
--- a/java/com/google/gerrit/index/SchemaUtil.java
+++ b/java/com/google/gerrit/index/SchemaUtil.java
@@ -70,33 +70,16 @@
return ImmutableSortedMap.copyOf(schemas);
}
- @SafeVarargs
- public static <V> Schema<V> schema(FieldDef<V, ?>... fields) {
- return new Schema.Builder<V>().version(0).add(fields).build();
- }
-
- @SafeVarargs
- public static <V> Schema<V> schema(int version, FieldDef<V, ?>... fields) {
- return new Schema.Builder<V>().version(version).add(fields).build();
- }
-
- public static <V> Schema<V> schema(int version, ImmutableList<FieldDef<V, ?>> fields) {
- return new Schema.Builder<V>().version(version).add(fields).build();
- }
-
- @SafeVarargs
- public static <V> Schema<V> schema(Schema<V> schema, FieldDef<V, ?>... moreFields) {
- return new Schema.Builder<V>().add(schema).add(moreFields).build();
+ public static <V> Schema<V> schema(int version) {
+ return new Schema.Builder<V>().version(version).build();
}
public static <V> Schema<V> schema(
int version,
- ImmutableList<FieldDef<V, ?>> fieldDefs,
ImmutableList<IndexedField<V, ?>> indexedFields,
ImmutableList<IndexedField<V, ?>.SearchSpec> searchSpecs) {
return new Schema.Builder<V>()
.version(version)
- .add(fieldDefs)
.addIndexedFields(indexedFields)
.addSearchSpecs(searchSpecs)
.build();
@@ -104,22 +87,23 @@
public static <V> Schema<V> schema(
Schema<V> schema,
- ImmutableList<FieldDef<V, ?>> fieldDefs,
ImmutableList<IndexedField<V, ?>> indexedFields,
ImmutableList<IndexedField<V, ?>.SearchSpec> searchSpecs) {
return new Schema.Builder<V>()
.add(schema)
- .add(fieldDefs)
.addIndexedFields(indexedFields)
.addSearchSpecs(searchSpecs)
.build();
}
+ public static <V> Schema<V> schema(Schema<V> schema) {
+ return new Schema.Builder<V>().add(schema).build();
+ }
+
public static <V> Schema<V> schema(
- ImmutableList<FieldDef<V, ?>> fieldDefs,
ImmutableList<IndexedField<V, ?>> indexFields,
ImmutableList<IndexedField<V, ?>.SearchSpec> searchSpecs) {
- return schema(/* version= */ 0, fieldDefs, indexFields, searchSpecs);
+ return schema(/* version= */ 0, indexFields, searchSpecs);
}
public static Set<String> getPersonParts(PersonIdent person) {
diff --git a/java/com/google/gerrit/index/project/ProjectField.java b/java/com/google/gerrit/index/project/ProjectField.java
index 3114b4c..ff55546 100644
--- a/java/com/google/gerrit/index/project/ProjectField.java
+++ b/java/com/google/gerrit/index/project/ProjectField.java
@@ -15,14 +15,10 @@
package com.google.gerrit.index.project;
import static com.google.common.collect.ImmutableList.toImmutableList;
-import static com.google.gerrit.index.FieldDef.exact;
-import static com.google.gerrit.index.FieldDef.fullText;
-import static com.google.gerrit.index.FieldDef.prefix;
-import static com.google.gerrit.index.FieldDef.storedOnly;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
-import com.google.gerrit.index.FieldDef;
+import com.google.gerrit.index.IndexedField;
import com.google.gerrit.index.RefState;
import com.google.gerrit.index.SchemaUtil;
@@ -38,23 +34,53 @@
.toByteArray(project.getNameKey());
}
- public static final FieldDef<ProjectData, String> NAME =
- exact("name").stored().build(p -> p.getProject().getName());
+ public static final IndexedField<ProjectData, String> NAME_FIELD =
+ IndexedField.<ProjectData>stringBuilder("RepoName")
+ .required()
+ .size(200)
+ .stored()
+ .build(p -> p.getProject().getName());
- public static final FieldDef<ProjectData, String> DESCRIPTION =
- fullText("description").stored().build(p -> p.getProject().getDescription());
+ public static final IndexedField<ProjectData, String>.SearchSpec NAME_SPEC =
+ NAME_FIELD.exact("name");
- public static final FieldDef<ProjectData, String> PARENT_NAME =
- exact("parent_name").build(p -> p.getProject().getParentName());
+ public static final IndexedField<ProjectData, String> DESCRIPTION_FIELD =
+ IndexedField.<ProjectData>stringBuilder("Description")
+ .stored()
+ .build(p -> p.getProject().getDescription());
- public static final FieldDef<ProjectData, Iterable<String>> NAME_PART =
- prefix("name_part").buildRepeatable(p -> SchemaUtil.getNameParts(p.getProject().getName()));
+ public static final IndexedField<ProjectData, String>.SearchSpec DESCRIPTION_SPEC =
+ DESCRIPTION_FIELD.fullText("description");
- public static final FieldDef<ProjectData, String> STATE =
- exact("state").stored().build(p -> p.getProject().getState().name());
+ public static final IndexedField<ProjectData, String> PARENT_NAME_FIELD =
+ IndexedField.<ProjectData>stringBuilder("ParentName")
+ .build(p -> p.getProject().getParentName());
- public static final FieldDef<ProjectData, Iterable<String>> ANCESTOR_NAME =
- exact("ancestor_name").buildRepeatable(ProjectData::getParentNames);
+ public static final IndexedField<ProjectData, String>.SearchSpec PARENT_NAME_SPEC =
+ PARENT_NAME_FIELD.exact("parent_name");
+
+ public static final IndexedField<ProjectData, Iterable<String>> NAME_PART_FIELD =
+ IndexedField.<ProjectData>iterableStringBuilder("NamePart")
+ .size(200)
+ .build(p -> SchemaUtil.getNameParts(p.getProject().getName()));
+
+ public static final IndexedField<ProjectData, Iterable<String>>.SearchSpec NAME_PART_SPEC =
+ NAME_PART_FIELD.prefix("name_part");
+
+ public static final IndexedField<ProjectData, String> STATE_FIELD =
+ IndexedField.<ProjectData>stringBuilder("State")
+ .stored()
+ .build(p -> p.getProject().getState().name());
+
+ public static final IndexedField<ProjectData, String>.SearchSpec STATE_SPEC =
+ STATE_FIELD.exact("state");
+
+ public static final IndexedField<ProjectData, Iterable<String>> ANCESTOR_NAME_FIELD =
+ IndexedField.<ProjectData>iterableStringBuilder("AncestorName")
+ .build(ProjectData::getParentNames);
+
+ public static final IndexedField<ProjectData, Iterable<String>>.SearchSpec ANCESTOR_NAME_SPEC =
+ ANCESTOR_NAME_FIELD.exact("ancestor_name");
/**
* All values of all refs that were used in the course of indexing this document. This covers
@@ -62,12 +88,17 @@
*
* <p>Emitted as UTF-8 encoded strings of the form {@code project:ref/name:[hex sha]}.
*/
- public static final FieldDef<ProjectData, Iterable<byte[]>> REF_STATE =
- storedOnly("ref_state")
- .buildRepeatable(
+ public static final IndexedField<ProjectData, Iterable<byte[]>> REF_STATE_FIELD =
+ IndexedField.<ProjectData>iterableByteArrayBuilder("RefState")
+ .stored()
+ .required()
+ .build(
projectData ->
projectData.tree().stream()
.filter(p -> p.getProject().getConfigRefState() != null)
.map(p -> toRefState(p.getProject()))
.collect(toImmutableList()));
+
+ public static final IndexedField<ProjectData, Iterable<byte[]>>.SearchSpec REF_STATE_SPEC =
+ REF_STATE_FIELD.storedOnly("ref_state");
}
diff --git a/java/com/google/gerrit/index/project/ProjectIndex.java b/java/com/google/gerrit/index/project/ProjectIndex.java
index b2ddaff..0aa7393 100644
--- a/java/com/google/gerrit/index/project/ProjectIndex.java
+++ b/java/com/google/gerrit/index/project/ProjectIndex.java
@@ -18,6 +18,7 @@
import com.google.gerrit.index.Index;
import com.google.gerrit.index.IndexDefinition;
import com.google.gerrit.index.query.Predicate;
+import java.util.function.Function;
/**
* Index for Gerrit projects (repositories). This class is mainly used for typing the generic parent
@@ -30,6 +31,8 @@
@Override
default Predicate<ProjectData> keyPredicate(Project.NameKey nameKey) {
- return new ProjectPredicate(ProjectField.NAME, nameKey.get());
+ return new ProjectPredicate(ProjectField.NAME_SPEC, nameKey.get());
}
+
+ Function<ProjectData, Project.NameKey> ENTITY_TO_KEY = (p) -> p.getProject().getNameKey();
}
diff --git a/java/com/google/gerrit/index/project/ProjectPredicate.java b/java/com/google/gerrit/index/project/ProjectPredicate.java
index 11875ef..0eaf2b6 100644
--- a/java/com/google/gerrit/index/project/ProjectPredicate.java
+++ b/java/com/google/gerrit/index/project/ProjectPredicate.java
@@ -14,12 +14,12 @@
package com.google.gerrit.index.project;
-import com.google.gerrit.index.FieldDef;
+import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import com.google.gerrit.index.query.IndexPredicate;
/** Predicate that is mapped to a field in the project index. */
public class ProjectPredicate extends IndexPredicate<ProjectData> {
- public ProjectPredicate(FieldDef<ProjectData, ?> def, String value) {
+ public ProjectPredicate(SchemaField<ProjectData, ?> def, String value) {
super(def, value);
}
}
diff --git a/java/com/google/gerrit/index/project/ProjectSchemaDefinitions.java b/java/com/google/gerrit/index/project/ProjectSchemaDefinitions.java
index 0619566..3ac594e 100644
--- a/java/com/google/gerrit/index/project/ProjectSchemaDefinitions.java
+++ b/java/com/google/gerrit/index/project/ProjectSchemaDefinitions.java
@@ -16,6 +16,8 @@
import static com.google.gerrit.index.SchemaUtil.schema;
+import com.google.common.collect.ImmutableList;
+import com.google.gerrit.index.IndexedField;
import com.google.gerrit.index.Schema;
import com.google.gerrit.index.SchemaDefinitions;
@@ -31,14 +33,27 @@
static final Schema<ProjectData> V1 =
schema(
/* version= */ 1,
- ProjectField.NAME,
- ProjectField.DESCRIPTION,
- ProjectField.PARENT_NAME,
- ProjectField.NAME_PART,
- ProjectField.ANCESTOR_NAME);
+ ImmutableList.of(
+ ProjectField.NAME_FIELD,
+ ProjectField.DESCRIPTION_FIELD,
+ ProjectField.PARENT_NAME_FIELD,
+ ProjectField.NAME_PART_FIELD,
+ ProjectField.ANCESTOR_NAME_FIELD),
+ ImmutableList.<IndexedField<ProjectData, ?>.SearchSpec>of(
+ ProjectField.NAME_SPEC,
+ ProjectField.DESCRIPTION_SPEC,
+ ProjectField.PARENT_NAME_SPEC,
+ ProjectField.NAME_PART_SPEC,
+ ProjectField.ANCESTOR_NAME_SPEC));
@Deprecated
- static final Schema<ProjectData> V2 = schema(V1, ProjectField.STATE, ProjectField.REF_STATE);
+ static final Schema<ProjectData> V2 =
+ schema(
+ V1,
+ ImmutableList.<IndexedField<ProjectData, ?>>of(
+ ProjectField.STATE_FIELD, ProjectField.REF_STATE_FIELD),
+ ImmutableList.<IndexedField<ProjectData, ?>.SearchSpec>of(
+ ProjectField.STATE_SPEC, ProjectField.REF_STATE_SPEC));
// Bump Lucene version requires reindexing
@Deprecated static final Schema<ProjectData> V3 = schema(V2);
diff --git a/java/com/google/gerrit/index/query/AndPredicate.java b/java/com/google/gerrit/index/query/AndPredicate.java
index 23ae312..fda961d 100644
--- a/java/com/google/gerrit/index/query/AndPredicate.java
+++ b/java/com/google/gerrit/index/query/AndPredicate.java
@@ -134,7 +134,7 @@
cmp = a.estimateCost() - b.estimateCost();
}
- if (cmp == 0 && a instanceof DataSource && b instanceof DataSource) {
+ if (cmp == 0 && a instanceof DataSource) {
DataSource<?> as = (DataSource<?>) a;
DataSource<?> bs = (DataSource<?>) b;
cmp = as.getCardinality() - bs.getCardinality();
diff --git a/java/com/google/gerrit/index/query/AndSource.java b/java/com/google/gerrit/index/query/AndSource.java
index f4c1464..3adf881 100644
--- a/java/com/google/gerrit/index/query/AndSource.java
+++ b/java/com/google/gerrit/index/query/AndSource.java
@@ -92,7 +92,7 @@
@SuppressWarnings("unchecked")
private PaginatingSource<T> toPaginatingSource(Predicate<T> pred) {
- return new PaginatingSource<T>((DataSource<T>) pred, start, indexConfig) {
+ return new PaginatingSource<>((DataSource<T>) pred, start, indexConfig) {
@Override
protected boolean match(T object) {
return AndSource.this.match(object);
diff --git a/java/com/google/gerrit/index/query/FieldBundle.java b/java/com/google/gerrit/index/query/FieldBundle.java
index 60881df..551de92 100644
--- a/java/com/google/gerrit/index/query/FieldBundle.java
+++ b/java/com/google/gerrit/index/query/FieldBundle.java
@@ -16,9 +16,12 @@
import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
+import com.google.gerrit.index.IndexedField;
+import com.google.gerrit.index.IndexedField.SearchSpec;
import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
/** FieldBundle is an abstraction that allows retrieval of raw values from different sources. */
@@ -27,8 +30,22 @@
// Map String => List{Integer, Long, Timestamp, String, byte[]}
private ImmutableListMultimap<String, Object> fields;
- public FieldBundle(ListMultimap<String, Object> fields) {
+ /**
+ * Depending on the index implementation 1) either {@link IndexedField} are stored once and
+ * referenced by {@link com.google.gerrit.index.IndexedField.SearchSpec} on the queries, 2) or
+ * each {@link com.google.gerrit.index.IndexedField.SearchSpec} is stored individually.
+ *
+ * <p>In case #1 {@link #storesIndexedFields} is set to {@code true} and the {@link #fields}
+ * contain a map from {@link IndexedField#name()} to a stored value.
+ *
+ * <p>In case #2 {@link #storesIndexedFields} is set to {@code false} and the {@link #fields}
+ * contain a map from {@link SearchSpec#name()} to a stored value.
+ */
+ private final boolean storesIndexedFields;
+
+ public FieldBundle(ListMultimap<String, Object> fields, boolean storesIndexedFields) {
this.fields = ImmutableListMultimap.copyOf(fields);
+ this.storesIndexedFields = storesIndexedFields;
}
/**
@@ -46,13 +63,17 @@
@SuppressWarnings("unchecked")
public <T> T getValue(SchemaField<?, T> schemaField) {
checkArgument(schemaField.isStored(), "Field must be stored");
+ String storedFieldName =
+ storesIndexedFields && schemaField instanceof IndexedField<?, ?>.SearchSpec
+ ? ((IndexedField<?, ?>.SearchSpec) schemaField).getField().name()
+ : schemaField.getName();
checkArgument(
- fields.containsKey(schemaField.getName()) || schemaField.isRepeatable(),
+ fields.containsKey(storedFieldName) || schemaField.isRepeatable(),
"Field %s is not in result set %s",
- schemaField.getName(),
+ storedFieldName,
fields.keySet());
- Iterable<Object> result = fields.get(schemaField.getName());
+ ImmutableList<Object> result = fields.get(storedFieldName);
if (schemaField.isRepeatable()) {
return (T) result;
}
diff --git a/java/com/google/gerrit/index/query/IndexPredicate.java b/java/com/google/gerrit/index/query/IndexPredicate.java
index de81c47..0bde640 100644
--- a/java/com/google/gerrit/index/query/IndexPredicate.java
+++ b/java/com/google/gerrit/index/query/IndexPredicate.java
@@ -23,6 +23,7 @@
import com.google.common.primitives.Longs;
import com.google.gerrit.index.FieldType;
import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
+import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.stream.StreamSupport;
@@ -117,7 +118,8 @@
}
private static ImmutableSet<String> tokenizeString(String value) {
- return StreamSupport.stream(FULL_TEXT_SPLITTER.split(value.toLowerCase()).spliterator(), false)
+ return StreamSupport.stream(
+ FULL_TEXT_SPLITTER.split(value.toLowerCase(Locale.US)).spliterator(), false)
.filter(s -> !s.trim().isEmpty())
.collect(toImmutableSet());
}
diff --git a/java/com/google/gerrit/index/query/IntegerRangePredicate.java b/java/com/google/gerrit/index/query/IntegerRangePredicate.java
index 850c4a5..278d2af 100644
--- a/java/com/google/gerrit/index/query/IntegerRangePredicate.java
+++ b/java/com/google/gerrit/index/query/IntegerRangePredicate.java
@@ -14,13 +14,13 @@
package com.google.gerrit.index.query;
-import com.google.gerrit.index.FieldDef;
+import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import com.google.gerrit.index.query.RangeUtil.Range;
public abstract class IntegerRangePredicate<T> extends IndexPredicate<T> {
private final Range range;
- protected IntegerRangePredicate(FieldDef<T, Integer> type, String value)
+ protected IntegerRangePredicate(SchemaField<T, Integer> type, String value)
throws QueryParseException {
super(type, value);
range = RangeUtil.getRange(value, Integer.MIN_VALUE, Integer.MAX_VALUE);
diff --git a/java/com/google/gerrit/index/query/InternalQuery.java b/java/com/google/gerrit/index/query/InternalQuery.java
index 5c003bc..b6418a9 100644
--- a/java/com/google/gerrit/index/query/InternalQuery.java
+++ b/java/com/google/gerrit/index/query/InternalQuery.java
@@ -20,12 +20,13 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.exceptions.StorageException;
-import com.google.gerrit.index.FieldDef;
import com.google.gerrit.index.Index;
import com.google.gerrit.index.IndexCollection;
import com.google.gerrit.index.IndexConfig;
import com.google.gerrit.index.Schema;
+import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
@@ -76,10 +77,10 @@
}
@SafeVarargs
- public final Q setRequestedFields(FieldDef<T, ?>... fields) {
+ public final Q setRequestedFields(SchemaField<T, ?>... fields) {
checkArgument(fields.length > 0, "requested field list is empty");
queryProcessor.setRequestedFields(
- Arrays.stream(fields).map(FieldDef::getName).collect(toSet()));
+ Arrays.stream(fields).map(SchemaField::getName).collect(toSet()));
return self();
}
@@ -118,6 +119,7 @@
}
}
+ @Nullable
protected final Schema<T> schema() {
Index<?, T> index = indexes != null ? indexes.getSearchIndex() : null;
return index != null ? index.getSchema() : null;
diff --git a/java/com/google/gerrit/index/query/LimitPredicate.java b/java/com/google/gerrit/index/query/LimitPredicate.java
index 23e0f6d..9196811 100644
--- a/java/com/google/gerrit/index/query/LimitPredicate.java
+++ b/java/com/google/gerrit/index/query/LimitPredicate.java
@@ -14,8 +14,11 @@
package com.google.gerrit.index.query;
+import com.google.gerrit.common.Nullable;
+
public class LimitPredicate<T> extends IntPredicate<T> implements Matchable<T> {
@SuppressWarnings("unchecked")
+ @Nullable
public static Integer getLimit(String fieldName, Predicate<?> p) {
IntPredicate<?> ip = QueryBuilder.find(p, IntPredicate.class, fieldName);
return ip != null ? ip.intValue() : null;
diff --git a/java/com/google/gerrit/index/query/PaginatingSource.java b/java/com/google/gerrit/index/query/PaginatingSource.java
index 03d749a..98a0ed3 100644
--- a/java/com/google/gerrit/index/query/PaginatingSource.java
+++ b/java/com/google/gerrit/index/query/PaginatingSource.java
@@ -113,7 +113,7 @@
@Override
public ResultSet<FieldBundle> readRaw() {
- // TOOD(hiesel): Implement
+ // TODO(hiesel): Implement
throw new UnsupportedOperationException("not implemented");
}
@@ -122,6 +122,12 @@
.transformAndConcat(this::transformBuffer);
}
+ /**
+ * Checks whether the given object matches.
+ *
+ * @param object the object to be matched
+ * @return whether the given object matches
+ */
protected boolean match(T object) {
return true;
}
diff --git a/java/com/google/gerrit/index/query/QueryProcessor.java b/java/com/google/gerrit/index/query/QueryProcessor.java
index c27b7c4..1f8266a 100644
--- a/java/com/google/gerrit/index/query/QueryProcessor.java
+++ b/java/com/google/gerrit/index/query/QueryProcessor.java
@@ -273,7 +273,9 @@
Ints.saturatedCast((long) limit + 1),
getRequestedFields());
logger.atFine().log("Query options: %s", opts);
- Predicate<T> pred = rewriter.rewrite(q, opts);
+ // Apply index-specific rewrite first
+ Predicate<T> pred = indexes.getSearchIndex().getIndexRewriter().rewrite(q, opts);
+ pred = rewriter.rewrite(pred, opts);
if (enforceVisibility) {
pred = enforceVisibility(pred);
}
@@ -287,7 +289,7 @@
@SuppressWarnings("unchecked")
DataSource<T> s = (DataSource<T>) pred;
if (initialPageSize < limit && !(pred instanceof AndSource)) {
- s = new PaginatingSource<T>(s, start, indexConfig);
+ s = new PaginatingSource<>(s, start, indexConfig);
}
sources.add(s);
}
diff --git a/java/com/google/gerrit/index/query/RegexPredicate.java b/java/com/google/gerrit/index/query/RegexPredicate.java
index 60a2a9e..4c76770 100644
--- a/java/com/google/gerrit/index/query/RegexPredicate.java
+++ b/java/com/google/gerrit/index/query/RegexPredicate.java
@@ -14,14 +14,14 @@
package com.google.gerrit.index.query;
-import com.google.gerrit.index.FieldDef;
+import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
public abstract class RegexPredicate<I> extends IndexPredicate<I> {
- protected RegexPredicate(FieldDef<I, ?> def, String value) {
+ protected RegexPredicate(SchemaField<I, ?> def, String value) {
super(def, value);
}
- protected RegexPredicate(FieldDef<I, ?> def, String name, String value) {
+ protected RegexPredicate(SchemaField<I, ?> def, String name, String value) {
super(def, name, value);
}
}
diff --git a/java/com/google/gerrit/index/query/TimestampRangePredicate.java b/java/com/google/gerrit/index/query/TimestampRangePredicate.java
index 29d6f22..1fd81a6 100644
--- a/java/com/google/gerrit/index/query/TimestampRangePredicate.java
+++ b/java/com/google/gerrit/index/query/TimestampRangePredicate.java
@@ -14,7 +14,7 @@
package com.google.gerrit.index.query;
-import com.google.gerrit.index.FieldDef;
+import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import com.google.gerrit.json.JavaSqlTimestampHelper;
import java.sql.Timestamp;
import java.time.Instant;
@@ -30,7 +30,7 @@
}
}
- protected TimestampRangePredicate(FieldDef<I, Timestamp> def, String name, String value) {
+ protected TimestampRangePredicate(SchemaField<I, Timestamp> def, String name, String value) {
super(def, name, value);
}
diff --git a/java/com/google/gerrit/index/testing/AbstractFakeIndex.java b/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
index c790fe4..e4c6745 100644
--- a/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
+++ b/java/com/google/gerrit/index/testing/AbstractFakeIndex.java
@@ -29,6 +29,7 @@
import com.google.gerrit.index.Index;
import com.google.gerrit.index.QueryOptions;
import com.google.gerrit.index.Schema;
+import com.google.gerrit.index.SchemaFieldDefs;
import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import com.google.gerrit.index.project.ProjectData;
import com.google.gerrit.index.project.ProjectIndex;
@@ -166,6 +167,7 @@
@Override
public ResultSet<V> read() {
return new ListResultSet<>(results) {
+ @Nullable
@Override
public Object searchAfter() {
@Nullable V last = Iterables.getLast(results, null);
@@ -190,7 +192,7 @@
fields.put(field.getName(), field.get(result));
}
}
- fieldBundles.add(new FieldBundle(fields.build()));
+ fieldBundles.add(new FieldBundle(fields.build(), /* storesIndexedFields= */ false));
searchAfter = keyFor(result);
}
ImmutableList<FieldBundle> resultSet = fieldBundles.build();
@@ -228,7 +230,7 @@
* <p>This index is special in that ChangeData is a mutable object. Therefore we can't just hold
* onto the object that the caller wanted us to index. We also can't just create a new ChangeData
* from scratch because there are tests that assert that certain computations (e.g. diffs) are
- * only done once. So we do what the prod indices do: We read and write fields using FieldDef.
+ * only done once. So we do what the prod indices do: We read and write fields using SchemaField.
*/
public static class FakeChangeIndex
extends AbstractFakeIndex<Change.Id, ChangeData, Map<String, Object>> implements ChangeIndex {
@@ -266,7 +268,7 @@
protected Map<String, Object> docFor(ChangeData value) {
ImmutableMap.Builder<String, Object> doc = ImmutableMap.builder();
for (SchemaField<ChangeData, ?> field : getSchema().getSchemaFields().values()) {
- if (ChangeField.MERGEABLE.getName().equals(field.getName()) && skipMergable) {
+ if (ChangeField.MERGEABLE_SPEC.getName().equals(field.getName()) && skipMergable) {
continue;
}
Object docifiedValue = field.get(value);
@@ -281,16 +283,23 @@
protected ChangeData valueFor(Map<String, Object> doc) {
ChangeData cd =
changeDataFactory.create(
- Project.nameKey((String) doc.get(ChangeField.PROJECT.getName())),
- Change.id(Integer.valueOf((String) doc.get(ChangeField.LEGACY_ID_STR.getName()))));
+ Project.nameKey((String) doc.get(ChangeField.PROJECT_SPEC.getName())),
+ Change.id(
+ Integer.valueOf((String) doc.get(ChangeField.NUMERIC_ID_STR_SPEC.getName()))));
for (SchemaField<ChangeData, ?> field : getSchema().getSchemaFields().values()) {
- field.setIfPossible(cd, new FakeStoredValue(doc.get(field.getName())));
+ boolean isProtoField = SchemaFieldDefs.isProtoField(field);
+ field.setIfPossible(cd, new FakeStoredValue(doc.get(field.getName()), isProtoField));
}
return cd;
}
@Override
public void insert(ChangeData obj) {}
+
+ @Override
+ public void deleteByValue(ChangeData value) {
+ delete(ChangeIndex.ENTITY_TO_KEY.apply(value));
+ }
}
/** Fake implementation of {@link AccountIndex} where all filtering happens in-memory. */
@@ -323,6 +332,11 @@
@Override
public void insert(AccountState obj) {}
+
+ @Override
+ public void deleteByValue(AccountState value) {
+ delete(AccountIndex.ENTITY_TO_KEY.apply(value));
+ }
}
/** Fake implementation of {@link GroupIndex} where all filtering happens in-memory. */
@@ -356,6 +370,11 @@
@Override
public void insert(InternalGroup obj) {}
+
+ @Override
+ public void deleteByValue(InternalGroup value) {
+ delete(GroupIndex.ENTITY_TO_KEY.apply(value));
+ }
}
/** Fake implementation of {@link ProjectIndex} where all filtering happens in-memory. */
@@ -388,5 +407,10 @@
@Override
public void insert(ProjectData obj) {}
+
+ @Override
+ public void deleteByValue(ProjectData value) {
+ delete(ProjectIndex.ENTITY_TO_KEY.apply(value));
+ }
}
}
diff --git a/java/com/google/gerrit/index/testing/BUILD b/java/com/google/gerrit/index/testing/BUILD
index 9af2598..44bf70d 100644
--- a/java/com/google/gerrit/index/testing/BUILD
+++ b/java/com/google/gerrit/index/testing/BUILD
@@ -10,13 +10,9 @@
deps = [
"//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/entities",
- "//java/com/google/gerrit/exceptions",
"//java/com/google/gerrit/index",
- "//java/com/google/gerrit/index:query_exception",
"//java/com/google/gerrit/index/project",
- "//java/com/google/gerrit/proto",
"//java/com/google/gerrit/server",
- "//java/com/google/gerrit/server/logging",
"//lib:guava",
"//lib:jgit",
"//lib:protobuf",
diff --git a/java/com/google/gerrit/index/testing/TestIndexedFields.java b/java/com/google/gerrit/index/testing/TestIndexedFields.java
index f80b8a1..51440fb 100644
--- a/java/com/google/gerrit/index/testing/TestIndexedFields.java
+++ b/java/com/google/gerrit/index/testing/TestIndexedFields.java
@@ -164,6 +164,12 @@
public static final IndexedField<TestIndexedData, String>.SearchSpec STRING_FIELD_SPEC =
STRING_FIELD.fullText("string_test");
+ public static final IndexedField<TestIndexedData, String>.SearchSpec PREFIX_STRING_FIELD_SPEC =
+ STRING_FIELD.prefix("prefix_string_test");
+
+ public static final IndexedField<TestIndexedData, String>.SearchSpec EXACT_STRING_FIELD_SPEC =
+ STRING_FIELD.exact("exact_string_test");
+
public static final IndexedField<TestIndexedData, Iterable<byte[]>> ITERABLE_STORED_BYTE_FIELD =
IndexedField.<TestIndexedData>iterableByteArrayBuilder("IterableByteTestField")
.stored()
@@ -182,7 +188,10 @@
public static final IndexedField<TestIndexedData, Entities.Change> STORED_PROTO_FIELD =
IndexedField.<TestIndexedData, Entities.Change>builder(
- "TestChange", new TypeToken<Entities.Change>() {})
+ "TestChange",
+ new TypeToken<Entities.Change>() {
+ private static final long serialVersionUID = 1L;
+ })
.stored()
.build(getter(), setter(), ChangeProtoConverter.INSTANCE);
@@ -192,7 +201,10 @@
public static final IndexedField<TestIndexedData, Iterable<Entities.Change>>
ITERABLE_STORED_PROTO_FIELD =
IndexedField.<TestIndexedData, Iterable<Entities.Change>>builder(
- "IterableTestChange", new TypeToken<Iterable<Entities.Change>>() {})
+ "IterableTestChange",
+ new TypeToken<Iterable<Entities.Change>>() {
+ private static final long serialVersionUID = 1L;
+ })
.stored()
.build(getter(), setter(), ChangeProtoConverter.INSTANCE);
diff --git a/java/com/google/gerrit/json/EnumTypeAdapterFactory.java b/java/com/google/gerrit/json/EnumTypeAdapterFactory.java
index 9c32aa8..b6cb5f9 100644
--- a/java/com/google/gerrit/json/EnumTypeAdapterFactory.java
+++ b/java/com/google/gerrit/json/EnumTypeAdapterFactory.java
@@ -14,6 +14,7 @@
package com.google.gerrit.json;
+import com.google.gerrit.common.Nullable;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
@@ -34,6 +35,7 @@
public class EnumTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings({"rawtypes", "unchecked"})
+ @Nullable
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
TypeAdapter<T> defaultEnumAdapter = TypeAdapters.ENUM_FACTORY.create(gson, typeToken);
diff --git a/java/com/google/gerrit/json/OptionalSubmitRequirementExpressionResultAdapterFactory.java b/java/com/google/gerrit/json/OptionalSubmitRequirementExpressionResultAdapterFactory.java
index d35b8fb..2557515 100644
--- a/java/com/google/gerrit/json/OptionalSubmitRequirementExpressionResultAdapterFactory.java
+++ b/java/com/google/gerrit/json/OptionalSubmitRequirementExpressionResultAdapterFactory.java
@@ -45,6 +45,7 @@
TypeToken.get(SubmitRequirementExpressionResult.class);
@SuppressWarnings({"unchecked"})
+ @Nullable
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
if (typeToken.equals(OPTIONAL_SR_EXPRESSION_RESULT_TOKEN)) {
diff --git a/java/com/google/gerrit/json/SqlTimestampDeserializer.java b/java/com/google/gerrit/json/SqlTimestampDeserializer.java
index e1cf382..9aeda2b 100644
--- a/java/com/google/gerrit/json/SqlTimestampDeserializer.java
+++ b/java/com/google/gerrit/json/SqlTimestampDeserializer.java
@@ -14,6 +14,7 @@
package com.google.gerrit.json;
+import com.google.gerrit.common.Nullable;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@@ -30,6 +31,7 @@
class SqlTimestampDeserializer implements JsonDeserializer<Timestamp>, JsonSerializer<Timestamp> {
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
+ @Nullable
@Override
public Timestamp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
diff --git a/java/com/google/gerrit/launcher/GerritLauncher.java b/java/com/google/gerrit/launcher/GerritLauncher.java
index 550597b..07a071a 100644
--- a/java/com/google/gerrit/launcher/GerritLauncher.java
+++ b/java/com/google/gerrit/launcher/GerritLauncher.java
@@ -44,6 +44,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Properties;
@@ -222,7 +223,7 @@
String cn = programClassName(name);
clazz = Class.forName(PKG + "." + cn, true, loader);
} catch (ClassNotFoundException cnfe) {
- if (name.equals(name.toLowerCase())) {
+ if (name.equals(name.toLowerCase(Locale.US))) {
clazz = Class.forName(PKG + "." + name, true, loader);
} else {
throw cnfe;
@@ -266,7 +267,7 @@
}
private static String programClassName(String cn) {
- if (cn.equals(cn.toLowerCase())) {
+ if (cn.equals(cn.toLowerCase(Locale.US))) {
StringBuilder buf = new StringBuilder();
buf.append(Character.toUpperCase(cn.charAt(0)));
for (int i = 1; i < cn.length(); i++) {
@@ -560,6 +561,7 @@
return myHome;
}
+ @SuppressWarnings("ReturnMissingNullable")
private static File tmproot() {
File tmp;
String gerritTemp = System.getenv("GERRIT_TMP");
@@ -599,6 +601,7 @@
}
}
+ @SuppressWarnings("ReturnMissingNullable")
private static File locateHomeDirectory() {
// Try to find the user's home directory. If we can't find it
// return null so the JVM's default temporary directory is used
diff --git a/java/com/google/gerrit/lucene/AbstractLuceneIndex.java b/java/com/google/gerrit/lucene/AbstractLuceneIndex.java
index 229674b..2fd1c45 100644
--- a/java/com/google/gerrit/lucene/AbstractLuceneIndex.java
+++ b/java/com/google/gerrit/lucene/AbstractLuceneIndex.java
@@ -40,16 +40,19 @@
import com.google.gerrit.index.QueryOptions;
import com.google.gerrit.index.Schema;
import com.google.gerrit.index.Schema.Values;
+import com.google.gerrit.index.SchemaFieldDefs;
import com.google.gerrit.index.SchemaFieldDefs.SchemaField;
import com.google.gerrit.index.query.DataSource;
import com.google.gerrit.index.query.FieldBundle;
import com.google.gerrit.index.query.ListResultSet;
import com.google.gerrit.index.query.ResultSet;
+import com.google.gerrit.proto.Protos;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.index.IndexUtils;
import com.google.gerrit.server.index.options.AutoFlush;
import com.google.gerrit.server.logging.LoggingContextAwareExecutorService;
import com.google.gerrit.server.logging.LoggingContextAwareScheduledExecutorService;
+import com.google.protobuf.MessageLite;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Set;
@@ -106,6 +109,7 @@
private final Set<NrtFuture> notDoneNrtFutures;
private final AutoFlush autoFlush;
private ScheduledExecutorService autoCommitExecutor;
+ private final Function<V, K> valueToKeyFunction;
@SuppressWarnings("ThreadPriorityCheck")
AbstractLuceneIndex(
@@ -117,7 +121,8 @@
String subIndex,
GerritIndexWriterConfig writerConfig,
SearcherFactory searcherFactory,
- AutoFlush autoFlush)
+ AutoFlush autoFlush,
+ Function<V, K> valueToKeyFunction)
throws IOException {
this.schema = schema;
this.sitePaths = sitePaths;
@@ -125,6 +130,7 @@
this.name = name;
this.skipFields = skipFields;
this.autoFlush = autoFlush;
+ this.valueToKeyFunction = valueToKeyFunction;
String index = Joiner.on('_').skipNulls().join(name, subIndex);
long commitPeriod = writerConfig.getCommitWithinMs();
@@ -298,6 +304,11 @@
}
@Override
+ public void deleteByValue(V value) {
+ delete(valueToKeyFunction.apply(value));
+ }
+
+ @Override
public void deleteAll() {
try {
writer.deleteAll();
@@ -368,8 +379,12 @@
doc.add(new TextField(name, (String) value, store));
}
} else if (type == FieldType.STORED_ONLY) {
+ boolean isProtoField = SchemaFieldDefs.isProtoField(values.getField());
for (Object value : values.getValues()) {
- doc.add(new StoredField(name, (byte[]) value));
+ // Lucene stores protos as bytes
+ doc.add(
+ new StoredField(
+ name, isProtoField ? Protos.toByteArray((MessageLite) value) : (byte[]) value));
}
} else {
throw FieldType.badFieldType(type);
@@ -402,7 +417,7 @@
throw FieldType.badFieldType(type);
}
}
- return new FieldBundle(rawFields);
+ return new FieldBundle(rawFields, /* storesIndexedFields= */ false);
}
private static Field.Store store(SchemaField<?, ?> f) {
@@ -550,7 +565,7 @@
}
}
ScoreDoc searchAfter = scoreDoc;
- return new ListResultSet<T>(b.build()) {
+ return new ListResultSet<>(b.build()) {
@Override
public Object searchAfter() {
return searchAfter;
diff --git a/java/com/google/gerrit/lucene/ChangeSubIndex.java b/java/com/google/gerrit/lucene/ChangeSubIndex.java
index ce50473..024b102 100644
--- a/java/com/google/gerrit/lucene/ChangeSubIndex.java
+++ b/java/com/google/gerrit/lucene/ChangeSubIndex.java
@@ -85,7 +85,8 @@
subIndex,
writerConfig,
searcherFactory,
- autoFlush);
+ autoFlush,
+ ChangeIndex.ENTITY_TO_KEY);
}
@Override
@@ -119,13 +120,13 @@
void add(Document doc, Values<ChangeData> values) {
// Add separate DocValues fields for those fields needed for sorting.
SchemaField<ChangeData, ?> f = values.getField();
- if (f == ChangeField.LEGACY_ID_STR) {
+ if (f == ChangeField.NUMERIC_ID_STR_SPEC) {
String v = (String) getOnlyElement(values.getValues());
doc.add(new NumericDocValuesField(ID_STR_SORT_FIELD, Integer.valueOf(v)));
- } else if (f == ChangeField.UPDATED) {
+ } else if (f == ChangeField.UPDATED_SPEC) {
long t = ((Timestamp) getOnlyElement(values.getValues())).getTime();
doc.add(new NumericDocValuesField(UPDATED_SORT_FIELD, t));
- } else if (f == ChangeField.MERGED_ON) {
+ } else if (f == ChangeField.MERGED_ON_SPEC) {
long t = ((Timestamp) getOnlyElement(values.getValues())).getTime();
doc.add(new NumericDocValuesField(MERGED_ON_SORT_FIELD, t));
}
diff --git a/java/com/google/gerrit/lucene/LuceneAccountIndex.java b/java/com/google/gerrit/lucene/LuceneAccountIndex.java
index 2e1771f..9c0baa8 100644
--- a/java/com/google/gerrit/lucene/LuceneAccountIndex.java
+++ b/java/com/google/gerrit/lucene/LuceneAccountIndex.java
@@ -108,7 +108,8 @@
null,
new GerritIndexWriterConfig(cfg, ACCOUNTS),
new SearcherFactory(),
- autoFlush);
+ autoFlush,
+ AccountIndex.ENTITY_TO_KEY);
this.accountCache = accountCache;
indexWriterConfig = new GerritIndexWriterConfig(cfg, ACCOUNTS);
diff --git a/java/com/google/gerrit/lucene/LuceneChangeIndex.java b/java/com/google/gerrit/lucene/LuceneChangeIndex.java
index eaae40f..4c05f70 100644
--- a/java/com/google/gerrit/lucene/LuceneChangeIndex.java
+++ b/java/com/google/gerrit/lucene/LuceneChangeIndex.java
@@ -17,8 +17,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.gerrit.lucene.AbstractLuceneIndex.sortFieldName;
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
-import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID_STR;
-import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
+import static com.google.gerrit.server.index.change.ChangeField.NUMERIC_ID_STR_SPEC;
+import static com.google.gerrit.server.index.change.ChangeField.PROJECT_SPEC;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
import static java.util.Objects.requireNonNull;
@@ -33,6 +33,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.converter.ChangeProtoConverter;
@@ -102,21 +103,21 @@
public class LuceneChangeIndex implements ChangeIndex {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- static final String UPDATED_SORT_FIELD = sortFieldName(ChangeField.UPDATED);
- static final String MERGED_ON_SORT_FIELD = sortFieldName(ChangeField.MERGED_ON);
- static final String ID_STR_SORT_FIELD = sortFieldName(ChangeField.LEGACY_ID_STR);
+ static final String UPDATED_SORT_FIELD = sortFieldName(ChangeField.UPDATED_SPEC);
+ static final String MERGED_ON_SORT_FIELD = sortFieldName(ChangeField.MERGED_ON_SPEC);
+ static final String ID_STR_SORT_FIELD = sortFieldName(ChangeField.NUMERIC_ID_STR_SPEC);
private static final String CHANGES = "changes";
private static final String CHANGES_OPEN = "open";
private static final String CHANGES_CLOSED = "closed";
- private static final String CHANGE_FIELD = ChangeField.CHANGE.getName();
+ private static final String CHANGE_FIELD = ChangeField.CHANGE_SPEC.getName();
static Term idTerm(ChangeData cd) {
return idTerm(cd.getVirtualId());
}
static Term idTerm(Change.Id id) {
- return QueryBuilder.stringTerm(LEGACY_ID_STR.getName(), Integer.toString(id.get()));
+ return QueryBuilder.stringTerm(NUMERIC_ID_STR_SPEC.getName(), Integer.toString(id.get()));
}
private final ListeningExecutorService executor;
@@ -142,7 +143,7 @@
this.skipFields =
MergeabilityComputationBehavior.fromConfig(cfg).includeInIndex()
? ImmutableSet.of()
- : ImmutableSet.of(ChangeField.MERGEABLE.getName());
+ : ImmutableSet.of(ChangeField.MERGEABLE_SPEC.getName());
GerritIndexWriterConfig openConfig = new GerritIndexWriterConfig(cfg, "changes_open");
GerritIndexWriterConfig closedConfig = new GerritIndexWriterConfig(cfg, "changes_closed");
@@ -242,6 +243,11 @@
}
@Override
+ public void deleteByValue(ChangeData value) {
+ delete(ChangeIndex.ENTITY_TO_KEY.apply(value));
+ }
+
+ @Override
public void delete(Change.Id changeId) {
Term idTerm = LuceneChangeIndex.idTerm(changeId);
try {
@@ -454,11 +460,13 @@
* @param subIndex change sub-index
* @return the score doc that can be used to page result sets
*/
+ @Nullable
private ScoreDoc getSearchAfter(ChangeSubIndex subIndex) {
if (isSearchAfterPagination
&& opts.searchAfter() != null
- && opts.searchAfter() instanceof Map) {
- return ((Map<ChangeSubIndex, ScoreDoc>) opts.searchAfter()).get(subIndex);
+ && opts.searchAfter() instanceof Map
+ && ((Map<?, ?>) opts.searchAfter()).get(subIndex) instanceof ScoreDoc) {
+ return (ScoreDoc) ((Map<?, ?>) opts.searchAfter()).get(subIndex);
}
return null;
}
@@ -498,7 +506,7 @@
ImmutableList.Builder<ChangeData> result =
ImmutableList.builderWithExpectedSize(docs.size());
for (Document doc : docs) {
- result.add(toChangeData(fields(doc, fields), fields, LEGACY_ID_STR.getName()));
+ result.add(toChangeData(fields(doc, fields), fields, NUMERIC_ID_STR_SPEC.getName()));
}
return result.build();
} catch (InterruptedException e) {
@@ -547,7 +555,7 @@
Change.Id id = Change.id(Integer.valueOf(f.stringValue()));
// IndexUtils#changeFields ensures either CHANGE or PROJECT is always present.
- IndexableField project = doc.get(PROJECT.getName()).iterator().next();
+ IndexableField project = doc.get(PROJECT_SPEC.getName()).iterator().next();
cd = changeDataFactory.create(Project.nameKey(project.stringValue()), id);
}
diff --git a/java/com/google/gerrit/lucene/LuceneGroupIndex.java b/java/com/google/gerrit/lucene/LuceneGroupIndex.java
index d475ab7..6301421 100644
--- a/java/com/google/gerrit/lucene/LuceneGroupIndex.java
+++ b/java/com/google/gerrit/lucene/LuceneGroupIndex.java
@@ -18,6 +18,7 @@
import static com.google.gerrit.server.index.group.GroupField.UUID_FIELD_SPEC;
import com.google.common.collect.ImmutableSet;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.entities.InternalGroup;
import com.google.gerrit.exceptions.StorageException;
@@ -97,7 +98,8 @@
null,
new GerritIndexWriterConfig(cfg, GROUPS),
new SearcherFactory(),
- autoFlush);
+ autoFlush,
+ GroupIndex.ENTITY_TO_KEY);
this.groupCache = groupCache;
indexWriterConfig = new GerritIndexWriterConfig(cfg, GROUPS);
@@ -151,6 +153,7 @@
new Sort(new SortField(UUID_SORT_FIELD, SortField.Type.STRING, false)));
}
+ @Nullable
@Override
protected InternalGroup fromDocument(Document doc) {
AccountGroup.UUID uuid =
diff --git a/java/com/google/gerrit/lucene/LuceneProjectIndex.java b/java/com/google/gerrit/lucene/LuceneProjectIndex.java
index 96b22db..911d91f 100644
--- a/java/com/google/gerrit/lucene/LuceneProjectIndex.java
+++ b/java/com/google/gerrit/lucene/LuceneProjectIndex.java
@@ -15,9 +15,10 @@
package com.google.gerrit.lucene;
import static com.google.common.collect.Iterables.getOnlyElement;
-import static com.google.gerrit.index.project.ProjectField.NAME;
+import static com.google.gerrit.index.project.ProjectField.NAME_SPEC;
import com.google.common.collect.ImmutableSet;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.index.QueryOptions;
@@ -57,14 +58,14 @@
implements ProjectIndex {
private static final String PROJECTS = "projects";
- private static final String NAME_SORT_FIELD = sortFieldName(NAME);
+ private static final String NAME_SORT_FIELD = sortFieldName(NAME_SPEC);
private static Term idTerm(ProjectData projectState) {
return idTerm(projectState.getProject().getNameKey());
}
private static Term idTerm(Project.NameKey nameKey) {
- return QueryBuilder.stringTerm(NAME.getName(), nameKey.get());
+ return QueryBuilder.stringTerm(NAME_SPEC.getName(), nameKey.get());
}
private final GerritIndexWriterConfig indexWriterConfig;
@@ -97,7 +98,8 @@
null,
new GerritIndexWriterConfig(cfg, PROJECTS),
new SearcherFactory(),
- autoFlush);
+ autoFlush,
+ ProjectIndex.ENTITY_TO_KEY);
this.projectCache = projectCache;
indexWriterConfig = new GerritIndexWriterConfig(cfg, PROJECTS);
@@ -108,7 +110,7 @@
void add(Document doc, Values<ProjectData> values) {
// Add separate DocValues field for the field that is needed for sorting.
SchemaField<ProjectData, ?> f = values.getField();
- if (f == NAME) {
+ if (f == NAME_SPEC) {
String value = (String) getOnlyElement(values.getValues());
doc.add(new SortedDocValuesField(NAME_SORT_FIELD, new BytesRef(value)));
}
@@ -151,9 +153,10 @@
new Sort(new SortField(NAME_SORT_FIELD, SortField.Type.STRING, false)));
}
+ @Nullable
@Override
protected ProjectData fromDocument(Document doc) {
- Project.NameKey nameKey = Project.nameKey(doc.getField(NAME.getName()).stringValue());
+ Project.NameKey nameKey = Project.nameKey(doc.getField(NAME_SPEC.getName()).stringValue());
return projectCache.get().get(nameKey).map(ProjectState::toProjectData).orElse(null);
}
}
diff --git a/java/com/google/gerrit/lucene/LuceneStoredValue.java b/java/com/google/gerrit/lucene/LuceneStoredValue.java
index 1f8c039..58ae3e0 100644
--- a/java/com/google/gerrit/lucene/LuceneStoredValue.java
+++ b/java/com/google/gerrit/lucene/LuceneStoredValue.java
@@ -38,6 +38,7 @@
this.field = field;
}
+ @Nullable
@Override
public String asString() {
return Iterables.getFirst(asStrings(), null);
@@ -48,6 +49,7 @@
return field.stream().map(f -> f.stringValue()).collect(toImmutableList());
}
+ @Nullable
@Override
public Integer asInteger() {
return Iterables.getFirst(asIntegers(), null);
@@ -58,6 +60,7 @@
return field.stream().map(f -> f.numericValue().intValue()).collect(toImmutableList());
}
+ @Nullable
@Override
public Long asLong() {
return Iterables.getFirst(asLongs(), null);
@@ -68,11 +71,13 @@
return field.stream().map(f -> f.numericValue().longValue()).collect(toImmutableList());
}
+ @Nullable
@Override
public Timestamp asTimestamp() {
return asLong() == null ? null : new Timestamp(asLong());
}
+ @Nullable
@Override
public byte[] asByteArray() {
return Iterables.getFirst(asByteArrays(), null);
diff --git a/java/com/google/gerrit/lucene/WrappableSearcherManager.java b/java/com/google/gerrit/lucene/WrappableSearcherManager.java
index c164b29..56cb220 100644
--- a/java/com/google/gerrit/lucene/WrappableSearcherManager.java
+++ b/java/com/google/gerrit/lucene/WrappableSearcherManager.java
@@ -17,6 +17,7 @@
* limitations under the License.
*/
+import com.google.gerrit.common.Nullable;
import java.io.IOException;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FilterDirectoryReader;
@@ -132,6 +133,7 @@
reference.getIndexReader().decRef();
}
+ @Nullable
@Override
protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws IOException {
final IndexReader r = referenceToRefresh.getIndexReader();
diff --git a/java/com/google/gerrit/mail/MailHeader.java b/java/com/google/gerrit/mail/MailHeader.java
index 2700f81..6933140 100644
--- a/java/com/google/gerrit/mail/MailHeader.java
+++ b/java/com/google/gerrit/mail/MailHeader.java
@@ -17,7 +17,6 @@
/** Variables used by emails to hold data */
public enum MailHeader {
// Gerrit metadata holders
- ASSIGNEE("Gerrit-Assignee"),
ATTENTION("Gerrit-Attention"),
BRANCH("Gerrit-Branch"),
CC("Gerrit-CC"),
diff --git a/java/com/google/gerrit/mail/RawMailParser.java b/java/com/google/gerrit/mail/RawMailParser.java
index 929e9f9..79d1cb8f 100644
--- a/java/com/google/gerrit/mail/RawMailParser.java
+++ b/java/com/google/gerrit/mail/RawMailParser.java
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.Instant;
+import java.util.Locale;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.dom.Entity;
import org.apache.james.mime4j.dom.Message;
@@ -90,7 +91,7 @@
// Add additional headers
mimeMessage.getHeader().getFields().stream()
- .filter(f -> !MAIN_HEADERS.contains(f.getName().toLowerCase()))
+ .filter(f -> !MAIN_HEADERS.contains(f.getName().toLowerCase(Locale.US)))
.forEach(f -> messageBuilder.addAdditionalHeader(f.getName() + ": " + f.getBody()));
// Add text and html body parts
diff --git a/java/com/google/gerrit/metrics/BUILD b/java/com/google/gerrit/metrics/BUILD
index 5f4e0c0..0f80a0c 100644
--- a/java/com/google/gerrit/metrics/BUILD
+++ b/java/com/google/gerrit/metrics/BUILD
@@ -5,6 +5,7 @@
srcs = glob(["**/*.java"]),
visibility = ["//visibility:public"],
deps = [
+ "//java/com/google/gerrit/common:annotations",
"//java/com/google/gerrit/common:server",
"//java/com/google/gerrit/extensions:api",
"//java/com/google/gerrit/lifecycle",
diff --git a/java/com/google/gerrit/metrics/dropwizard/MetricJson.java b/java/com/google/gerrit/metrics/dropwizard/MetricJson.java
index d59a1d9..27e9377 100644
--- a/java/com/google/gerrit/metrics/dropwizard/MetricJson.java
+++ b/java/com/google/gerrit/metrics/dropwizard/MetricJson.java
@@ -23,6 +23,7 @@
import com.codahale.metrics.Timer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.Field;
import java.util.ArrayList;
@@ -144,6 +145,7 @@
}
}
+ @Nullable
private static Boolean toBool(ImmutableMap<String, String> atts, String key) {
return Description.TRUE_VALUE.equals(atts.get(key)) ? true : null;
}
diff --git a/java/com/google/gerrit/metrics/proc/OperatingSystemMXBeanFactory.java b/java/com/google/gerrit/metrics/proc/OperatingSystemMXBeanFactory.java
index ef0ced6..84f2320 100644
--- a/java/com/google/gerrit/metrics/proc/OperatingSystemMXBeanFactory.java
+++ b/java/com/google/gerrit/metrics/proc/OperatingSystemMXBeanFactory.java
@@ -15,6 +15,7 @@
package com.google.gerrit.metrics.proc;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.sun.management.UnixOperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
@@ -25,6 +26,7 @@
private OperatingSystemMXBeanFactory() {}
+ @Nullable
static OperatingSystemMXBeanInterface create() {
OperatingSystemMXBean sys = ManagementFactory.getOperatingSystemMXBean();
if (sys instanceof UnixOperatingSystemMXBean) {
diff --git a/java/com/google/gerrit/pgm/Daemon.java b/java/com/google/gerrit/pgm/Daemon.java
index 74a3dce..72c465d 100644
--- a/java/com/google/gerrit/pgm/Daemon.java
+++ b/java/com/google/gerrit/pgm/Daemon.java
@@ -55,6 +55,7 @@
import com.google.gerrit.pgm.util.LogFileCompressor.LogFileCompressorModule;
import com.google.gerrit.pgm.util.RuntimeShutdown;
import com.google.gerrit.pgm.util.SiteProgram;
+import com.google.gerrit.server.DefaultRefLogIdentityProvider;
import com.google.gerrit.server.LibModuleLoader;
import com.google.gerrit.server.LibModuleType;
import com.google.gerrit.server.ModuleOverloader;
@@ -64,6 +65,7 @@
import com.google.gerrit.server.account.externalids.ExternalIdCaseSensitivityMigrator;
import com.google.gerrit.server.api.GerritApiModule;
import com.google.gerrit.server.api.PluginApiModule;
+import com.google.gerrit.server.api.projects.ProjectQueryBuilderModule;
import com.google.gerrit.server.audit.AuditModule;
import com.google.gerrit.server.cache.h2.H2CacheModule;
import com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule;
@@ -212,6 +214,7 @@
private Path runFile;
private boolean inMemoryTest;
private AbstractModule indexModule;
+ private Module accountPatchReviewStoreModule;
private Module emailModule;
private List<Module> testSysModules = new ArrayList<>();
private List<Module> testSshModules = new ArrayList<>();
@@ -334,6 +337,11 @@
}
@VisibleForTesting
+ public void setAccountPatchReviewStoreModuleForTesting(Module module) {
+ accountPatchReviewStoreModule = module;
+ }
+
+ @VisibleForTesting
public void setEmailModuleForTesting(Module module) {
emailModule = module;
}
@@ -444,12 +452,18 @@
modules.add(new WorkQueueModule());
modules.add(new StreamEventsApiListenerModule());
modules.add(new EventBrokerModule());
- modules.add(new JdbcAccountPatchReviewStoreModule(config));
+ if (accountPatchReviewStoreModule != null) {
+ modules.add(accountPatchReviewStoreModule);
+ } else {
+ modules.add(new JdbcAccountPatchReviewStoreModule(config));
+ }
modules.add(new SysExecutorModule());
modules.add(new DiffExecutorModule());
modules.add(new MimeUtil2Module());
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new GerritApiModule());
+ modules.add(new ProjectQueryBuilderModule());
+ modules.add(new DefaultRefLogIdentityProvider.Module());
modules.add(new PluginApiModule());
modules.add(
diff --git a/java/com/google/gerrit/pgm/Reindex.java b/java/com/google/gerrit/pgm/Reindex.java
index ecfca0d..b4344d7 100644
--- a/java/com/google/gerrit/pgm/Reindex.java
+++ b/java/com/google/gerrit/pgm/Reindex.java
@@ -36,6 +36,7 @@
import com.google.gerrit.server.cache.CacheInfo;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.git.WorkQueue.WorkQueueModule;
import com.google.gerrit.server.index.IndexModule;
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
import com.google.gerrit.server.index.options.AutoFlush;
@@ -175,6 +176,8 @@
}
boolean replica = ReplicaUtil.isReplica(globalConfig);
List<Module> modules = new ArrayList<>();
+ modules.add(new WorkQueueModule());
+
Module indexModule;
IndexType indexType = IndexModule.getIndexType(dbInjector);
if (indexType.isLucene()) {
diff --git a/java/com/google/gerrit/pgm/SwitchSecureStore.java b/java/com/google/gerrit/pgm/SwitchSecureStore.java
index 824a9a7..6dec2d8 100644
--- a/java/com/google/gerrit/pgm/SwitchSecureStore.java
+++ b/java/com/google/gerrit/pgm/SwitchSecureStore.java
@@ -19,6 +19,7 @@
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.IoUtil;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.SiteLibraryLoaderUtil;
import com.google.gerrit.pgm.util.SiteProgram;
import com.google.gerrit.server.config.SitePaths;
@@ -185,6 +186,7 @@
}
}
+ @Nullable
private Path findJarWithSecureStore(SitePaths sitePaths, String secureStoreClass)
throws IOException {
List<Path> jars = SiteLibraryLoaderUtil.listJars(sitePaths.lib_dir);
diff --git a/java/com/google/gerrit/pgm/init/BUILD b/java/com/google/gerrit/pgm/init/BUILD
index 5849711..0c0d937 100644
--- a/java/com/google/gerrit/pgm/init/BUILD
+++ b/java/com/google/gerrit/pgm/init/BUILD
@@ -23,7 +23,6 @@
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/time",
"//lib:guava",
- "//lib:h2",
"//lib:jgit",
"//lib/commons:validator",
"//lib/flogger:api",
diff --git a/java/com/google/gerrit/pgm/init/BaseInit.java b/java/com/google/gerrit/pgm/init/BaseInit.java
index 4592cbb..b59b924 100644
--- a/java/com/google/gerrit/pgm/init/BaseInit.java
+++ b/java/com/google/gerrit/pgm/init/BaseInit.java
@@ -22,6 +22,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Die;
import com.google.gerrit.common.IoUtil;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.index.IndexType;
import com.google.gerrit.metrics.DisabledMetricMaker;
@@ -175,6 +176,7 @@
*/
protected void afterInit(SiteRun run) throws Exception {}
+ @Nullable
protected List<String> getInstallPlugins() {
try {
if (pluginsToInstall != null && pluginsToInstall.isEmpty()) {
@@ -304,6 +306,7 @@
return ConsoleUI.getInstance(false);
}
+ @Nullable
private SecureStoreInitData discoverSecureStoreClass() {
String secureStore = getSecureStoreLib();
if (Strings.isNullOrEmpty(secureStore)) {
diff --git a/java/com/google/gerrit/pgm/init/Browser.java b/java/com/google/gerrit/pgm/init/Browser.java
index 2e49e13..228a528 100644
--- a/java/com/google/gerrit/pgm/init/Browser.java
+++ b/java/com/google/gerrit/pgm/init/Browser.java
@@ -24,7 +24,7 @@
import java.net.URISyntaxException;
import org.eclipse.jgit.lib.Config;
-/** Opens the user's web browser to the web UI. */
+/** Points the user to a web browser URL. */
public class Browser {
private final Config cfg;
@@ -57,7 +57,7 @@
return;
}
waitForServer(uri);
- openBrowser(uri, link);
+ printBrowserUrl(uri, link);
}
private void waitForServer(URI uri) throws IOException {
@@ -97,17 +97,9 @@
return url;
}
- private void openBrowser(URI uri, String link) {
+ private void printBrowserUrl(URI uri, String link) {
String url = resolveUrl(uri, link);
- System.err.format("Opening %s ...", url);
+ System.err.format("Please open the following URL in the browser: %s", url);
System.err.flush();
- try {
- org.h2.tools.Server.openBrowser(url);
- System.err.println("OK");
- } catch (Exception e) {
- System.err.println("FAILED");
- System.err.println("Open Gerrit with a JavaScript capable browser:");
- System.err.println(" " + url);
- }
}
}
diff --git a/java/com/google/gerrit/pgm/init/InitAdminUser.java b/java/com/google/gerrit/pgm/init/InitAdminUser.java
index 4e854b5..3dce974 100644
--- a/java/com/google/gerrit/pgm/init/InitAdminUser.java
+++ b/java/com/google/gerrit/pgm/init/InitAdminUser.java
@@ -17,6 +17,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Strings;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.GroupReference;
import com.google.gerrit.entities.InternalGroup;
@@ -182,6 +183,7 @@
return email;
}
+ @Nullable
private AccountSshKey readSshKey(Account.Id id) throws IOException {
String defaultPublicSshKeyFile = "";
Path defaultPublicSshKeyPath = Paths.get(System.getProperty("user.home"), ".ssh", "id_rsa.pub");
diff --git a/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java b/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
index a7f9c5d..16c4ce7 100644
--- a/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
+++ b/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
@@ -16,6 +16,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.pgm.init.api.ConsoleUI;
import com.google.gerrit.pgm.init.api.InitStep;
@@ -62,6 +63,7 @@
return pluginsInitSteps;
}
+ @Nullable
private InitStep loadInitStep(Path jar) {
try {
URLClassLoader pluginLoader =
diff --git a/java/com/google/gerrit/pgm/init/SitePathInitializer.java b/java/com/google/gerrit/pgm/init/SitePathInitializer.java
index 236d185..a057e66 100644
--- a/java/com/google/gerrit/pgm/init/SitePathInitializer.java
+++ b/java/com/google/gerrit/pgm/init/SitePathInitializer.java
@@ -144,8 +144,6 @@
extractMailExample("RestoredHtml.soy");
extractMailExample("Reverted.soy");
extractMailExample("RevertedHtml.soy");
- extractMailExample("SetAssignee.soy");
- extractMailExample("SetAssigneeHtml.soy");
if (!ui.isBatch()) {
System.err.println();
diff --git a/java/com/google/gerrit/pgm/init/api/ConsoleUI.java b/java/com/google/gerrit/pgm/init/api/ConsoleUI.java
index dffdde7..865f7d7 100644
--- a/java/com/google/gerrit/pgm/init/api/ConsoleUI.java
+++ b/java/com/google/gerrit/pgm/init/api/ConsoleUI.java
@@ -17,8 +17,10 @@
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.FormatString;
import com.google.gerrit.common.Die;
+import com.google.gerrit.common.Nullable;
import java.io.Console;
import java.util.EnumSet;
+import java.util.Locale;
import java.util.Set;
/** Console based interaction with the invoking user. */
@@ -164,21 +166,22 @@
String def, Set<String> allowedValues, @FormatString String fmt, Object... args) {
for (; ; ) {
String r = readString(def, fmt, args);
- if (allowedValues.contains(r.toLowerCase())) {
- return r.toLowerCase();
+ if (allowedValues.contains(r.toLowerCase(Locale.US))) {
+ return r.toLowerCase(Locale.US);
}
if (!"?".equals(r)) {
console.printf("error: '%s' is not a valid choice\n", r);
}
console.printf(" Supported options are:\n");
for (String v : allowedValues) {
- console.printf(" %s\n", v.toLowerCase());
+ console.printf(" %s\n", v.toLowerCase(Locale.US));
}
}
}
@Override
@FormatMethod
+ @Nullable
public String password(String fmt, Object... args) {
final String prompt = String.format(fmt, args);
for (; ; ) {
@@ -208,7 +211,8 @@
T def, A options, String fmt, Object... args) {
final String prompt = String.format(fmt, args);
for (; ; ) {
- String r = console.readLine("%-30s [%s/?]: ", prompt, def.toString().toLowerCase());
+ String r =
+ console.readLine("%-30s [%s/?]: ", prompt, def.toString().toLowerCase(Locale.US));
if (r == null) {
throw abort();
}
@@ -226,7 +230,7 @@
}
console.printf(" Supported options are:\n");
for (T e : options) {
- console.printf(" %s\n", e.toString().toLowerCase());
+ console.printf(" %s\n", e.toString().toLowerCase(Locale.US));
}
}
}
diff --git a/java/com/google/gerrit/pgm/init/api/InitUtil.java b/java/com/google/gerrit/pgm/init/api/InitUtil.java
index d038de7..7688728 100644
--- a/java/com/google/gerrit/pgm/init/api/InitUtil.java
+++ b/java/com/google/gerrit/pgm/init/api/InitUtil.java
@@ -18,6 +18,7 @@
import com.google.common.io.ByteStreams;
import com.google.gerrit.common.Die;
+import com.google.gerrit.common.Nullable;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
@@ -127,6 +128,7 @@
}
}
+ @Nullable
private static InputStream open(Class<?> sibling, String name) {
final InputStream in = sibling.getResourceAsStream(name);
if (in == null) {
diff --git a/java/com/google/gerrit/pgm/init/api/Section.java b/java/com/google/gerrit/pgm/init/api/Section.java
index b5d35f4..5cc4b5d 100644
--- a/java/com/google/gerrit/pgm/init/api/Section.java
+++ b/java/com/google/gerrit/pgm/init/api/Section.java
@@ -166,6 +166,7 @@
return nv;
}
+ @Nullable
public String password(String username, String password) {
final String ov = getSecure(password);
diff --git a/java/com/google/gerrit/pgm/rules/PrologCompiler.java b/java/com/google/gerrit/pgm/rules/PrologCompiler.java
index 0a41db5..e68e203 100644
--- a/java/com/google/gerrit/pgm/rules/PrologCompiler.java
+++ b/java/com/google/gerrit/pgm/rules/PrologCompiler.java
@@ -14,6 +14,9 @@
package com.google.gerrit.pgm.rules;
+import static com.google.gerrit.server.project.ProjectConfig.RULES_PL_FILE;
+
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.Version;
import com.google.gerrit.entities.RefNames;
import com.google.gerrit.server.config.GerritServerConfig;
@@ -83,7 +86,7 @@
return Status.NO_RULES;
}
- ObjectId rulesId = git.resolve(metaConfig.name() + ":rules.pl");
+ ObjectId rulesId = git.resolve(metaConfig.name() + ":" + RULES_PL_FILE);
if (rulesId == null) {
return Status.NO_RULES;
}
@@ -182,6 +185,7 @@
}
}
+ @Nullable
private String getMyClasspath() {
StringBuilder cp = new StringBuilder();
appendClasspath(cp, getClass().getClassLoader());
diff --git a/java/com/google/gerrit/pgm/util/AbstractProgram.java b/java/com/google/gerrit/pgm/util/AbstractProgram.java
index 96b042a..00cba31 100644
--- a/java/com/google/gerrit/pgm/util/AbstractProgram.java
+++ b/java/com/google/gerrit/pgm/util/AbstractProgram.java
@@ -18,6 +18,7 @@
import com.google.gerrit.util.cli.CmdLineParser;
import com.google.gerrit.util.cli.OptionHandlers;
import java.io.StringWriter;
+import java.util.Locale;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.Option;
@@ -35,7 +36,7 @@
if (0 < dot) {
n = n.substring(dot + 1);
}
- return n.toLowerCase();
+ return n.toLowerCase(Locale.US);
}
public final int main(String[] argv) throws Exception {
diff --git a/java/com/google/gerrit/pgm/util/BatchProgramModule.java b/java/com/google/gerrit/pgm/util/BatchProgramModule.java
index f58387e3..1e41cbc 100644
--- a/java/com/google/gerrit/pgm/util/BatchProgramModule.java
+++ b/java/com/google/gerrit/pgm/util/BatchProgramModule.java
@@ -28,6 +28,7 @@
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.CurrentUser;
+import com.google.gerrit.server.DefaultRefLogIdentityProvider;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.InternalUser;
import com.google.gerrit.server.LibModuleLoader;
@@ -84,18 +85,19 @@
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.project.SubmitRequirementsEvaluatorImpl;
import com.google.gerrit.server.project.SubmitRuleEvaluator;
-import com.google.gerrit.server.query.FileEditsPredicate;
import com.google.gerrit.server.query.approval.ApprovalModule;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeIsVisibleToPredicate;
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gerrit.server.query.change.ConflictsCacheImpl;
-import com.google.gerrit.server.query.change.DistinctVotersPredicate;
import com.google.gerrit.server.restapi.group.GroupModule;
import com.google.gerrit.server.rules.DefaultSubmitRule.DefaultSubmitRuleModule;
import com.google.gerrit.server.rules.IgnoreSelfApprovalRule.IgnoreSelfApprovalRuleModule;
import com.google.gerrit.server.rules.PrologModule;
import com.google.gerrit.server.rules.SubmitRule;
+import com.google.gerrit.server.submitrequirement.predicate.DistinctVotersPredicate;
+import com.google.gerrit.server.submitrequirement.predicate.FileEditsPredicate;
+import com.google.gerrit.server.submitrequirement.predicate.HasSubmoduleUpdatePredicate;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.inject.Injector;
import com.google.inject.Key;
@@ -127,6 +129,7 @@
modules.add(PatchListCacheImpl.module());
modules.add(new DefaultUrlFormatterModule());
modules.add(DiffOperationsImpl.module());
+ modules.add(new DefaultRefLogIdentityProvider.Module());
// There is the concept of LifecycleModule, in Gerrit's own extension to Guice, which has these:
// listener().to(SomeClassImplementingLifecycleListener.class);
@@ -197,6 +200,7 @@
factory(ChangeData.AssistedFactory.class);
factory(ChangeIsVisibleToPredicate.Factory.class);
factory(DistinctVotersPredicate.Factory.class);
+ factory(HasSubmoduleUpdatePredicate.Factory.class);
factory(ProjectState.Factory.class);
DynamicMap.mapOf(binder(), ChangeQueryBuilder.ChangeOperatorFactory.class);
diff --git a/java/com/google/gerrit/prettify/BUILD b/java/com/google/gerrit/prettify/BUILD
index 0a15fda..a5c8b77 100644
--- a/java/com/google/gerrit/prettify/BUILD
+++ b/java/com/google/gerrit/prettify/BUILD
@@ -5,6 +5,7 @@
srcs = glob(["common/**/*.java"]),
visibility = ["//visibility:public"],
deps = [
+ "//java/com/google/gerrit/common:annotations",
"//lib:guava",
"//lib:jgit",
"//lib/auto:auto-value",
diff --git a/java/com/google/gerrit/prettify/common/SparseFileContent.java b/java/com/google/gerrit/prettify/common/SparseFileContent.java
index 1249b65..f40222a 100644
--- a/java/com/google/gerrit/prettify/common/SparseFileContent.java
+++ b/java/com/google/gerrit/prettify/common/SparseFileContent.java
@@ -17,6 +17,7 @@
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
+import com.google.gerrit.common.Nullable;
/**
* A class to store subset of a file's lines in a memory efficient way. Internally, it stores lines
@@ -134,6 +135,7 @@
return getSize();
}
+ @Nullable
private String getLine(int idx) {
// Most requests are sequential in nature, fetching the next
// line from the current range, or the next range.
diff --git a/java/com/google/gerrit/server/AssigneeStatusUpdate.java b/java/com/google/gerrit/server/AssigneeStatusUpdate.java
deleted file mode 100644
index 812aad1..0000000
--- a/java/com/google/gerrit/server/AssigneeStatusUpdate.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.gerrit.server;
-
-import com.google.auto.value.AutoValue;
-import com.google.gerrit.entities.Account;
-import java.time.Instant;
-import java.util.Optional;
-
-/** Change to an assignee's status. */
-@AutoValue
-public abstract class AssigneeStatusUpdate {
- public static AssigneeStatusUpdate create(
- Instant ts, Account.Id updatedBy, Optional<Account.Id> currentAssignee) {
- return new AutoValue_AssigneeStatusUpdate(ts, updatedBy, currentAssignee);
- }
-
- public abstract Instant date();
-
- public abstract Account.Id updatedBy();
-
- public abstract Optional<Account.Id> currentAssignee();
-}
diff --git a/java/com/google/gerrit/server/ProjectUtil.java b/java/com/google/gerrit/server/BranchUtil.java
similarity index 71%
rename from java/com/google/gerrit/server/ProjectUtil.java
rename to java/com/google/gerrit/server/BranchUtil.java
index fa056b3..78f693d 100644
--- a/java/com/google/gerrit/server/ProjectUtil.java
+++ b/java/com/google/gerrit/server/BranchUtil.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2012 The Android Open Source Project
+// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -21,8 +21,7 @@
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Repository;
-public class ProjectUtil {
-
+public class BranchUtil {
/**
* Checks whether the specified branch exists.
*
@@ -45,28 +44,4 @@
return exists;
}
}
-
- public static String sanitizeProjectName(String name) {
- name = stripGitSuffix(name);
- name = stripTrailingSlash(name);
- return name;
- }
-
- public static String stripGitSuffix(String name) {
- if (name.endsWith(".git")) {
- // Be nice and drop the trailing ".git" suffix, which we never keep
- // in our database, but clients might mistakenly provide anyway.
- //
- name = name.substring(0, name.length() - 4);
- name = stripTrailingSlash(name);
- }
- return name;
- }
-
- private static String stripTrailingSlash(String name) {
- while (name.endsWith("/")) {
- name = name.substring(0, name.length() - 1);
- }
- return name;
- }
}
diff --git a/java/com/google/gerrit/server/ChangeMessagesUtil.java b/java/com/google/gerrit/server/ChangeMessagesUtil.java
index 81cff6e..400da58 100644
--- a/java/com/google/gerrit/server/ChangeMessagesUtil.java
+++ b/java/com/google/gerrit/server/ChangeMessagesUtil.java
@@ -40,8 +40,6 @@
public static final String TAG_ABANDON = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "abandon";
public static final String TAG_CHERRY_PICK_CHANGE =
AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "cherryPickChange";
- public static final String TAG_DELETE_ASSIGNEE =
- AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "deleteAssignee";
public static final String TAG_DELETE_REVIEWER =
AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "deleteReviewer";
public static final String TAG_DELETE_VOTE = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "deleteVote";
@@ -49,7 +47,6 @@
public static final String TAG_MOVE = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "move";
public static final String TAG_RESTORE = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "restore";
public static final String TAG_REVERT = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "revert";
- public static final String TAG_SET_ASSIGNEE = AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "setAssignee";
public static final String TAG_UPDATE_ATTENTION_SET =
AUTOGENERATED_BY_GERRIT_TAG_PREFIX + "updateAttentionSet";
public static final String TAG_SET_DESCRIPTION =
@@ -150,7 +147,7 @@
cmi.tag = message.getTag();
cmi._revisionNumber = patchNum != null ? patchNum.get() : null;
Account.Id realAuthor = message.getRealAuthor();
- if (realAuthor != null) {
+ if (realAuthor != null && !realAuthor.equals(message.getAuthor())) {
cmi.realAuthor = accountLoader.get(realAuthor);
}
cmi.accountsInMessage =
diff --git a/java/com/google/gerrit/server/ChangeUtil.java b/java/com/google/gerrit/server/ChangeUtil.java
index d9edf42..2265055 100644
--- a/java/com/google/gerrit/server/ChangeUtil.java
+++ b/java/com/google/gerrit/server/ChangeUtil.java
@@ -31,6 +31,7 @@
import java.security.SecureRandom;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@@ -124,7 +125,10 @@
* @throws BadRequestException if the new commit message is null or empty
*/
public static void ensureChangeIdIsCorrect(
- boolean requireChangeId, String currentChangeId, String newCommitMessage)
+ boolean requireChangeId,
+ String currentChangeId,
+ String newCommitMessage,
+ UrlFormatter urlFormatter)
throws ResourceConflictException, BadRequestException {
RevCommit revCommit =
RevCommit.parse(
@@ -133,7 +137,7 @@
// Check that the commit message without footers is not empty
CommitMessageUtil.checkAndSanitizeCommitMessage(revCommit.getShortMessage());
- List<String> changeIdFooters = revCommit.getFooterLines(FooterConstants.CHANGE_ID);
+ List<String> changeIdFooters = getChangeIdsFromFooter(revCommit, urlFormatter);
if (requireChangeId && changeIdFooters.isEmpty()) {
throw new ResourceConflictException("missing Change-Id footer");
}
@@ -146,7 +150,7 @@
}
public static String status(Change c) {
- return c != null ? c.getStatus().name().toLowerCase() : "deleted";
+ return c != null ? c.getStatus().name().toLowerCase(Locale.US) : "deleted";
}
private static final Pattern LINK_CHANGE_ID_PATTERN = Pattern.compile("I[0-9a-f]{40}");
diff --git a/java/com/google/gerrit/server/CommentsUtil.java b/java/com/google/gerrit/server/CommentsUtil.java
index 8198ce4..285657e 100644
--- a/java/com/google/gerrit/server/CommentsUtil.java
+++ b/java/com/google/gerrit/server/CommentsUtil.java
@@ -104,6 +104,7 @@
return PatchSet.id(changeId, comment.key.patchSetId);
}
+ @Nullable
public static String extractMessageId(@Nullable String tag) {
if (tag == null || !tag.startsWith("mailMessageId=")) {
return null;
diff --git a/java/com/google/gerrit/server/DefaultRefLogIdentityProvider.java b/java/com/google/gerrit/server/DefaultRefLogIdentityProvider.java
new file mode 100644
index 0000000..10b4ec5
--- /dev/null
+++ b/java/com/google/gerrit/server/DefaultRefLogIdentityProvider.java
@@ -0,0 +1,97 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server;
+
+import com.google.common.base.Strings;
+import com.google.gerrit.entities.Account;
+import com.google.gerrit.server.config.AnonymousCowardName;
+import com.google.gerrit.server.config.EnablePeerIPInReflogRecord;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.time.Instant;
+import java.time.ZoneId;
+import org.eclipse.jgit.lib.PersonIdent;
+
+@Singleton
+public class DefaultRefLogIdentityProvider implements RefLogIdentityProvider {
+ public static class Module extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(RefLogIdentityProvider.class).to(DefaultRefLogIdentityProvider.class);
+ }
+ }
+
+ private final String anonymousCowardName;
+ private final Boolean enablePeerIPInReflogRecord;
+
+ @Inject
+ DefaultRefLogIdentityProvider(
+ @AnonymousCowardName String anonymousCowardName,
+ @EnablePeerIPInReflogRecord Boolean enablePeerIPInReflogRecord) {
+ this.anonymousCowardName = anonymousCowardName;
+ this.enablePeerIPInReflogRecord = enablePeerIPInReflogRecord;
+ }
+
+ @Override
+ public PersonIdent newRefLogIdent(IdentifiedUser user, Instant when, ZoneId zoneId) {
+ Account account = user.getAccount();
+
+ String name = account.fullName();
+ if (name == null || name.isEmpty()) {
+ name = account.preferredEmail();
+ }
+ if (name == null || name.isEmpty()) {
+ name = anonymousCowardName;
+ }
+
+ String email;
+ if (enablePeerIPInReflogRecord) {
+ email = constructMailAddress(user, guessHost(user));
+ } else {
+ email =
+ Strings.isNullOrEmpty(account.preferredEmail())
+ ? constructMailAddress(user, getDefaultDomain())
+ : account.preferredEmail();
+ }
+
+ return new PersonIdent(name, email, when, zoneId);
+ }
+
+ private String constructMailAddress(IdentifiedUser user, String host) {
+ return user.getUserName().orElse("")
+ + "|account-"
+ + user.getAccountId().toString()
+ + "@"
+ + host;
+ }
+
+ private String guessHost(IdentifiedUser user) {
+ String host = null;
+ SocketAddress remotePeer = user.getRemotePeer();
+ if (remotePeer instanceof InetSocketAddress) {
+ InetSocketAddress sa = (InetSocketAddress) remotePeer;
+ InetAddress in = sa.getAddress();
+ host = in != null ? in.getHostAddress() : sa.getHostName();
+ }
+ if (Strings.isNullOrEmpty(host)) {
+ return getDefaultDomain();
+ }
+ return host;
+ }
+}
diff --git a/java/com/google/gerrit/server/IdentifiedUser.java b/java/com/google/gerrit/server/IdentifiedUser.java
index 65a81f7..36d7888 100644
--- a/java/com/google/gerrit/server/IdentifiedUser.java
+++ b/java/com/google/gerrit/server/IdentifiedUser.java
@@ -19,7 +19,6 @@
import static com.google.common.flogger.LazyArgs.lazy;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.flogger.FluentLogger;
@@ -44,8 +43,6 @@
import com.google.inject.ProvisionException;
import com.google.inject.Singleton;
import com.google.inject.util.Providers;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.SocketAddress;
import java.net.URL;
@@ -66,6 +63,7 @@
private final AuthConfig authConfig;
private final Realm realm;
private final String anonymousCowardName;
+ private final RefLogIdentityProvider refLogIdentityProvider;
private final Provider<String> canonicalUrl;
private final AccountCache accountCache;
private final GroupBackend groupBackend;
@@ -76,6 +74,7 @@
AuthConfig authConfig,
Realm realm,
@AnonymousCowardName String anonymousCowardName,
+ RefLogIdentityProvider refLogIdentityProvider,
@CanonicalWebUrl Provider<String> canonicalUrl,
@EnablePeerIPInReflogRecord Boolean enablePeerIPInReflogRecord,
AccountCache accountCache,
@@ -83,6 +82,7 @@
this.authConfig = authConfig;
this.realm = realm;
this.anonymousCowardName = anonymousCowardName;
+ this.refLogIdentityProvider = refLogIdentityProvider;
this.canonicalUrl = canonicalUrl;
this.accountCache = accountCache;
this.groupBackend = groupBackend;
@@ -94,36 +94,37 @@
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
canonicalUrl,
accountCache,
groupBackend,
enablePeerIPInReflogRecord,
Providers.of(null),
state,
- null);
+ /* realUser= */ null);
}
public IdentifiedUser create(Account.Id id) {
- return create(null, id);
+ return create(/* remotePeer= */ null, id);
}
@VisibleForTesting
@UsedAt(UsedAt.Project.GOOGLE)
public IdentifiedUser forTest(Account.Id id, PropertyMap properties) {
- return runAs(null, id, null, properties);
+ return runAs(/* remotePeer= */ null, id, /* caller= */ null, properties);
}
- public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
- return runAs(remotePeer, id, null);
+ public IdentifiedUser create(@Nullable SocketAddress remotePeer, Account.Id id) {
+ return runAs(remotePeer, id, /* caller= */ null);
}
public IdentifiedUser runAs(
- SocketAddress remotePeer, Account.Id id, @Nullable CurrentUser caller) {
+ @Nullable SocketAddress remotePeer, Account.Id id, @Nullable CurrentUser caller) {
return runAs(remotePeer, id, caller, PropertyMap.EMPTY);
}
private IdentifiedUser runAs(
- SocketAddress remotePeer,
+ @Nullable SocketAddress remotePeer,
Account.Id id,
@Nullable CurrentUser caller,
PropertyMap properties) {
@@ -131,6 +132,7 @@
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
canonicalUrl,
accountCache,
groupBackend,
@@ -153,6 +155,7 @@
private final AuthConfig authConfig;
private final Realm realm;
private final String anonymousCowardName;
+ private final RefLogIdentityProvider refLogIdentityProvider;
private final Provider<String> canonicalUrl;
private final AccountCache accountCache;
private final GroupBackend groupBackend;
@@ -164,6 +167,7 @@
AuthConfig authConfig,
Realm realm,
@AnonymousCowardName String anonymousCowardName,
+ RefLogIdentityProvider refLogIdentityProvider,
@CanonicalWebUrl Provider<String> canonicalUrl,
AccountCache accountCache,
GroupBackend groupBackend,
@@ -172,6 +176,7 @@
this.authConfig = authConfig;
this.realm = realm;
this.anonymousCowardName = anonymousCowardName;
+ this.refLogIdentityProvider = refLogIdentityProvider;
this.canonicalUrl = canonicalUrl;
this.accountCache = accountCache;
this.groupBackend = groupBackend;
@@ -188,6 +193,7 @@
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
canonicalUrl,
accountCache,
groupBackend,
@@ -203,6 +209,7 @@
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
canonicalUrl,
accountCache,
groupBackend,
@@ -224,6 +231,7 @@
private final Realm realm;
private final GroupBackend groupBackend;
private final String anonymousCowardName;
+ private final RefLogIdentityProvider refLogIdentityProvider;
private final Boolean enablePeerIPInReflogRecord;
private final Set<String> validEmails = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
private final CurrentUser realUser; // Must be final since cached properties depend on it.
@@ -235,22 +243,25 @@
private boolean loadedAllEmails;
private Set<String> invalidEmails;
private GroupMembership effectiveGroups;
+ private PersonIdent refLogIdent;
private IdentifiedUser(
AuthConfig authConfig,
Realm realm,
String anonymousCowardName,
+ RefLogIdentityProvider refLogIdentityProvider,
Provider<String> canonicalUrl,
AccountCache accountCache,
GroupBackend groupBackend,
Boolean enablePeerIPInReflogRecord,
- @Nullable Provider<SocketAddress> remotePeerProvider,
+ Provider<SocketAddress> remotePeerProvider,
AccountState state,
@Nullable CurrentUser realUser) {
this(
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
canonicalUrl,
accountCache,
groupBackend,
@@ -266,11 +277,12 @@
AuthConfig authConfig,
Realm realm,
String anonymousCowardName,
+ RefLogIdentityProvider refLogIdentityProvider,
Provider<String> canonicalUrl,
AccountCache accountCache,
GroupBackend groupBackend,
Boolean enablePeerIPInReflogRecord,
- @Nullable Provider<SocketAddress> remotePeerProvider,
+ Provider<SocketAddress> remotePeerProvider,
Account.Id id,
@Nullable CurrentUser realUser,
PropertyMap properties) {
@@ -281,6 +293,7 @@
this.authConfig = authConfig;
this.realm = realm;
this.anonymousCowardName = anonymousCowardName;
+ this.refLogIdentityProvider = refLogIdentityProvider;
this.enablePeerIPInReflogRecord = enablePeerIPInReflogRecord;
this.remotePeerProvider = remotePeerProvider;
this.accountId = id;
@@ -426,36 +439,27 @@
return getAccountId();
}
+ @Nullable
+ public SocketAddress getRemotePeer() {
+ try {
+ return remotePeerProvider.get();
+ } catch (OutOfScopeException | ProvisionException e) {
+ return null;
+ }
+ }
+
public PersonIdent newRefLogIdent() {
- return newRefLogIdent(Instant.now(), ZoneId.systemDefault());
+ return refLogIdentityProvider.newRefLogIdent(this);
}
public PersonIdent newRefLogIdent(Instant when, ZoneId zoneId) {
- final Account ua = getAccount();
-
- String name = ua.fullName();
- if (name == null || name.isEmpty()) {
- name = ua.preferredEmail();
+ if (refLogIdent != null) {
+ refLogIdent =
+ new PersonIdent(refLogIdent.getName(), refLogIdent.getEmailAddress(), when, zoneId);
+ return refLogIdent;
}
- if (name == null || name.isEmpty()) {
- name = anonymousCowardName;
- }
-
- String user;
- if (enablePeerIPInReflogRecord) {
- user = constructMailAddress(ua, guessHost());
- } else {
- user =
- Strings.isNullOrEmpty(ua.preferredEmail())
- ? constructMailAddress(ua, "unknown")
- : ua.preferredEmail();
- }
-
- return new PersonIdent(name, user, when, zoneId);
- }
-
- private String constructMailAddress(Account ua, String host) {
- return getUserName().orElse("") + "|account-" + ua.id().toString() + "@" + host;
+ refLogIdent = refLogIdentityProvider.newRefLogIdent(this, when, zoneId);
+ return refLogIdent;
}
public PersonIdent newCommitterIdent(PersonIdent ident) {
@@ -533,6 +537,7 @@
authConfig,
realm,
anonymousCowardName,
+ refLogIdentityProvider,
Providers.of(canonicalUrl.get()),
accountCache,
groupBackend,
@@ -546,23 +551,4 @@
public boolean hasSameAccountId(CurrentUser other) {
return getAccountId().get() == other.getAccountId().get();
}
-
- private String guessHost() {
- String host = null;
- SocketAddress remotePeer = null;
- try {
- remotePeer = remotePeerProvider.get();
- } catch (OutOfScopeException | ProvisionException e) {
- // Leave null.
- }
- if (remotePeer instanceof InetSocketAddress) {
- InetSocketAddress sa = (InetSocketAddress) remotePeer;
- InetAddress in = sa.getAddress();
- host = in != null ? in.getHostAddress() : sa.getHostName();
- }
- if (Strings.isNullOrEmpty(host)) {
- return "unknown";
- }
- return host;
- }
}
diff --git a/java/com/google/gerrit/server/PatchSetUtil.java b/java/com/google/gerrit/server/PatchSetUtil.java
index 3d449b7..68d2314 100644
--- a/java/com/google/gerrit/server/PatchSetUtil.java
+++ b/java/com/google/gerrit/server/PatchSetUtil.java
@@ -35,11 +35,14 @@
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
+import com.google.gerrit.server.update.RepoContext;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.eclipse.jgit.lib.ObjectId;
@@ -105,6 +108,7 @@
.id(psId)
.commitId(commit)
.uploader(update.getAccountId())
+ .realUploader(update.getRealAccountId())
.createdOn(update.getWhen())
.groups(groups)
.pushCertificate(Optional.ofNullable(pushCertificate))
@@ -169,4 +173,55 @@
return src;
}
}
+
+ /**
+ * Gets the commit ID for the latest patch-set of a given change.
+ *
+ * <p>This also takes into account the patch sets that are added in the provided {@link
+ * RepoContext}.
+ *
+ * @param ctx to look for pending updates in.
+ * @param notesFactory to fetch existing patch sets with.
+ * @param changeId to get the latest commit for.
+ * @return the latest commit ID.
+ * @throws IOException if no committed nor pending commits found for the change.
+ */
+ public static RevCommit getCurrentRevCommitIncludingPending(
+ RepoContext ctx, ChangeNotes.Factory notesFactory, Change.Id changeId) throws IOException {
+ Map<String, ObjectId> refUpdates = ctx.getRepoView().getRefs(changeId.toRefPrefix());
+ refUpdates.remove("meta");
+ if (!refUpdates.isEmpty()) {
+ Optional<PatchSet.Id> latestPendingPatchSet =
+ refUpdates.keySet().stream()
+ .map(r -> PatchSet.Id.fromRef(changeId.toRefPrefix() + r))
+ .filter(Objects::nonNull)
+ .max(PatchSet.Id::compareTo);
+ if (latestPendingPatchSet.isPresent()) {
+ return ctx.getRevWalk().parseCommit(refUpdates.get(latestPendingPatchSet.get().getId()));
+ }
+ }
+ return getCurrentCommittedRevCommit(ctx.getProject(), ctx.getRevWalk(), notesFactory, changeId);
+ }
+
+ /**
+ * Gets the commit ID for the latest committed patch-set of a given change.
+ *
+ * <p>This DOES NOT take into account the patch sets that are added in the provided {@link
+ * RepoContext}.
+ *
+ * @param project name.
+ * @param notesFactory to fetch existing patch sets with.
+ * @param changeId to get the latest commit for.
+ * @return the latest commit ID.
+ * @throws IOException if no committed commits found for the change.
+ */
+ public static RevCommit getCurrentCommittedRevCommit(
+ Project.NameKey project,
+ RevWalk revWalk,
+ ChangeNotes.Factory notesFactory,
+ Change.Id changeId)
+ throws IOException {
+ ChangeNotes notes = notesFactory.createChecked(project, changeId);
+ return revWalk.parseCommit(notes.getCurrentPatchSet().commitId());
+ }
}
diff --git a/java/com/google/gerrit/server/PublishCommentsOp.java b/java/com/google/gerrit/server/PublishCommentsOp.java
index 827c078..830928a 100644
--- a/java/com/google/gerrit/server/PublishCommentsOp.java
+++ b/java/com/google/gerrit/server/PublishCommentsOp.java
@@ -23,7 +23,6 @@
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.server.change.EmailReviewComments;
-import com.google.gerrit.server.change.NotifyResolver;
import com.google.gerrit.server.extensions.events.CommentAdded;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.notedb.ChangeUpdate;
@@ -112,19 +111,16 @@
}
ChangeNotes changeNotes = changeNotesFactory.createChecked(projectNameKey, psId.changeId());
PatchSet ps = psUtil.get(changeNotes, psId);
- NotifyResolver.Result notify = ctx.getNotify(changeNotes.getChangeId());
- if (notify.shouldNotify()) {
- email
- .create(
- ctx,
- ps,
- preUpdateMetaId,
- mailMessage,
- comments,
- /* patchSetComment= */ null,
- /* labels= */ ImmutableList.of())
- .sendAsync();
- }
+ email
+ .create(
+ ctx,
+ ps,
+ preUpdateMetaId,
+ mailMessage,
+ comments,
+ /* patchSetComment= */ null,
+ /* labels= */ ImmutableList.of())
+ .sendAsync();
commentAdded.fire(
ctx.getChangeData(changeNotes),
ps,
diff --git a/java/com/google/gerrit/server/RefLogIdentityProvider.java b/java/com/google/gerrit/server/RefLogIdentityProvider.java
new file mode 100644
index 0000000..613b2bb
--- /dev/null
+++ b/java/com/google/gerrit/server/RefLogIdentityProvider.java
@@ -0,0 +1,110 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server;
+
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.stream.Collectors.joining;
+
+import com.google.common.collect.ImmutableList;
+import com.google.gerrit.entities.Account;
+import java.time.Instant;
+import java.time.ZoneId;
+import org.eclipse.jgit.lib.PersonIdent;
+
+/**
+ * Extension point that allows to control which identity should be recorded in the reflog for ref
+ * updates done by a user or done on behalf of a user.
+ */
+public interface RefLogIdentityProvider {
+ /**
+ * Creates a {@link PersonIdent} for the given user that should be used as the user identity in
+ * the reflog for ref updates done by this user or done on behalf of this user.
+ *
+ * <p>The returned {@link PersonIdent} is created with the current timestamp and the system
+ * default timezone.
+ *
+ * @param user the user for which a reflog identity should be created
+ */
+ default PersonIdent newRefLogIdent(IdentifiedUser user) {
+ return newRefLogIdent(user, Instant.now(), ZoneId.systemDefault());
+ }
+
+ /**
+ * Creates a {@link PersonIdent} for the given user that should be used as the user identity in
+ * the reflog for ref updates done by this user or done on behalf of this user.
+ *
+ * @param user the user for which a reflog identity should be created
+ * @param when the timestamp that should be used to create the {@link PersonIdent}
+ * @param zoneId the zone ID identifying the timezone that should be used to create the {@link
+ * PersonIdent}
+ */
+ PersonIdent newRefLogIdent(IdentifiedUser user, Instant when, ZoneId zoneId);
+
+ /**
+ * Creates a {@link PersonIdent} for the given users that should be used as the user identity in
+ * the reflog for ref updates done by these users or done on behalf of these users.
+ *
+ * <p>Usually ref updates are done by a single user or on behalf of a single user, but with {@link
+ * com.google.gerrit.server.update.BatchUpdate} it's possible that updates of different users are
+ * batched together into a single ref update.
+ *
+ * <p>If a single user is provided or all provided users reference the same account a reflog
+ * identity for that user/account is created and returned.
+ *
+ * <p>If multiple users (that reference different accounts) are provided a shared reflog identity
+ * is created and returned. The shared reflog identity lists all involved accounts. How the shared
+ * reflog identity looks like doesn't matter much, as long as it's not the reflog identity of a
+ * real user (e.g. if impersonated updates of multiple users are batched together it must not be
+ * the reflog identity of the real user).
+ *
+ * @param users the users for which a reflog identity should be created
+ * @param when the timestamp that should be used to create the {@link PersonIdent}
+ * @param zoneId the zone ID identifying the timezone that should be used to create the {@link
+ * PersonIdent}
+ */
+ default PersonIdent newRefLogIdent(
+ ImmutableList<IdentifiedUser> users, Instant when, ZoneId zoneId) {
+ checkState(!users.isEmpty(), "expected at least one user");
+
+ // If it's a single user create a reflog ident for that user.
+ // Use IdentifiedUser.newReflogIdent(Instant, ZoneId) rather than invoking
+ // #newRefLogIdent(IdentifiedUser, Instant ZoneId) directly, so that we can benefit from the
+ // reflog ident caching in IdentifiedUser.
+ if (users.size() == 1 || users.stream().allMatch(user -> user.hasSameAccountId(users.get(0)))) {
+ return users.get(0).newRefLogIdent(when, zoneId);
+ }
+
+ // Multiple users (for different accounts) have been provided. Create a shared relog identity
+ // that lists all involved accounts.
+ String accounts =
+ users.stream()
+ .map(IdentifiedUser::getAccountId)
+ .map(Account.Id::get)
+ .distinct()
+ .sorted()
+ .map(id -> "account-" + id)
+ .collect(joining("|"));
+ return new PersonIdent(
+ accounts, String.format("%s@%s", accounts, getDefaultDomain()), when, zoneId);
+ }
+
+ /**
+ * Returns the default domain for constructing email addresses if guessing the correct host is not
+ * possible.
+ */
+ default String getDefaultDomain() {
+ return "unknown";
+ }
+}
diff --git a/java/com/google/gerrit/server/StarredChangesUtil.java b/java/com/google/gerrit/server/StarredChangesUtil.java
index c845415..cf04029 100644
--- a/java/com/google/gerrit/server/StarredChangesUtil.java
+++ b/java/com/google/gerrit/server/StarredChangesUtil.java
@@ -14,6 +14,7 @@
package com.google.gerrit.server;
+import static com.google.gerrit.server.update.context.RefUpdateContext.RefUpdateType.CHANGE_MODIFICATION;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
@@ -23,7 +24,6 @@
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
@@ -32,7 +32,6 @@
import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change;
-import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.git.GitUpdateFailureException;
@@ -40,13 +39,10 @@
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
-import com.google.gerrit.server.index.change.ChangeField;
import com.google.gerrit.server.logging.Metadata;
import com.google.gerrit.server.logging.TraceContext;
import com.google.gerrit.server.logging.TraceContext.TraceTimer;
-import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gerrit.server.query.change.ChangeData;
-import com.google.gerrit.server.query.change.InternalChangeQuery;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -55,6 +51,7 @@
import java.util.Collections;
import java.util.List;
import java.util.NavigableSet;
+import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
@@ -81,6 +78,7 @@
public abstract static class StarField {
private static final String SEPARATOR = ":";
+ @Nullable
public static StarField parse(String s) {
int p = s.indexOf(SEPARATOR);
if (p >= 0) {
@@ -167,20 +165,17 @@
private final GitReferenceUpdated gitRefUpdated;
private final AllUsersName allUsers;
private final Provider<PersonIdent> serverIdent;
- private final Provider<InternalChangeQuery> queryProvider;
@Inject
StarredChangesUtil(
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
AllUsersName allUsers,
- @GerritPersonIdent Provider<PersonIdent> serverIdent,
- Provider<InternalChangeQuery> queryProvider) {
+ @GerritPersonIdent Provider<PersonIdent> serverIdent) {
this.repoManager = repoManager;
this.gitRefUpdated = gitRefUpdated;
this.allUsers = allUsers;
this.serverIdent = serverIdent;
- this.queryProvider = queryProvider;
}
public NavigableSet<String> getLabels(Account.Id accountId, Change.Id changeId) {
@@ -195,7 +190,7 @@
}
}
- public void star(Account.Id accountId, Project.NameKey project, Change.Id changeId, Operation op)
+ public void star(Account.Id accountId, Change.Id changeId, Operation op)
throws IllegalLabelException {
try (Repository repo = repoManager.openRepository(allUsers)) {
String refName = RefNames.refsStarredChanges(changeId, accountId);
@@ -262,7 +257,7 @@
batchUpdate.setAllowNonFastForwards(true);
batchUpdate.setRefLogIdent(serverIdent.get());
batchUpdate.setRefLogMessage("Unstar change " + changeId.get(), true);
- for (Account.Id accountId : byChangeFromIndex(changeId).keySet()) {
+ for (Account.Id accountId : getStars(repo, changeId)) {
String refName = RefNames.refsStarredChanges(changeId, accountId);
Ref ref = repo.getRefDatabase().exactRef(refName);
if (ref != null) {
@@ -288,12 +283,7 @@
public ImmutableMap<Account.Id, StarRef> byChange(Change.Id changeId) {
try (Repository repo = repoManager.openRepository(allUsers)) {
ImmutableMap.Builder<Account.Id, StarRef> builder = ImmutableMap.builder();
- for (String refPart : getRefNames(repo, RefNames.refsStarredChangesPrefix(changeId))) {
- Integer id = Ints.tryParse(refPart);
- if (id == null) {
- continue;
- }
- Account.Id accountId = Account.id(id);
+ for (Account.Id accountId : getStars(repo, changeId)) {
builder.put(accountId, readLabels(repo, RefNames.refsStarredChanges(changeId, accountId)));
}
return builder.build();
@@ -303,7 +293,7 @@
}
}
- public ImmutableSet<Change.Id> byAccountId(Account.Id accountId, String label) {
+ public ImmutableSet<Change.Id> byAccountId(Account.Id accountId) {
try (Repository repo = repoManager.openRepository(allUsers)) {
ImmutableSet.Builder<Change.Id> builder = ImmutableSet.builder();
for (Ref ref : repo.getRefDatabase().getRefsByPrefix(RefNames.REFS_STARRED_CHANGES)) {
@@ -314,7 +304,7 @@
}
// Skip all refs that don't contain the required label.
StarRef starRef = readLabels(repo, ref.getName());
- if (!starRef.labels().contains(label)) {
+ if (!starRef.labels().contains(DEFAULT_LABEL)) {
continue;
}
@@ -332,22 +322,15 @@
}
}
- public ImmutableListMultimap<Account.Id, String> byChangeFromIndex(Change.Id changeId) {
- List<ChangeData> changeData =
- queryProvider
- .get()
- .setRequestedFields(ChangeField.ID, ChangeField.STAR)
- .byLegacyChangeId(changeId);
- if (changeData.size() != 1) {
- throw new NoSuchChangeException(changeId);
- }
- return changeData.get(0).stars();
- }
-
- private static Set<String> getRefNames(Repository repo, String prefix) throws IOException {
- RefDatabase refDb = repo.getRefDatabase();
+ private static Set<Account.Id> getStars(Repository allUsers, Change.Id changeId)
+ throws IOException {
+ String prefix = RefNames.refsStarredChangesPrefix(changeId);
+ RefDatabase refDb = allUsers.getRefDatabase();
return refDb.getRefsByPrefix(prefix).stream()
.map(r -> r.getName().substring(prefix.length()))
+ .map(refPart -> Ints.tryParse(refPart))
+ .filter(Objects::nonNull)
+ .map(id -> Account.id(id))
.collect(toSet());
}
@@ -432,27 +415,29 @@
u.setNewObjectId(writeLabels(repo, labels));
u.setRefLogIdent(serverIdent.get());
u.setRefLogMessage("Update star labels", true);
- RefUpdate.Result result = u.update(rw);
- switch (result) {
- case NEW:
- case FORCED:
- case NO_CHANGE:
- case FAST_FORWARD:
- gitRefUpdated.fire(allUsers, u, null);
- return;
- case LOCK_FAILURE:
- throw new LockFailureException(
- String.format("Update star labels on ref %s failed", refName), u);
- case IO_FAILURE:
- case NOT_ATTEMPTED:
- case REJECTED:
- case REJECTED_CURRENT_BRANCH:
- case RENAMED:
- case REJECTED_MISSING_OBJECT:
- case REJECTED_OTHER_REASON:
- default:
- throw new StorageException(
- String.format("Update star labels on ref %s failed: %s", refName, result.name()));
+ try (RefUpdateContext ctx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
+ RefUpdate.Result result = u.update(rw);
+ switch (result) {
+ case NEW:
+ case FORCED:
+ case NO_CHANGE:
+ case FAST_FORWARD:
+ gitRefUpdated.fire(allUsers, u, null);
+ return;
+ case LOCK_FAILURE:
+ throw new LockFailureException(
+ String.format("Update star labels on ref %s failed", refName), u);
+ case IO_FAILURE:
+ case NOT_ATTEMPTED:
+ case REJECTED:
+ case REJECTED_CURRENT_BRANCH:
+ case RENAMED:
+ case REJECTED_MISSING_OBJECT:
+ case REJECTED_OTHER_REASON:
+ default:
+ throw new StorageException(
+ String.format("Update star labels on ref %s failed: %s", refName, result.name()));
+ }
}
}
}
@@ -471,26 +456,28 @@
u.setExpectedOldObjectId(oldObjectId);
u.setRefLogIdent(serverIdent.get());
u.setRefLogMessage("Unstar change", true);
- RefUpdate.Result result = u.delete();
- switch (result) {
- case FORCED:
- gitRefUpdated.fire(allUsers, u, null);
- return;
- case LOCK_FAILURE:
- throw new LockFailureException(String.format("Delete star ref %s failed", refName), u);
- case NEW:
- case NO_CHANGE:
- case FAST_FORWARD:
- case IO_FAILURE:
- case NOT_ATTEMPTED:
- case REJECTED:
- case REJECTED_CURRENT_BRANCH:
- case RENAMED:
- case REJECTED_MISSING_OBJECT:
- case REJECTED_OTHER_REASON:
- default:
- throw new StorageException(
- String.format("Delete star ref %s failed: %s", refName, result.name()));
+ try (RefUpdateContext ctx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
+ RefUpdate.Result result = u.delete();
+ switch (result) {
+ case FORCED:
+ gitRefUpdated.fire(allUsers, u, null);
+ return;
+ case LOCK_FAILURE:
+ throw new LockFailureException(String.format("Delete star ref %s failed", refName), u);
+ case NEW:
+ case NO_CHANGE:
+ case FAST_FORWARD:
+ case IO_FAILURE:
+ case NOT_ATTEMPTED:
+ case REJECTED:
+ case REJECTED_CURRENT_BRANCH:
+ case RENAMED:
+ case REJECTED_MISSING_OBJECT:
+ case REJECTED_OTHER_REASON:
+ default:
+ throw new StorageException(
+ String.format("Delete star ref %s failed: %s", refName, result.name()));
+ }
}
}
}
diff --git a/java/com/google/gerrit/server/account/AccountControl.java b/java/com/google/gerrit/server/account/AccountControl.java
index c80059b..ca63565 100644
--- a/java/com/google/gerrit/server/account/AccountControl.java
+++ b/java/com/google/gerrit/server/account/AccountControl.java
@@ -82,12 +82,12 @@
* accounts.
*/
@UsedAt(UsedAt.Project.PLUGIN_CODE_OWNERS)
- public AccountControl get(IdentifiedUser identifiedUser) {
+ public AccountControl get(CurrentUser user) {
return new AccountControl(
permissionBackend,
projectCache,
groupControlFactory,
- identifiedUser,
+ user,
userFactory,
accountVisibility);
}
diff --git a/java/com/google/gerrit/server/account/AccountDelta.java b/java/com/google/gerrit/server/account/AccountDelta.java
index fac3233..8f285b5 100644
--- a/java/com/google/gerrit/server/account/AccountDelta.java
+++ b/java/com/google/gerrit/server/account/AccountDelta.java
@@ -161,6 +161,11 @@
*/
public abstract Optional<EditPreferencesInfo> getEditPreferences();
+ public boolean hasExternalIdUpdates() {
+ return !this.getCreatedExternalIds().isEmpty()
+ || !this.getDeletedExternalIds().isEmpty()
+ || !this.getUpdatedExternalIds().isEmpty();
+ }
/**
* Class to build an {@link AccountDelta}.
*
diff --git a/java/com/google/gerrit/server/account/AccountLimits.java b/java/com/google/gerrit/server/account/AccountLimits.java
index 5549d28..d97563a 100644
--- a/java/com/google/gerrit/server/account/AccountLimits.java
+++ b/java/com/google/gerrit/server/account/AccountLimits.java
@@ -14,6 +14,7 @@
package com.google.gerrit.server.account;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.entities.PermissionRange;
import com.google.gerrit.entities.PermissionRule;
@@ -105,6 +106,7 @@
}
/** The range of permitted values associated with a label permission. */
+ @Nullable
public PermissionRange getRange(String permission) {
if (GlobalCapability.hasRange(permission)) {
return toRange(permission, getRules(permission));
diff --git a/java/com/google/gerrit/server/account/AccountManager.java b/java/com/google/gerrit/server/account/AccountManager.java
index 891a467..edec52c 100644
--- a/java/com/google/gerrit/server/account/AccountManager.java
+++ b/java/com/google/gerrit/server/account/AccountManager.java
@@ -16,6 +16,8 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
+import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GERRIT;
+import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GOOGLE_OAUTH;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME;
import com.google.common.annotations.VisibleForTesting;
@@ -146,10 +148,7 @@
try {
Optional<ExternalId> optionalExtId = externalIds.get(who.getExternalIdKey());
if (!optionalExtId.isPresent()) {
- logger.atFine().log(
- "External ID for account %s not found. A new account will be automatically created.",
- who.getUserName());
- return create(who);
+ return createOrLinkAccount(who);
}
ExternalId extId = optionalExtId.get();
@@ -180,6 +179,46 @@
}
}
+ /**
+ * Determines if a new account should be created or if we should link to an existing account.
+ *
+ * @param who identity of the user, with any details we received about them.
+ * @return the result of authenticating the user.
+ * @throws AccountException the account does not exist, and cannot be created, or exists, but
+ * cannot be located, is unable to be activated or deactivated, or is inactive, or cannot be
+ * added to the admin group (only for the first account).
+ */
+ private AuthResult createOrLinkAccount(AuthRequest who)
+ throws AccountException, IOException, ConfigInvalidException {
+ // TODO: in case of extension of further migration paths this code should
+ // probably be refactored out by creating an AccountMigrator extension point.
+ if (who.getExternalIdKey().isScheme(SCHEME_GOOGLE_OAUTH)) {
+ Optional<ExternalId> existingLDAPExtID = findLdapExternalId(who);
+ if (existingLDAPExtID.isPresent()) {
+ return migrateLdapAccountToOauth(who, existingLDAPExtID.get());
+ }
+ }
+ logger.atFine().log(
+ "External ID for account %s not found. A new account will be automatically created.",
+ who.getEmailAddress());
+ return create(who);
+ }
+
+ private AuthResult migrateLdapAccountToOauth(AuthRequest who, ExternalId ldapExternalId)
+ throws AccountException, IOException, ConfigInvalidException {
+ Account.Id extAccId = ldapExternalId.accountId();
+ AuthResult res = link(extAccId, who);
+ accountsUpdateProvider
+ .get()
+ .update(
+ "remove existing LDAP externalId with matching e-mail",
+ extAccId,
+ u -> {
+ u.deleteExternalId(ldapExternalId);
+ });
+ return res;
+ }
+
private void deactivateAccountIfItExists(AuthRequest authRequest) {
if (!shouldUpdateActiveStatus(authRequest)) {
return;
@@ -277,6 +316,17 @@
}
}
+ private Optional<ExternalId> findLdapExternalId(AuthRequest who) throws IOException {
+ String email = who.getEmailAddress();
+ if (email == null || email.isEmpty()) {
+ return Optional.empty();
+ }
+
+ Optional<ExternalId> ldapExternalId =
+ externalIds.byEmail(email).stream().filter(a -> a.isScheme(SCHEME_GERRIT)).findFirst();
+ return ldapExternalId;
+ }
+
private AuthResult create(AuthRequest who)
throws AccountException, IOException, ConfigInvalidException {
Account.Id newId = Account.id(sequences.nextAccountId());
diff --git a/java/com/google/gerrit/server/account/AccountResolver.java b/java/com/google/gerrit/server/account/AccountResolver.java
index 8824d56..2020d2f 100644
--- a/java/com/google/gerrit/server/account/AccountResolver.java
+++ b/java/com/google/gerrit/server/account/AccountResolver.java
@@ -25,6 +25,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.gerrit.entities.Account;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
@@ -43,6 +44,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
@@ -132,12 +134,18 @@
private final String input;
private final ImmutableList<AccountState> list;
private final ImmutableList<AccountState> filteredInactive;
+ private final CurrentUser searchedAsUser;
@VisibleForTesting
- Result(String input, List<AccountState> list, List<AccountState> filteredInactive) {
+ Result(
+ String input,
+ List<AccountState> list,
+ List<AccountState> filteredInactive,
+ CurrentUser searchedAsUser) {
this.input = requireNonNull(input);
this.list = canonicalize(list);
this.filteredInactive = canonicalize(filteredInactive);
+ this.searchedAsUser = requireNonNull(searchedAsUser);
}
private ImmutableList<AccountState> canonicalize(List<AccountState> list) {
@@ -180,13 +188,21 @@
}
}
- public IdentifiedUser asUniqueUser() throws UnresolvableAccountException {
+ private void ensureSelfIsUniqueIdentifiedUser() throws UnresolvableAccountException {
ensureUnique();
+ if (!searchedAsUser.isIdentifiedUser()) {
+ throw new UnresolvableAccountException(this);
+ }
+ }
+
+ public IdentifiedUser asUniqueUser() throws UnresolvableAccountException {
if (isSelf()) {
+ ensureSelfIsUniqueIdentifiedUser();
// In the special case of "self", use the exact IdentifiedUser from the request context, to
// preserve the peer address and any other per-request state.
- return self.get().asIdentifiedUser();
+ return searchedAsUser.asIdentifiedUser();
}
+ ensureUnique();
return userFactory.create(asUnique());
}
@@ -194,11 +210,10 @@
throws UnresolvableAccountException {
ensureUnique();
if (isSelf()) {
- // TODO(dborowitz): This preserves old behavior, but it seems wrong to discard the caller.
- return self.get().asIdentifiedUser();
+ return searchedAsUser.asIdentifiedUser();
}
return userFactory.runAs(
- null, list.get(0).account().id(), requireNonNull(caller).getRealUser());
+ /* remotePeer= */ null, list.get(0).account().id(), requireNonNull(caller).getRealUser());
}
@VisibleForTesting
@@ -217,20 +232,57 @@
return true;
}
- default boolean callerMayAssumeCandidatesAreVisible() {
+ /**
+ * Searches can be done on behalf of either the current user or another provided user. The
+ * results of some searchers, such as BySelf, are affected by the context user.
+ */
+ default boolean requiresContextUser() {
return false;
}
Optional<I> tryParse(String input) throws IOException;
- Stream<AccountState> search(I input) throws IOException, ConfigInvalidException;
+ /**
+ * This method should be implemented for every searcher which doesn't require a context user.
+ *
+ * @param input to search for
+ * @return stream of the matching accounts
+ * @throws IOException by some subclasses
+ * @throws ConfigInvalidException by some subclasses
+ */
+ default Stream<AccountState> search(I input) throws IOException, ConfigInvalidException {
+ throw new IllegalStateException("search(I) default implementation should never be called.");
+ }
+
+ /**
+ * This method should be implemented for every searcher which requires a context user.
+ *
+ * @param input to search for
+ * @param asUser the context user for the search
+ * @return stream of the matching accounts
+ * @throws IOException by some subclasses
+ * @throws ConfigInvalidException by some subclasses
+ */
+ default Stream<AccountState> search(I input, CurrentUser asUser)
+ throws IOException, ConfigInvalidException {
+ if (!requiresContextUser()) {
+ return search(input);
+ }
+ throw new IllegalStateException(
+ "The searcher requires a context user, but doesn't implement search(input, asUser).");
+ }
boolean shortCircuitIfNoResults();
- default Optional<Stream<AccountState>> trySearch(String input)
+ default Optional<Stream<AccountState>> trySearch(String input, CurrentUser asUser)
throws IOException, ConfigInvalidException {
Optional<I> parsed = tryParse(input);
- return parsed.isPresent() ? Optional.of(search(parsed.get())) : Optional.empty();
+ if (parsed.isEmpty()) {
+ return Optional.empty();
+ }
+ return requiresContextUser()
+ ? Optional.of(search(parsed.get(), asUser))
+ : Optional.of(search(parsed.get()));
}
}
@@ -251,14 +303,14 @@
}
}
- private class BySelf extends StringSearcher {
+ private static class BySelf extends StringSearcher {
@Override
public boolean callerShouldFilterOutInactiveCandidates() {
return false;
}
@Override
- public boolean callerMayAssumeCandidatesAreVisible() {
+ public boolean requiresContextUser() {
return true;
}
@@ -268,12 +320,11 @@
}
@Override
- public Stream<AccountState> search(String input) {
- CurrentUser user = self.get();
- if (!user.isIdentifiedUser()) {
+ public Stream<AccountState> search(String input, CurrentUser asUser) {
+ if (!asUser.isIdentifiedUser()) {
return Stream.empty();
}
- return Stream.of(user.asIdentifiedUser().state());
+ return Stream.of(asUser.asIdentifiedUser().state());
}
@Override
@@ -372,13 +423,70 @@
private class ByEmail extends StringSearcher {
@Override
+ public boolean requiresContextUser() {
+ return true;
+ }
+
+ @Override
protected boolean matches(String input) {
return input.contains("@");
}
@Override
- public Stream<AccountState> search(String input) throws IOException {
- return toAccountStates(emails.getAccountFor(input));
+ public Stream<AccountState> search(String input, CurrentUser asUser) throws IOException {
+ boolean canViewSecondaryEmails = false;
+ try {
+ if (permissionBackend.user(asUser).test(GlobalPermission.VIEW_SECONDARY_EMAILS)) {
+ canViewSecondaryEmails = true;
+ }
+ } catch (PermissionBackendException e) {
+ // remains false
+ }
+
+ if (canViewSecondaryEmails) {
+ return toAccountStates(emails.getAccountFor(input));
+ }
+
+ // User cannot see secondary emails, hence search by preferred email only.
+ List<AccountState> accountStates = accountQueryProvider.get().byPreferredEmail(input);
+
+ if (accountStates.size() == 1) {
+ return Stream.of(Iterables.getOnlyElement(accountStates));
+ }
+
+ if (accountStates.size() > 1) {
+ // An email can only belong to a single account. If multiple accounts are found it means
+ // there is an inconsistency, i.e. some of the found accounts have a preferred email set
+ // that they do not own via an external ID. Hence in this case we return only the one
+ // account that actually owns the email via an external ID.
+ for (AccountState accountState : accountStates) {
+ if (accountState.externalIds().stream()
+ .map(ExternalId::email)
+ .filter(Objects::nonNull)
+ .anyMatch(email -> email.equals(input))) {
+ return Stream.of(accountState);
+ }
+ }
+
+ // None of the matched accounts owns the email, return all matches to be consistent with
+ // the behavior of Emails.getAccountFor(String) that is used above if the user can see
+ // secondary emails.
+ return accountStates.stream();
+ }
+
+ // No match by preferred email. Since users can always see their own secondary emails, check
+ // if the input matches a secondary email of the user and if yes, return the account of the
+ // user.
+ if (asUser.isIdentifiedUser()
+ && asUser.asIdentifiedUser().state().externalIds().stream()
+ .map(ExternalId::email)
+ .filter(Objects::nonNull)
+ .anyMatch(email -> email.equals(input))) {
+ return Stream.of(asUser.asIdentifiedUser().state());
+ }
+
+ // No match.
+ return Stream.empty();
}
@Override
@@ -399,34 +507,9 @@
}
}
- private class ByFullName implements Searcher<AccountState> {
- @Override
- public boolean callerMayAssumeCandidatesAreVisible() {
- return true; // Rely on enforceVisibility from the index.
- }
-
- @Override
- public Optional<AccountState> tryParse(String input) {
- List<AccountState> results =
- accountQueryProvider.get().enforceVisibility(true).byFullName(input);
- return results.size() == 1 ? Optional.of(results.get(0)) : Optional.empty();
- }
-
- @Override
- public Stream<AccountState> search(AccountState input) {
- return Stream.of(input);
- }
-
- @Override
- public boolean shortCircuitIfNoResults() {
- return false;
- }
- }
-
- private class ByDefaultSearch extends StringSearcher {
- @Override
- public boolean callerMayAssumeCandidatesAreVisible() {
- return true; // Rely on enforceVisibility from the index.
+ private class ByFullName extends StringSearcher {
+ ByFullName() {
+ super();
}
@Override
@@ -436,20 +519,45 @@
@Override
public Stream<AccountState> search(String input) {
+ return accountQueryProvider.get().byFullName(input).stream();
+ }
+
+ @Override
+ public boolean shortCircuitIfNoResults() {
+ return false;
+ }
+ }
+
+ private class ByDefaultSearch extends StringSearcher {
+ ByDefaultSearch() {
+ super();
+ }
+
+ @Override
+ public boolean requiresContextUser() {
+ return true;
+ }
+
+ @Override
+ protected boolean matches(String input) {
+ return true;
+ }
+
+ @Override
+ public Stream<AccountState> search(String input, CurrentUser asUser) {
// At this point we have no clue. Just perform a whole bunch of suggestions and pray we come
// up with a reasonable result list.
// TODO(dborowitz): This doesn't match the documentation; consider whether it's possible to be
// more strict here.
- boolean canSeeSecondaryEmails = false;
+ boolean canViewSecondaryEmails = false;
try {
- if (permissionBackend.user(self.get()).test(GlobalPermission.MODIFY_ACCOUNT)) {
- canSeeSecondaryEmails = true;
+ if (permissionBackend.user(asUser).test(GlobalPermission.VIEW_SECONDARY_EMAILS)) {
+ canViewSecondaryEmails = true;
}
} catch (PermissionBackendException e) {
// remains false
}
- return accountQueryProvider.get().enforceVisibility(true)
- .byDefault(input, canSeeSecondaryEmails).stream();
+ return accountQueryProvider.get().byDefault(input, canViewSecondaryEmails).stream();
}
@Override
@@ -538,12 +646,59 @@
* @throws IOException if an error occurs.
*/
public Result resolve(String input) throws ConfigInvalidException, IOException {
- return searchImpl(input, searchers, this::canSeePredicate, AccountResolver::isActive);
+ return searchImpl(
+ input, searchers, self.get(), this::currentUserCanSeePredicate, AccountResolver::isActive);
}
public Result resolve(String input, Predicate<AccountState> accountActivityPredicate)
throws ConfigInvalidException, IOException {
- return searchImpl(input, searchers, this::canSeePredicate, accountActivityPredicate);
+ return searchImpl(
+ input, searchers, self.get(), this::currentUserCanSeePredicate, accountActivityPredicate);
+ }
+
+ /**
+ * Resolves all accounts matching the input string, visible to the provided user.
+ *
+ * <p>The following input formats are recognized:
+ *
+ * <ul>
+ * <li>The strings {@code "self"} and {@code "me"}, if the provided user is an {@link
+ * IdentifiedUser}. In this case, may return exactly one inactive account.
+ * <li>A bare account ID ({@code "18419"}). In this case, may return exactly one inactive
+ * account. This case short-circuits if the input matches.
+ * <li>An account ID in parentheses following a full name ({@code "Full Name (18419)"}). This
+ * case short-circuits if the input matches.
+ * <li>A username ({@code "username"}).
+ * <li>A full name and email address ({@code "Full Name <email@example>"}). This case
+ * short-circuits if the input matches.
+ * <li>An email address ({@code "email@example"}. This case short-circuits if the input matches.
+ * <li>An account name recognized by the configured {@link Realm#lookup(String)} Realm}.
+ * <li>A full name ({@code "Full Name"}).
+ * <li>As a fallback, a {@link
+ * com.google.gerrit.server.query.account.AccountPredicates#defaultPredicate(Schema,
+ * boolean, String) default search} against the account index.
+ * </ul>
+ *
+ * @param asUser user to resolve the users by.
+ * @param input input string.
+ * @return a result describing matching accounts. Never null even if the result set is empty.
+ * @throws ConfigInvalidException if an error occurs.
+ * @throws IOException if an error occurs.
+ */
+ public Result resolveAsUser(CurrentUser asUser, String input)
+ throws ConfigInvalidException, IOException {
+ return resolveAsUser(asUser, input, AccountResolver::isActive);
+ }
+
+ public Result resolveAsUser(
+ CurrentUser asUser, String input, Predicate<AccountState> accountActivityPredicate)
+ throws ConfigInvalidException, IOException {
+ return searchImpl(
+ input,
+ searchers,
+ asUser,
+ new ProvidedUserCanSeePredicate(asUser),
+ accountActivityPredicate);
}
/**
@@ -556,17 +711,35 @@
* instead will be stored as a link to the corresponding Gerrit Account.
*/
public Result resolveIncludeInactive(String input) throws ConfigInvalidException, IOException {
- return searchImpl(input, searchers, this::canSeePredicate, AccountResolver::allVisible);
+ return searchImpl(
+ input,
+ searchers,
+ self.get(),
+ this::currentUserCanSeePredicate,
+ AccountResolver::allVisible);
+ }
+
+ public Result resolveIncludeInactiveIgnoreVisibility(String input)
+ throws ConfigInvalidException, IOException {
+ return searchImpl(
+ input, searchers, self.get(), this::allVisiblePredicate, AccountResolver::allVisible);
}
public Result resolveIgnoreVisibility(String input) throws ConfigInvalidException, IOException {
- return searchImpl(input, searchers, this::allVisiblePredicate, AccountResolver::isActive);
+ return searchImpl(
+ input, searchers, self.get(), this::allVisiblePredicate, AccountResolver::isActive);
}
- public Result resolveIgnoreVisibility(
- String input, Predicate<AccountState> accountActivityPredicate)
+ public Result resolveAsUserIgnoreVisibility(CurrentUser asUser, String input)
throws ConfigInvalidException, IOException {
- return searchImpl(input, searchers, this::allVisiblePredicate, accountActivityPredicate);
+ return resolveAsUserIgnoreVisibility(asUser, input, AccountResolver::isActive);
+ }
+
+ public Result resolveAsUserIgnoreVisibility(
+ CurrentUser asUser, String input, Predicate<AccountState> accountActivityPredicate)
+ throws ConfigInvalidException, IOException {
+ return searchImpl(
+ input, searchers, asUser, this::allVisiblePredicate, accountActivityPredicate);
}
/**
@@ -595,7 +768,11 @@
@Deprecated
public Result resolveByNameOrEmail(String input) throws ConfigInvalidException, IOException {
return searchImpl(
- input, nameOrEmailSearchers, this::canSeePredicate, AccountResolver::isActive);
+ input,
+ nameOrEmailSearchers,
+ self.get(),
+ this::currentUserCanSeePredicate,
+ AccountResolver::isActive);
}
/**
@@ -614,16 +791,26 @@
return searchImpl(
input,
ImmutableList.of(new ByNameAndEmail(), new ByEmail(), new ByFullName(), new ByUsername()),
- this::canSeePredicate,
+ self.get(),
+ this::currentUserCanSeePredicate,
AccountResolver::isActive);
}
- private Predicate<AccountState> canSeePredicate() {
- return this::canSee;
+ private Predicate<AccountState> currentUserCanSeePredicate() {
+ return accountControlFactory.get()::canSee;
}
- private boolean canSee(AccountState accountState) {
- return accountControlFactory.get().canSee(accountState);
+ private class ProvidedUserCanSeePredicate implements Supplier<Predicate<AccountState>> {
+ CurrentUser asUser;
+
+ ProvidedUserCanSeePredicate(CurrentUser asUser) {
+ this.asUser = asUser;
+ }
+
+ @Override
+ public Predicate<AccountState> get() {
+ return accountControlFactory.get(asUser)::canSee;
+ }
}
private Predicate<AccountState> allVisiblePredicate() {
@@ -643,22 +830,24 @@
Result searchImpl(
String input,
ImmutableList<Searcher<?>> searchers,
+ CurrentUser asUser,
Supplier<Predicate<AccountState>> visibilitySupplier,
Predicate<AccountState> accountActivityPredicate)
throws ConfigInvalidException, IOException {
+ requireNonNull(asUser);
visibilitySupplier = Suppliers.memoize(visibilitySupplier::get);
List<AccountState> inactive = new ArrayList<>();
for (Searcher<?> searcher : searchers) {
- Optional<Stream<AccountState>> maybeResults = searcher.trySearch(input);
+ Optional<Stream<AccountState>> maybeResults = searcher.trySearch(input, asUser);
if (!maybeResults.isPresent()) {
continue;
}
Stream<AccountState> results = maybeResults.get();
- if (!searcher.callerMayAssumeCandidatesAreVisible()) {
- results = results.filter(visibilitySupplier.get());
- }
+ // Filter out non-visible results, except if it's the BySelf searcher. Since users can always
+ // see themselves checking the visibility is not needed for the BySelf searcher.
+ results = searcher instanceof BySelf ? results : results.filter(visibilitySupplier.get());
List<AccountState> list;
if (searcher.callerShouldFilterOutInactiveCandidates()) {
@@ -672,22 +861,25 @@
}
if (!list.isEmpty()) {
- return createResult(input, list);
+ return createResult(input, list, asUser);
}
if (searcher.shortCircuitIfNoResults()) {
// For a short-circuiting searcher, return results even if empty.
- return !inactive.isEmpty() ? emptyResult(input, inactive) : createResult(input, list);
+ return !inactive.isEmpty()
+ ? emptyResult(input, inactive, asUser)
+ : createResult(input, list, asUser);
}
}
- return emptyResult(input, inactive);
+ return emptyResult(input, inactive, asUser);
}
- private Result createResult(String input, List<AccountState> list) {
- return new Result(input, list, ImmutableList.of());
+ private Result createResult(String input, List<AccountState> list, CurrentUser searchedAsUser) {
+ return new Result(input, list, ImmutableList.of(), searchedAsUser);
}
- private Result emptyResult(String input, List<AccountState> inactive) {
- return new Result(input, ImmutableList.of(), inactive);
+ private Result emptyResult(
+ String input, List<AccountState> inactive, CurrentUser searchedAsUser) {
+ return new Result(input, ImmutableList.of(), inactive, searchedAsUser);
}
private Stream<AccountState> toAccountStates(Set<Account.Id> ids) {
diff --git a/java/com/google/gerrit/server/account/AccountsUpdate.java b/java/com/google/gerrit/server/account/AccountsUpdate.java
index 8d5fea4..b706bca 100644
--- a/java/com/google/gerrit/server/account/AccountsUpdate.java
+++ b/java/com/google/gerrit/server/account/AccountsUpdate.java
@@ -16,6 +16,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
+import static com.google.gerrit.server.update.context.RefUpdateContext.RefUpdateType.ACCOUNTS_UPDATE;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
@@ -25,6 +26,7 @@
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.exceptions.DuplicateKeyException;
import com.google.gerrit.exceptions.StorageException;
@@ -45,6 +47,7 @@
import com.google.gerrit.server.notedb.Sequences;
import com.google.gerrit.server.update.RetryHelper;
import com.google.gerrit.server.update.RetryableAction.Action;
+import com.google.gerrit.server.update.context.RefUpdateContext;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -199,10 +202,9 @@
private final Runnable beforeCommit;
/** Single instance that accumulates updates from the batch. */
- private ExternalIdNotes externalIdNotes;
+ @Nullable private ExternalIdNotes externalIdNotes;
@AssistedInject
- @SuppressWarnings("BindingAnnotationWithoutInject")
AccountsUpdate(
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
@@ -228,7 +230,6 @@
}
@AssistedInject
- @SuppressWarnings("BindingAnnotationWithoutInject")
AccountsUpdate(
GitRepositoryManager repoManager,
GitReferenceUpdated gitRefUpdated,
@@ -402,13 +403,17 @@
delta.getDeletedExternalIds()),
updateArguments.accountId);
- if (externalIdNotes == null) {
- externalIdNotes =
- extIdNotesLoader.load(
- repo, accountConfig.getExternalIdsRev().orElse(ObjectId.zeroId()));
+ if (delta.hasExternalIdUpdates()) {
+ // Only load the externalIds if they are going to be updated
+ // This makes e.g. preferences updates faster.
+ if (externalIdNotes == null) {
+ externalIdNotes =
+ extIdNotesLoader.load(
+ repo, accountConfig.getExternalIdsRev().orElse(ObjectId.zeroId()));
+ }
+ externalIdNotes.replace(delta.getDeletedExternalIds(), delta.getCreatedExternalIds());
+ externalIdNotes.upsert(delta.getUpdatedExternalIds());
}
- externalIdNotes.replace(delta.getDeletedExternalIds(), delta.getCreatedExternalIds());
- externalIdNotes.upsert(delta.getUpdatedExternalIds());
CachedPreferences cachedDefaultPreferences =
CachedPreferences.fromConfig(VersionedDefaultPreferences.get(repo, allUsersName));
@@ -445,28 +450,32 @@
private ImmutableList<Optional<AccountState>> execute(List<ExecutableUpdate> executableUpdates)
throws IOException, ConfigInvalidException {
- List<Optional<AccountState>> accountState = new ArrayList<>();
- List<UpdatedAccount> updatedAccounts = new ArrayList<>();
- executeWithRetry(
- () -> {
- // Reset state for retry.
- externalIdNotes = null;
- accountState.clear();
- updatedAccounts.clear();
+ try (RefUpdateContext ctx = RefUpdateContext.open(ACCOUNTS_UPDATE)) {
+ List<Optional<AccountState>> accountState = new ArrayList<>();
+ List<UpdatedAccount> updatedAccounts = new ArrayList<>();
+ executeWithRetry(
+ () -> {
- try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
- for (ExecutableUpdate executableUpdate : executableUpdates) {
- updatedAccounts.add(executableUpdate.execute(allUsersRepo));
+ // Reset state for retry.
+ externalIdNotes = null;
+ accountState.clear();
+ updatedAccounts.clear();
+ try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
+ for (ExecutableUpdate executableUpdate : executableUpdates) {
+ updatedAccounts.add(executableUpdate.execute(allUsersRepo));
+ }
+ commit(
+ allUsersRepo,
+ updatedAccounts.stream().filter(Objects::nonNull).collect(toList()));
+ for (UpdatedAccount ua : updatedAccounts) {
+ accountState.add(ua == null ? Optional.empty() : ua.getAccountState());
+ }
}
- commit(
- allUsersRepo, updatedAccounts.stream().filter(Objects::nonNull).collect(toList()));
- for (UpdatedAccount ua : updatedAccounts) {
- accountState.add(ua == null ? Optional.empty() : ua.getAccountState());
- }
- }
- return null;
- });
- return ImmutableList.copyOf(accountState);
+ return null;
+ });
+
+ return ImmutableList.copyOf(accountState);
+ }
}
private void executeWithRetry(Action<Void> action) throws IOException, ConfigInvalidException {
@@ -505,17 +514,22 @@
beforeCommit.run();
BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
-
- String externalIdUpdateMessage =
- updatedAccounts.size() == 1
- ? Iterables.getOnlyElement(updatedAccounts).message
- : "Batch update for " + updatedAccounts.size() + " accounts";
- ObjectId oldExternalIdsRevision = externalIdNotes.getRevision();
- // These update the same ref, so they need to be stacked on top of one another using the same
- // ExternalIdNotes instance.
- RevCommit revCommit =
- commitExternalIdUpdates(externalIdUpdateMessage, allUsersRepo, batchRefUpdate);
- boolean externalIdsUpdated = !Objects.equals(revCommit.getId(), oldExternalIdsRevision);
+ // External ids may be not updated if:
+ // * externalIdNotes is not loaded (there were no externalId updates in the delta)
+ // * new revCommit is identical to the previous externalId tip
+ boolean externalIdsUpdated = false;
+ if (externalIdNotes != null) {
+ String externalIdUpdateMessage =
+ updatedAccounts.size() == 1
+ ? Iterables.getOnlyElement(updatedAccounts).message
+ : "Batch update for " + updatedAccounts.size() + " accounts";
+ ObjectId oldExternalIdsRevision = externalIdNotes.getRevision();
+ // These update the same ref, so they need to be stacked on top of one another using the same
+ // ExternalIdNotes instance.
+ RevCommit revCommit =
+ commitExternalIdUpdates(externalIdUpdateMessage, allUsersRepo, batchRefUpdate);
+ externalIdsUpdated = !Objects.equals(revCommit.getId(), oldExternalIdsRevision);
+ }
for (UpdatedAccount updatedAccount : updatedAccounts) {
// These updates are all for different refs (because batches never update the same account
@@ -540,8 +554,10 @@
RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
Set<Account.Id> accountsToSkipForReindex = getUpdatedAccountIds(batchRefUpdate);
- extIdNotesLoader.updateExternalIdCacheAndMaybeReindexAccounts(
- externalIdNotes, accountsToSkipForReindex);
+ if (externalIdsUpdated) {
+ extIdNotesLoader.updateExternalIdCacheAndMaybeReindexAccounts(
+ externalIdNotes, accountsToSkipForReindex);
+ }
gitRefUpdated.fire(
allUsersName, batchRefUpdate, currentUser.map(IdentifiedUser::state).orElse(null));
diff --git a/java/com/google/gerrit/server/account/AuthRequest.java b/java/com/google/gerrit/server/account/AuthRequest.java
index cceda70..cf1e552 100644
--- a/java/com/google/gerrit/server/account/AuthRequest.java
+++ b/java/com/google/gerrit/server/account/AuthRequest.java
@@ -16,6 +16,7 @@
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_EXTERNAL;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GERRIT;
+import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GOOGLE_OAUTH;
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_MAILTO;
import com.google.common.base.Strings;
@@ -66,6 +67,14 @@
return r;
}
+ public AuthRequest createForOAuthUser(String userName) {
+ AuthRequest r =
+ new AuthRequest(
+ externalIdKeyFactory.create(SCHEME_GOOGLE_OAUTH, userName), externalIdKeyFactory);
+ r.setUserName(userName);
+ return r;
+ }
+
/**
* Create a request for an email address registration.
*
@@ -102,6 +111,7 @@
return externalId;
}
+ @Nullable
public String getLocalUser() {
if (externalId.isScheme(SCHEME_GERRIT)) {
return externalId.id();
diff --git a/java/com/google/gerrit/server/account/CreateGroupArgs.java b/java/com/google/gerrit/server/account/CreateGroupArgs.java
index ba58c3f..9d9fe9d 100644
--- a/java/com/google/gerrit/server/account/CreateGroupArgs.java
+++ b/java/com/google/gerrit/server/account/CreateGroupArgs.java
@@ -14,6 +14,7 @@
package com.google.gerrit.server.account;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AccountGroup;
import java.util.Collection;
@@ -30,6 +31,7 @@
return groupName;
}
+ @Nullable
public String getGroupName() {
return groupName != null ? groupName.get() : null;
}
diff --git a/java/com/google/gerrit/server/account/DefaultRealm.java b/java/com/google/gerrit/server/account/DefaultRealm.java
index 329825f..cfffceb 100644
--- a/java/com/google/gerrit/server/account/DefaultRealm.java
+++ b/java/com/google/gerrit/server/account/DefaultRealm.java
@@ -16,6 +16,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.client.AccountFieldName;
@@ -79,6 +80,7 @@
@Override
public void onCreateAccount(AuthRequest who, Account account) {}
+ @Nullable
@Override
public Account.Id lookup(String accountName) throws IOException {
if (emailExpander.canExpand(accountName)) {
diff --git a/java/com/google/gerrit/server/account/DestinationList.java b/java/com/google/gerrit/server/account/DestinationList.java
index 15c1e25..084a3ac 100644
--- a/java/com/google/gerrit/server/account/DestinationList.java
+++ b/java/com/google/gerrit/server/account/DestinationList.java
@@ -18,6 +18,7 @@
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.server.git.ValidationError;
@@ -39,6 +40,7 @@
destinations.replaceValues(label, toSet(parse(text, DIR_NAME + label, TRIM, null, errors)));
}
+ @Nullable
String asText(String label) {
Set<BranchNameKey> dests = destinations.get(label);
if (dests == null) {
diff --git a/java/com/google/gerrit/server/account/Emails.java b/java/com/google/gerrit/server/account/Emails.java
index 8c3f033..13385d0 100644
--- a/java/com/google/gerrit/server/account/Emails.java
+++ b/java/com/google/gerrit/server/account/Emails.java
@@ -57,12 +57,11 @@
* are needed it is more efficient to use {@link #getAccountsFor(String...)} as this method reads
* the SHA1 of the refs/meta/external-ids branch only once (and not once per email).
*
- * <p>In addition accounts are included that have the given email as preferred email even if they
- * have no external ID for the preferred email. Having accounts with a preferred email that does
- * not exist as external ID is an inconsistency, but existing functionality relies on still
- * getting those accounts, which is why they are included. Accounts by preferred email are fetched
- * from the account index as a fallback for email addresses that could not be resolved using
- * {@link ExternalIds}.
+ * <p>If there is no account that owns the email via an external ID all accounts that have the
+ * email set as a preferred email are returned. Having accounts with a preferred email that does
+ * not exist as external ID is an inconsistency, but existing functionality relies on getting
+ * those accounts, which is why they are returned as a fall-back by fetching them from the account
+ * index.
*
* @see #getAccountsFor(String...)
*/
diff --git a/java/com/google/gerrit/server/account/GroupCache.java b/java/com/google/gerrit/server/account/GroupCache.java
index 1e28d7d..46c730c 100644
--- a/java/com/google/gerrit/server/account/GroupCache.java
+++ b/java/com/google/gerrit/server/account/GroupCache.java
@@ -14,11 +14,15 @@
package com.google.gerrit.server.account;
+import com.google.gerrit.common.UsedAt;
+import com.google.gerrit.common.UsedAt.Project;
import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.entities.InternalGroup;
+import com.google.gerrit.exceptions.StorageException;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
+import org.eclipse.jgit.lib.ObjectId;
/** Tracks group objects in memory for efficient access. */
public interface GroupCache {
@@ -62,6 +66,22 @@
Map<AccountGroup.UUID, InternalGroup> get(Collection<AccountGroup.UUID> groupUuids);
/**
+ * Returns an {@code InternalGroup} instance for the given {@code AccountGroup.UUID} at the given
+ * {@code metaId} of {@link com.google.gerrit.entities.RefNames#refsGroups} ref.
+ *
+ * <p>The caller is responsible to ensure the presence of {@code metaId} and the corresponding
+ * meta ref.
+ *
+ * @param groupUuid the UUID of the internal group
+ * @param metaId the sha1 of commit in {@link com.google.gerrit.entities.RefNames#refsGroups} ref.
+ * @return the internal group at specific sha1 {@code metaId}
+ * @throws StorageException if no internal group with this UUID exists on this server at the
+ * specific sha1, or if an error occurred during lookup.
+ */
+ @UsedAt(Project.GOOGLE)
+ InternalGroup getFromMetaId(AccountGroup.UUID groupUuid, ObjectId metaId) throws StorageException;
+
+ /**
* Removes the association of the given ID with a group.
*
* <p>The next call to {@link #get(AccountGroup.Id)} won't provide a cached value.
diff --git a/java/com/google/gerrit/server/account/GroupCacheImpl.java b/java/com/google/gerrit/server/account/GroupCacheImpl.java
index 36f725f..fac2fd5 100644
--- a/java/com/google/gerrit/server/account/GroupCacheImpl.java
+++ b/java/com/google/gerrit/server/account/GroupCacheImpl.java
@@ -23,9 +23,11 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
+import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.entities.InternalGroup;
import com.google.gerrit.entities.RefNames;
+import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.proto.Protos;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.cache.proto.Cache;
@@ -121,15 +123,19 @@
private final LoadingCache<AccountGroup.Id, Optional<InternalGroup>> byId;
private final LoadingCache<String, Optional<InternalGroup>> byName;
private final LoadingCache<String, Optional<InternalGroup>> byUUID;
+ private final LoadingCache<Cache.GroupKeyProto, InternalGroup> persistedByUuidCache;
@Inject
GroupCacheImpl(
@Named(BYID_NAME) LoadingCache<AccountGroup.Id, Optional<InternalGroup>> byId,
@Named(BYNAME_NAME) LoadingCache<String, Optional<InternalGroup>> byName,
- @Named(BYUUID_NAME) LoadingCache<String, Optional<InternalGroup>> byUUID) {
+ @Named(BYUUID_NAME) LoadingCache<String, Optional<InternalGroup>> byUUID,
+ @Named(BYUUID_NAME_PERSISTED)
+ LoadingCache<Cache.GroupKeyProto, InternalGroup> persistedByUuidCache) {
this.byId = byId;
this.byName = byName;
this.byUUID = byUUID;
+ this.persistedByUuidCache = persistedByUuidCache;
}
@Override
@@ -184,6 +190,21 @@
}
@Override
+ public InternalGroup getFromMetaId(AccountGroup.UUID groupUuid, ObjectId metaId)
+ throws StorageException {
+ Cache.GroupKeyProto key =
+ Cache.GroupKeyProto.newBuilder()
+ .setUuid(groupUuid.get())
+ .setRevision(ObjectIdConverter.create().toByteString(metaId))
+ .build();
+ try {
+ return persistedByUuidCache.get(key);
+ } catch (ExecutionException e) {
+ throw new StorageException(e);
+ }
+ }
+
+ @Override
public void evict(AccountGroup.Id groupId) {
if (groupId != null) {
logger.atFine().log("Evict group %s by ID", groupId.get());
@@ -351,6 +372,7 @@
return Protos.toByteArray(InternalGroupSerializer.serialize(value));
}
+ @Nullable
@Override
public InternalGroup deserialize(byte[] in) {
if (Strings.fromByteArray(in).isEmpty()) {
diff --git a/java/com/google/gerrit/server/account/GroupIncludeCache.java b/java/com/google/gerrit/server/account/GroupIncludeCache.java
index d92d9fc..266f858 100644
--- a/java/com/google/gerrit/server/account/GroupIncludeCache.java
+++ b/java/com/google/gerrit/server/account/GroupIncludeCache.java
@@ -16,7 +16,9 @@
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AccountGroup;
+import com.google.gerrit.entities.AccountGroup.UUID;
import java.util.Collection;
+import java.util.Set;
/** Tracks group inclusions in memory for efficient access. */
public interface GroupIncludeCache {
@@ -37,6 +39,14 @@
*/
Collection<AccountGroup.UUID> parentGroupsOf(AccountGroup.UUID groupId);
+ /**
+ * Returns the parent groups of the provided subgroups.
+ *
+ * @param groupId the UUID of the subgroup
+ * @return the UUIDs of all direct parent groups
+ */
+ Collection<AccountGroup.UUID> parentGroupsOf(Set<UUID> groupId);
+
/** Returns set of any UUIDs that are not internal groups. */
Collection<AccountGroup.UUID> allExternalMembers();
diff --git a/java/com/google/gerrit/server/account/GroupIncludeCacheImpl.java b/java/com/google/gerrit/server/account/GroupIncludeCacheImpl.java
index f203240..fc6087b 100644
--- a/java/com/google/gerrit/server/account/GroupIncludeCacheImpl.java
+++ b/java/com/google/gerrit/server/account/GroupIncludeCacheImpl.java
@@ -22,6 +22,8 @@
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AccountGroup;
@@ -45,6 +47,9 @@
import com.google.inject.name.Named;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
/** Tracks group inclusions in memory for efficient access. */
@@ -70,7 +75,7 @@
cache(
PARENT_GROUPS_NAME,
AccountGroup.UUID.class,
- new TypeLiteral<Immuta