X-Git-Url: http://git.annexia.org/?p=whenjobs.git;a=blobdiff_plain;f=lib%2Fwhenstate.ml;h=e3aad07c8b57a500cc02d45351b3278e5891615d;hp=fe53a1649cf1f2711b70d99fb6b0ded112bc6c53;hb=2f2b5efdf699e4bc0723079dcd2f68a0fd44ce07;hpb=9a137583b1fd5e6705ac116045db3b583834e838 diff --git a/lib/whenstate.ml b/lib/whenstate.ml index fe53a16..e3aad07 100644 --- a/lib/whenstate.ml +++ b/lib/whenstate.ml @@ -77,6 +77,36 @@ let set_variable t name value = let copy_variables old t = { t with variables = StringMap.fold StringMap.add old.variables t.variables } +let copy_prev_state old t = + let is_explicit jobname = + String.length jobname < 4 || String.sub jobname 0 4 <> "job$" + in + + let prev_variables = StringMap.fold ( + fun jobname _ map -> + try + if not (is_explicit jobname) then raise Not_found; + (* See if we can find a job with the same name in the old state. *) + let old_vars = StringMap.find jobname old.prev_variables in + StringMap.add jobname old_vars map + with + Not_found -> map + ) t.jobmap t.prev_variables in + + let prev_eval_result = StringMap.fold ( + fun jobname _ map -> + try + if not (is_explicit jobname) then raise Not_found; + (* See if we can find a job with the same name in the old state. *) + let old_result = StringMap.find jobname old.prev_eval_result in + StringMap.add jobname old_result map + with + Not_found -> map + ) t.jobmap t.prev_eval_result in + + { t with + prev_variables = prev_variables; prev_eval_result = prev_eval_result } + let get_variable t name = try StringMap.find name t.variables with Not_found -> T_string ""