config.c: fix saving of deep/wide template configurations
Follow-on to #244 and #960 regarding how the ast_config_XXX APIs
handle template inheritance.
ast_config_text_file_save2() incorrectly suppressed variables if they
matched any ancestor template. This broke deep chains (dropping values
based on distant parents) and wide inheritance (ignoring last-wins order
across multiple parents).
The function now inspects the full template hierarchy to find the nearest
effective parent (last occurrence wins). Earlier inherited duplicates are
collapsed, explicit overrides are kept unless they exactly match the parent,
and PreserveEffectiveContext avoids writing redundant lines.