Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 1 | %% Copyright (C) 2011 The Android Open Source Project |
| 2 | %% |
| 3 | %% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | %% you may not use this file except in compliance with the License. |
| 5 | %% You may obtain a copy of the License at |
| 6 | %% |
| 7 | %% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | %% |
| 9 | %% Unless required by applicable law or agreed to in writing, software |
| 10 | %% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | %% See the License for the specific language governing permissions and |
| 13 | %% limitations under the License. |
| 14 | |
Shawn O. Pearce | 6262881 | 2011-06-16 13:56:25 -0700 | [diff] [blame] | 15 | :- package gerrit. |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 16 | '$init' :- init. |
| 17 | |
| 18 | |
| 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 20 | %% |
| 21 | %% init: |
| 22 | %% |
| 23 | %% Initialize the module's private state. These typically take the form of global |
| 24 | %% aliased hashes carrying "constant" data about the current change for any |
| 25 | %% predicate that needs to obtain it. |
| 26 | %% |
| 27 | init :- |
Shawn O. Pearce | d0df169 | 2012-05-02 15:20:07 -0700 | [diff] [blame] | 28 | define_hash(commit_labels). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 29 | |
| 30 | define_hash(A) :- hash_exists(A), !, hash_clear(A). |
| 31 | define_hash(A) :- atom(A), !, new_hash(_, [alias(A)]). |
| 32 | |
| 33 | |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | %% |
| 36 | %% commit_label/2: |
| 37 | %% |
| 38 | %% During rule evaluation of a change, this predicate is defined to |
| 39 | %% be a table of labels that pertain to the commit of interest. |
| 40 | %% |
| 41 | %% commit_label( label('Code-Review', 2), user(12345789) ). |
| 42 | %% commit_label( label('Verified', -1), user(8181) ). |
| 43 | %% |
| 44 | :- public commit_label/2. |
| 45 | %% |
| 46 | commit_label(L, User) :- L = label(H, _), |
| 47 | atom(H), |
| 48 | !, |
| 49 | hash_get(commit_labels, H, Cached), |
| 50 | ( [] == Cached -> |
| 51 | get_commit_labels(_), |
| 52 | hash_get(commit_labels, H, Rs), ! |
| 53 | ; |
| 54 | Rs = Cached |
| 55 | ), |
| 56 | scan_commit_labels(Rs, L, User) |
| 57 | . |
| 58 | commit_label(Label, User) :- |
| 59 | get_commit_labels(Rs), |
| 60 | scan_commit_labels(Rs, Label, User). |
| 61 | |
| 62 | scan_commit_labels([R | Rs], L, U) :- R = commit_label(L, U). |
| 63 | scan_commit_labels([_ | Rs], L, U) :- scan_commit_labels(Rs, L, U). |
| 64 | scan_commit_labels([], _, _) :- fail. |
| 65 | |
| 66 | get_commit_labels(Rs) :- |
| 67 | hash_contains_key(commit_labels, '$all'), |
| 68 | !, |
| 69 | hash_get(commit_labels, '$all', Rs) |
| 70 | . |
| 71 | get_commit_labels(Rs) :- |
Dave Borowitz | 808ee99 | 2012-01-18 15:36:23 -0800 | [diff] [blame] | 72 | '_load_commit_labels'(Rs), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 73 | set_commit_labels(Rs). |
| 74 | |
| 75 | set_commit_labels(Rs) :- |
| 76 | define_hash(commit_labels), |
| 77 | hash_put(commit_labels, '$all', Rs), |
| 78 | index_commit_labels(Rs). |
| 79 | |
| 80 | index_commit_labels([]). |
| 81 | index_commit_labels([R | Rs]) :- |
| 82 | R = commit_label(label(H, _), _), |
| 83 | atom(H), |
| 84 | !, |
| 85 | hash_get(commit_labels, H, Tmp), |
| 86 | hash_put(commit_labels, H, [R | Tmp]), |
| 87 | index_commit_labels(Rs) |
| 88 | . |
| 89 | index_commit_labels([_ | Rs]) :- |
| 90 | index_commit_labels(Rs). |
| 91 | |
| 92 | |
| 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 94 | %% |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 95 | %% not_same/2: |
| 96 | %% |
| 97 | :- public not_same/2. |
| 98 | %% |
| 99 | not_same(ok(A), ok(B)) :- !, A \= B. |
| 100 | not_same(label(_, ok(A)), label(_, ok(B))) :- !, A \= B. |
| 101 | not_same(_, _). |
| 102 | |
| 103 | |
| 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 105 | %% |
| 106 | %% can_submit/2: |
| 107 | %% |
Jason Tsay | f93796c | 2011-06-09 16:17:01 -0700 | [diff] [blame] | 108 | %% Executes the SubmitRule for each solution until one where all of the |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 109 | %% states has the format label(_, ok(_)) is found, then cut away any |
| 110 | %% remaining choice points leaving this as the last solution. |
| 111 | %% |
| 112 | :- public can_submit/2. |
| 113 | %% |
| 114 | can_submit(SubmitRule, S) :- |
Sasa Zivkov | 680a5f8 | 2012-08-13 10:46:08 +0200 | [diff] [blame] | 115 | call_rule(SubmitRule, Tmp), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 116 | Tmp =.. [submit | Ls], |
| 117 | ( is_all_ok(Ls) -> S = ok(Tmp), ! ; S = not_ready(Tmp) ). |
| 118 | |
Sasa Zivkov | 680a5f8 | 2012-08-13 10:46:08 +0200 | [diff] [blame] | 119 | call_rule(P:X, Arg) :- !, F =.. [X, Arg], P:F. |
| 120 | call_rule(X, Arg) :- !, F =.. [X, Arg], F. |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 121 | |
| 122 | is_all_ok([]). |
| 123 | is_all_ok([label(_, ok(__)) | Ls]) :- is_all_ok(Ls). |
Magnus Bäck | a6ce960 | 2012-05-10 11:33:47 -0700 | [diff] [blame] | 124 | is_all_ok([label(_, may(__)) | Ls]) :- is_all_ok(Ls). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 125 | is_all_ok(_) :- fail. |
| 126 | |
| 127 | |
| 128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 129 | %% |
Sasa Zivkov | 3531ca4 | 2012-10-10 14:05:03 +0200 | [diff] [blame] | 130 | %% locate_helper |
| 131 | %% |
| 132 | %% Returns user:Func if it exists otherwise returns gerrit:Default |
| 133 | |
| 134 | locate_helper(Func, Default, Arity, user:Func) :- |
| 135 | '$compiled_predicate'(user, Func, Arity), !. |
| 136 | locate_helper(Func, Default, Arity, user:Func) :- |
| 137 | listN(Arity, P), C =.. [Func | P], clause(user:C, _), !. |
| 138 | locate_helper(Func, Default, _, gerrit:Default). |
| 139 | |
| 140 | listN(0, []). |
| 141 | listN(N, [_|T]) :- N > 0, N1 is N - 1, listN(N1, T). |
| 142 | |
| 143 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 144 | %% |
Jason Tsay | f93796c | 2011-06-09 16:17:01 -0700 | [diff] [blame] | 145 | %% locate_submit_rule/1: |
| 146 | %% |
| 147 | %% Finds a submit_rule depending on what rules are available. |
| 148 | %% If none are available, use default_submit/1. |
| 149 | %% |
| 150 | :- public locate_submit_rule/1. |
| 151 | %% |
| 152 | |
| 153 | locate_submit_rule(RuleName) :- |
Sasa Zivkov | 3531ca4 | 2012-10-10 14:05:03 +0200 | [diff] [blame] | 154 | locate_helper(submit_rule, default_submit, 1, RuleName). |
Jason Tsay | f93796c | 2011-06-09 16:17:01 -0700 | [diff] [blame] | 155 | |
| 156 | |
| 157 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 158 | %% |
Sasa Zivkov | 680a5f8 | 2012-08-13 10:46:08 +0200 | [diff] [blame] | 159 | %% get_submit_type/2: |
| 160 | %% |
| 161 | %% Executes the SubmitTypeRule and return the first solution |
| 162 | %% |
| 163 | :- public get_submit_type/2. |
| 164 | %% |
| 165 | get_submit_type(SubmitTypeRule, A) :- |
| 166 | call_rule(SubmitTypeRule, A), !. |
| 167 | |
| 168 | |
| 169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 170 | %% |
| 171 | %% locate_submit_type/1: |
| 172 | %% |
| 173 | %% Finds a submit_type_rule depending on what rules are available. |
| 174 | %% If none are available, use project_default_submit_type/1. |
| 175 | %% |
| 176 | :- public locate_submit_type/1. |
| 177 | %% |
| 178 | locate_submit_type(RuleName) :- |
| 179 | locate_helper(submit_type, project_default_submit_type, 1, RuleName). |
| 180 | |
| 181 | |
| 182 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 183 | %% |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 184 | %% default_submit/1: |
| 185 | %% |
| 186 | :- public default_submit/1. |
| 187 | %% |
| 188 | default_submit(P) :- |
Dave Borowitz | 03fbaf8 | 2013-02-15 17:34:31 -0800 | [diff] [blame] | 189 | get_legacy_label_types(LabelTypes), |
| 190 | default_submit(LabelTypes, P). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 191 | |
| 192 | % Apply the old "all approval categories must be satisfied" |
Dave Borowitz | 03fbaf8 | 2013-02-15 17:34:31 -0800 | [diff] [blame] | 193 | % loop by scanning over all of the label types to build up the |
| 194 | % submit record. |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 195 | % |
Dave Borowitz | 03fbaf8 | 2013-02-15 17:34:31 -0800 | [diff] [blame] | 196 | default_submit(LabelTypes, P) :- |
| 197 | default_submit(LabelTypes, [], Tmp), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 198 | reverse(Tmp, Ls), |
| 199 | P =.. [ submit | Ls]. |
| 200 | |
| 201 | default_submit([], Out, Out). |
| 202 | default_submit([Type | Types], Tmp, Out) :- |
Dave Borowitz | 8e5de82 | 2013-02-18 14:53:57 -0800 | [diff] [blame] | 203 | label_type(Label, Fun, Min, Max) = Type, |
| 204 | legacy_submit_rule(Fun, Label, Min, Max, Status), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 205 | R = label(Label, Status), |
| 206 | default_submit(Types, [R | Tmp], Out). |
| 207 | |
| 208 | |
| 209 | %% legacy_submit_rule: |
| 210 | %% |
| 211 | %% Apply the old -2..+2 style logic. |
| 212 | %% |
Dave Borowitz | 8e5de82 | 2013-02-18 14:53:57 -0800 | [diff] [blame] | 213 | legacy_submit_rule('MaxWithBlock', Label, Min, Max, T) :- !, max_with_block(Label, Min, Max, T). |
Khai Do | d44ea94 | 2013-07-31 07:45:17 -0700 | [diff] [blame] | 214 | legacy_submit_rule('AnyWithBlock', Label, Min, Max, T) :- !, any_with_block(Label, Min, T). |
Dave Borowitz | 8e5de82 | 2013-02-18 14:53:57 -0800 | [diff] [blame] | 215 | legacy_submit_rule('MaxNoBlock', Label, Min, Max, T) :- !, max_no_block(Label, Max, T). |
| 216 | legacy_submit_rule('NoBlock', Label, Min, Max, T) :- !, T = may(_). |
| 217 | legacy_submit_rule('NoOp', Label, Min, Max, T) :- !, T = may(_). |
Nasser Grainawi | 240ea29 | 2015-11-09 09:56:56 -0800 | [diff] [blame] | 218 | legacy_submit_rule('PatchSetLock', Label, Min, Max, T) :- !, T = may(_). |
Dave Borowitz | 8e5de82 | 2013-02-18 14:53:57 -0800 | [diff] [blame] | 219 | legacy_submit_rule(Fun, Label, Min, Max, T) :- T = impossible(unsupported(Fun)). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 220 | |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 221 | %% max_with_block: |
| 222 | %% |
| 223 | %% - The minimum is never used. |
| 224 | %% - At least one maximum is used. |
| 225 | %% |
Shawn O. Pearce | 849a0a5 | 2011-06-20 17:39:07 -0700 | [diff] [blame] | 226 | :- public max_with_block/4. |
| 227 | %% |
Sasa Zivkov | c73ea62 | 2013-01-30 13:56:15 +0100 | [diff] [blame] | 228 | max_with_block(Min, Max, Label, label(Label, S)) :- |
| 229 | number(Min), number(Max), atom(Label), |
| 230 | !, |
| 231 | max_with_block(Label, Min, Max, S). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 232 | max_with_block(Label, Min, Max, reject(Who)) :- |
Changcheng Xiao | 6071c4e | 2017-07-21 16:10:23 +0200 | [diff] [blame] | 233 | commit_label(label(Label, Min), Who), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 234 | ! |
| 235 | . |
| 236 | max_with_block(Label, Min, Max, ok(Who)) :- |
Changcheng Xiao | 6071c4e | 2017-07-21 16:10:23 +0200 | [diff] [blame] | 237 | \+ commit_label(label(Label, Min), _), |
| 238 | commit_label(label(Label, Max), Who), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 239 | ! |
| 240 | . |
| 241 | max_with_block(Label, Min, Max, need(Max)) :- |
| 242 | true |
| 243 | . |
Khai Do | d44ea94 | 2013-07-31 07:45:17 -0700 | [diff] [blame] | 244 | |
Khai Do | d44ea94 | 2013-07-31 07:45:17 -0700 | [diff] [blame] | 245 | %% any_with_block: |
| 246 | %% |
| 247 | %% - The maximum is never used. |
| 248 | %% |
| 249 | any_with_block(Label, Min, reject(Who)) :- |
Simon Hwang | d7fa6e38 | 2015-09-17 16:26:46 -0400 | [diff] [blame] | 250 | Min < 0, |
Changcheng Xiao | 6071c4e | 2017-07-21 16:10:23 +0200 | [diff] [blame] | 251 | commit_label(label(Label, Min), Who), |
Khai Do | d44ea94 | 2013-07-31 07:45:17 -0700 | [diff] [blame] | 252 | ! |
| 253 | . |
| 254 | any_with_block(Label, Min, may(_)). |
| 255 | |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 256 | |
| 257 | %% max_no_block: |
| 258 | %% |
| 259 | %% - At least one maximum is used. |
| 260 | %% |
Nasser Grainawi | ca444d0 | 2015-11-12 18:38:29 -0800 | [diff] [blame] | 261 | max_no_block(Max, Label, label(Label, S)) :- |
| 262 | number(Max), atom(Label), |
| 263 | !, |
| 264 | max_no_block(Label, Max, S). |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 265 | max_no_block(Label, Max, ok(Who)) :- |
Changcheng Xiao | 6071c4e | 2017-07-21 16:10:23 +0200 | [diff] [blame] | 266 | commit_label(label(Label, Max), Who), |
Shawn O. Pearce | 9f25352 | 2011-06-06 13:49:06 -0700 | [diff] [blame] | 267 | ! |
| 268 | . |
| 269 | max_no_block(Label, Max, need(Max)) :- |
| 270 | true |
| 271 | . |
Jason Tsay | 6c6700f | 2011-06-21 13:25:52 -0700 | [diff] [blame] | 272 | |
Jason Tsay | 82c088e | 2011-06-30 15:42:37 -0700 | [diff] [blame] | 273 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 274 | %% |
| 275 | %% filter_submit_results/3: |
| 276 | %% |
| 277 | %% Executes the submit_filter against the given list of results, |
| 278 | %% returns a list of filtered results. |
| 279 | %% |
| 280 | :- public filter_submit_results/3. |
| 281 | %% |
| 282 | filter_submit_results(Filter, In, Out) :- |
| 283 | filter_submit_results(Filter, In, [], Tmp), |
| 284 | reverse(Tmp, Out). |
| 285 | filter_submit_results(Filter, [I | In], Tmp, Out) :- |
| 286 | arg(1, I, R), |
| 287 | call_submit_filter(Filter, R, S), |
| 288 | !, |
| 289 | S =.. [submit | Ls], |
| 290 | ( is_all_ok(Ls) -> T = ok(S) ; T = not_ready(S) ), |
| 291 | filter_submit_results(Filter, In, [T | Tmp], Out). |
| 292 | filter_submit_results(Filter, [_ | In], Tmp, Out) :- |
Gustaf Lundh | 7020947 | 2014-12-18 16:05:30 +0100 | [diff] [blame] | 293 | filter_submit_results(Filter, In, Tmp, Out), |
Jason Tsay | 82c088e | 2011-06-30 15:42:37 -0700 | [diff] [blame] | 294 | ! |
| 295 | . |
| 296 | filter_submit_results(Filter, [], Out, Out). |
| 297 | |
| 298 | call_submit_filter(P:X, R, S) :- !, F =.. [X, R, S], P:F. |
| 299 | call_submit_filter(X, R, S) :- F =.. [X, R, S], F. |
| 300 | |
Sasa Zivkov | 680a5f8 | 2012-08-13 10:46:08 +0200 | [diff] [blame] | 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | %% |
| 303 | %% filter_submit_type_results/3: |
| 304 | %% |
| 305 | %% Executes the submit_type_filter against the result, |
| 306 | %% returns the filtered result. |
| 307 | %% |
| 308 | :- public filter_submit_type_results/3. |
| 309 | %% |
| 310 | filter_submit_type_results(Filter, In, Out) :- call_submit_filter(Filter, In, Out). |
| 311 | |
Jason Tsay | 82c088e | 2011-06-30 15:42:37 -0700 | [diff] [blame] | 312 | |
| 313 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 314 | %% |
| 315 | %% locate_submit_filter/1: |
| 316 | %% |
| 317 | %% Finds a submit_filter if available. |
| 318 | %% |
| 319 | :- public locate_submit_filter/1. |
| 320 | %% |
| 321 | locate_submit_filter(FilterName) :- |
Sasa Zivkov | 3531ca4 | 2012-10-10 14:05:03 +0200 | [diff] [blame] | 322 | locate_helper(submit_filter, noop_filter, 2, FilterName). |
| 323 | |
| 324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 325 | %% |
| 326 | %% noop_filter/2: |
| 327 | %% |
| 328 | :- public noop_filter/2. |
| 329 | %% |
| 330 | noop_filter(In, In). |
Jason Tsay | 82c088e | 2011-06-30 15:42:37 -0700 | [diff] [blame] | 331 | |
Sasa Zivkov | 680a5f8 | 2012-08-13 10:46:08 +0200 | [diff] [blame] | 332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 333 | %% |
| 334 | %% locate_submit_type_filter/1: |
| 335 | %% |
| 336 | %% Finds a submit_type_filter if available. |
| 337 | %% |
| 338 | :- public locate_submit_type_filter/1. |
| 339 | %% |
| 340 | locate_submit_type_filter(FilterName) :- |
| 341 | locate_helper(submit_type_filter, noop_filter, 2, FilterName). |
Jason Tsay | 82c088e | 2011-06-30 15:42:37 -0700 | [diff] [blame] | 342 | |
| 343 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 344 | %% |
| 345 | %% find_label/3: |
| 346 | %% |
| 347 | %% Finds labels successively and fails when there are no more results. |
| 348 | %% |
| 349 | :- public find_label/3. |
| 350 | %% |
| 351 | find_label([], _, _) :- !, fail. |
| 352 | find_label(List, Name, Label) :- |
| 353 | List = [_ | _], |
| 354 | !, |
| 355 | find_label2(List, Name, Label). |
| 356 | find_label(S, Name, Label) :- |
| 357 | S =.. [submit | Ls], |
| 358 | find_label2(Ls, Name, Label). |
| 359 | |
| 360 | find_label2([L | _ ], Name, L) :- L = label(Name, _). |
| 361 | find_label2([_ | Ls], Name, L) :- find_label2(Ls, Name, L). |
| 362 | |
| 363 | |
| 364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 365 | %% |
| 366 | %% remove_label/3: |
| 367 | %% |
| 368 | %% Removes all occurances of label(Name, Status). |
| 369 | %% |
| 370 | :- public remove_label/3. |
| 371 | %% |
| 372 | remove_label([], _, []) :- !. |
| 373 | remove_label(List, Label, Out) :- |
| 374 | List = [_ | _], |
| 375 | !, |
| 376 | subtract1(List, Label, Out). |
| 377 | remove_label(S, Label, Out) :- |
| 378 | S =.. [submit | Ls], |
| 379 | subtract1(Ls, Label, Tmp), |
| 380 | Out =.. [submit | Tmp]. |
| 381 | |
| 382 | subtract1([], _, []) :- !. |
| 383 | subtract1([E | L], E, R) :- !, subtract1(L, E, R). |
| 384 | subtract1([H | L], E, [H | R]) :- subtract1(L, E, R). |
| 385 | |
| 386 | |
Jason Tsay | 6c6700f | 2011-06-21 13:25:52 -0700 | [diff] [blame] | 387 | %% commit_author/1: |
| 388 | %% |
| 389 | :- public commit_author/1. |
| 390 | %% |
| 391 | commit_author(Author) :- |
| 392 | commit_author(Author, _, _). |
| 393 | |
| 394 | |
| 395 | %% commit_committer/1: |
| 396 | %% |
| 397 | :- public commit_committer/1. |
| 398 | %% |
| 399 | commit_committer(Committer) :- |
| 400 | commit_committer(Committer, _, _). |
Jason Tsay | 93f4de9 | 2011-06-27 11:25:07 -0700 | [diff] [blame] | 401 | |
| 402 | |
| 403 | %% commit_delta/1: |
| 404 | %% |
| 405 | :- public commit_delta/1. |
| 406 | %% |
| 407 | commit_delta(Regex) :- |
| 408 | once(commit_delta(Regex, _, _, _)). |
| 409 | |
| 410 | |
| 411 | %% commit_delta/3: |
| 412 | %% |
| 413 | :- public commit_delta/3. |
| 414 | %% |
| 415 | commit_delta(Regex, Type, Path) :- |
| 416 | commit_delta(Regex, TmpType, NewPath, OldPath), |
| 417 | split_commit_delta(TmpType, NewPath, OldPath, Type, Path). |
| 418 | |
| 419 | split_commit_delta(rename, NewPath, OldPath, delete, OldPath). |
| 420 | split_commit_delta(rename, NewPath, OldPath, add, NewPath) :- !. |
| 421 | split_commit_delta(copy, NewPath, OldPath, add, NewPath) :- !. |
| 422 | split_commit_delta(Type, Path, _, Type, Path). |
Jason Tsay | ac7d2f3 | 2011-07-15 12:26:36 -0700 | [diff] [blame] | 423 | |
| 424 | |
| 425 | %% commit_message_matches/1: |
| 426 | %% |
| 427 | :- public commit_message_matches/1. |
| 428 | %% |
| 429 | commit_message_matches(Pattern) :- |
| 430 | commit_message(Msg), |
| 431 | regex_matches(Pattern, Msg). |
Gal Paikin | 1226ce6 | 2020-07-24 20:58:45 +0300 | [diff] [blame] | 432 | |
| 433 | |
| 434 | %% member/2: |
| 435 | %% |
| 436 | :- public member/2. |
| 437 | %% |
| 438 | member(X,[X|_]). |
| 439 | member(X,[Y|T]) :- member(X,T). |
| 440 | |
| 441 | %% includes_file/1: |
| 442 | %% |
| 443 | :- public includes_file/1. |
| 444 | %% |
| 445 | includes_file(File) :- |
| 446 | files(List), |
| 447 | member(File, List). |