@@ -39,16 +39,21 @@ class AdjustCallback(Protocol):
3939 A callback for per-rule notifications made by Tree.adjust()
4040
4141 Function which will be called for every rule inspected by adjust().
42- It will be given three arguments: fmf tree being inspected,
43- current adjust rule, and whether the rule was skipped (``None``),
44- applied (``True``) or not applied (``False``).
42+ It will be given the following arguments:
43+
44+ * fmf tree being inspected - **after ``adjust``** rule was applied,
45+ * the current adjust rule,
46+ * whether the rule was skipped (``None``), applied (``True``) or not
47+ applied (``False``),
48+ * and if the rule was applied, the original node content.
4549 """
4650
4751 def __call__ (
4852 self ,
4953 node : 'Tree' ,
5054 rule : Dict [str , Any ],
51- applied : Optional [bool ]) -> None :
55+ applied : Optional [bool ],
56+ before : Optional ['Tree' ] = None ) -> None :
5257 pass
5358
5459
@@ -584,16 +589,22 @@ def apply_rules(rule_set):
584589 # Apply remaining rule attributes if context matches
585590 try :
586591 if context .matches (condition ):
587- if decision_callback :
588- decision_callback (self , rule , True )
589-
590592 # Remove special keys (when, because...) from the rule
591593 apply_rule = {
592594 key : value
593595 for key , value in rule .items ()
594596 if key not in ADJUST_CONTROL_KEYS
595597 }
596- self ._merge_special (self .data , apply_rule )
598+
599+ if decision_callback :
600+ node_before = self .copy ()
601+
602+ self ._merge_special (self .data , apply_rule )
603+
604+ decision_callback (self , rule , True , before = node_before )
605+
606+ else :
607+ self ._merge_special (self .data , apply_rule )
597608
598609 # First matching rule wins, skip the rest of this set unless continue
599610 if not continue_ :
0 commit comments