From d44ea94ece35d12097e3899e24d04657979e490a Mon Sep 17 00:00:00 2001 From: Khai Do Date: Wed, 31 Jul 2013 07:45:17 -0700 Subject: [PATCH] Add AnyWithBlock prolog function Add a prolog function 'AnyWithBlock' that will block a submit on the lowest possible negative value. Any other value will enable a submit. Bug: Issue 2042 Change-Id: I56826db2eb63de9ea7150757240ad916f6e9f8a8 --- Documentation/config-labels.txt | 6 ++++++ .../com/google/gerrit/server/git/ProjectConfig.java | 2 +- gerrit-server/src/main/prolog/gerrit_common.pl | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Documentation/config-labels.txt b/Documentation/config-labels.txt index 1ff7e24e6e..7df55fe89e 100644 --- a/Documentation/config-labels.txt +++ b/Documentation/config-labels.txt @@ -203,6 +203,12 @@ the highest possible positive value is required to enable submit. There must be at least one positive value, or else submit will never be enabled. To permit blocking submits, ensure a negative value is defined. +* `AnyWithBlock` ++ +The lowest possible negative value, if present, blocks a submit, Any +other value enables a submit. To permit blocking submits, ensure +that a negative value is defined. + * `MaxNoBlock` + The highest possible positive value is required to enable submit, but diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ProjectConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ProjectConfig.java index b6d50ee31d..5144dcb73e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ProjectConfig.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ProjectConfig.java @@ -128,7 +128,7 @@ public class ProjectConfig extends VersionedMetaData { private static final String KEY_VALUE = "value"; private static final String KEY_CAN_OVERRIDE = "canOverride"; private static final Set LABEL_FUNCTIONS = ImmutableSet.of( - "MaxWithBlock", "MaxNoBlock", "NoBlock", "NoOp"); + "MaxWithBlock", "AnyWithBlock", "MaxNoBlock", "NoBlock", "NoOp"); private static final SubmitType defaultSubmitAction = SubmitType.MERGE_IF_NECESSARY; diff --git a/gerrit-server/src/main/prolog/gerrit_common.pl b/gerrit-server/src/main/prolog/gerrit_common.pl index 71e7383010..4738d15a28 100644 --- a/gerrit-server/src/main/prolog/gerrit_common.pl +++ b/gerrit-server/src/main/prolog/gerrit_common.pl @@ -239,6 +239,7 @@ default_submit([Type | Types], Tmp, Out) :- %% Apply the old -2..+2 style logic. %% legacy_submit_rule('MaxWithBlock', Label, Min, Max, T) :- !, max_with_block(Label, Min, Max, T). +legacy_submit_rule('AnyWithBlock', Label, Min, Max, T) :- !, any_with_block(Label, Min, T). legacy_submit_rule('MaxNoBlock', Label, Min, Max, T) :- !, max_no_block(Label, Max, T). legacy_submit_rule('NoBlock', Label, Min, Max, T) :- !, T = may(_). legacy_submit_rule('NoOp', Label, Min, Max, T) :- !, T = may(_). @@ -267,6 +268,7 @@ max_with_block(Label, Min, Max, ok(Who)) :- max_with_block(Label, Min, Max, need(Max)) :- true . + %TODO Uncomment this clause when group suggesting is possible. %max_with_block(Label, Min, Max, need(Max, Group)) :- % \+ check_label_range_permission(Label, Max, ok(_)), @@ -276,6 +278,16 @@ max_with_block(Label, Min, Max, need(Max)) :- % \+ check_label_range_permission(Label, Max, ask(Group)) % . +%% any_with_block: +%% +%% - The maximum is never used. +%% +any_with_block(Label, Min, reject(Who)) :- + check_label_range_permission(Label, Min, ok(Who)), + ! + . +any_with_block(Label, Min, may(_)). + %% max_no_block: %%