@@ -2500,6 +2500,18 @@ static const char *closure_k8s_decline(cbm_store_t *store, const char *project,
25002500 return NULL ;
25012501}
25022502
2503+ /* A Python file whose namespace metadata changed, or is unreadable, declines
2504+ * the closure before any hash cutoff: its importers' bindings follow the
2505+ * namespace order. A deleted file passes NULL for fresh_json. */
2506+ static const char * closure_python_namespace_decline (const char * stored_json ,
2507+ const char * fresh_json ) {
2508+ int change = cbm_lsp_surface_python_change (stored_json , fresh_json );
2509+ if (change < 0 ) {
2510+ return "python_namespace_metadata_invalid" ;
2511+ }
2512+ return change > 0 ? "python_namespace_changed" : NULL ;
2513+ }
2514+
25032515/* Decide whether this manifest delta is closure-repairable, and if so build
25042516 * the plan. Returns 1 with *plan filled, or 0 (decline → FULL) with the
25052517 * reason logged. Every early exit declines; nothing here mutates state. */
@@ -2708,7 +2720,10 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27082720 }
27092721 body_targets = dep_targets + n_changed + n_deleted ;
27102722 int dep_target_count = 0 ;
2711- for (int i = 0 ; i < n_changed ; i ++ ) {
2723+ /* The first file that declines the closure stops both loops; the one exit
2724+ * below releases dep_targets and the row index for every reason. */
2725+ const char * why = NULL ;
2726+ for (int i = 0 ; i < n_changed && !why ; i ++ ) {
27122727 const cbm_lsp_surface_row_t * stored_row = cbm_ht_get (rows_by_path , changed_paths [i ]);
27132728 const cbm_lsp_surface_row_t * fresh_row = NULL ;
27142729 for (int j = 0 ; j < probe_count ; j ++ ) {
@@ -2718,19 +2733,12 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27182733 }
27192734 }
27202735 if (!stored_row || !fresh_row ) {
2721- free (dep_targets );
2722- cbm_ht_free (rows_by_path );
2723- decline = "missing_surface_row" ;
2724- goto done ;
2736+ why = "missing_surface_row" ;
2737+ break ;
27252738 }
2726- int python_change =
2727- cbm_lsp_surface_python_change (stored_row -> defs_json , fresh_row -> defs_json );
2728- if (python_change != 0 ) {
2729- free (dep_targets );
2730- cbm_ht_free (rows_by_path );
2731- decline = python_change < 0 ? "python_namespace_metadata_invalid"
2732- : "python_namespace_changed" ;
2733- goto done ;
2739+ why = closure_python_namespace_decline (stored_row -> defs_json , fresh_row -> defs_json );
2740+ if (why ) {
2741+ break ;
27342742 }
27352743 if (strcmp (stored_row -> surface_sha , fresh_row -> surface_sha ) == 0 ) {
27362744 /* body edit: the file re-resolves, and of the others only the
@@ -2739,38 +2747,25 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27392747 continue ;
27402748 }
27412749 bool added = false;
2742- const char * why = NULL ;
27432750 if (surface_added_names (stored_row -> defs_json , fresh_row -> defs_json , & added ) != 0 ||
27442751 added ) {
27452752 why = "added_definition_names" ;
27462753 } else if (!doc_scope_repairable (stored_row -> defs_json , fresh_row -> defs_json ,
27472754 removed_names )) {
27482755 why = "doc_scope_changed" ;
2756+ } else {
2757+ n_surface_changed ++ ;
2758+ dep_targets [dep_target_count ++ ] = changed_paths [i ];
27492759 }
2750- if (why ) {
2751- free (dep_targets );
2752- cbm_ht_free (rows_by_path );
2753- decline = why ;
2754- goto done ;
2755- }
2756- n_surface_changed ++ ;
2757- dep_targets [dep_target_count ++ ] = changed_paths [i ];
27582760 }
27592761 bool gone_scope_changed = false; /* a deleted file takes its declarations along */
2760- for (int i = 0 ; i < n_deleted ; i ++ ) {
2761- const cbm_lsp_surface_row_t * stored_row =
2762- cbm_ht_get (rows_by_path , changed_paths [n_changed + i ]);
2763- int python_change =
2764- cbm_lsp_surface_python_change (stored_row ? stored_row -> defs_json : NULL , NULL );
2765- if (python_change != 0 ) {
2766- free (dep_targets );
2767- cbm_ht_free (rows_by_path );
2768- decline = python_change < 0 ? "python_namespace_metadata_invalid"
2769- : "python_namespace_changed" ;
2770- goto done ;
2762+ for (int i = 0 ; i < n_deleted && !why ; i ++ ) {
2763+ const cbm_lsp_surface_row_t * gone = cbm_ht_get (rows_by_path , changed_paths [n_changed + i ]);
2764+ why = closure_python_namespace_decline (gone ? gone -> defs_json : NULL , NULL );
2765+ if (why ) {
2766+ break ;
27712767 }
27722768 dep_targets [dep_target_count ++ ] = changed_paths [n_changed + i ];
2773- const cbm_lsp_surface_row_t * gone = cbm_ht_get (rows_by_path , changed_paths [n_changed + i ]);
27742769 if (gone && !doc_scope_repairable (gone -> defs_json , NULL , removed_names )) {
27752770 gone_scope_changed = true;
27762771 }
@@ -2782,14 +2777,18 @@ static int closure_try_plan(cbm_pipeline_t *p, cbm_store_t *store, const char *p
27822777 * target, so the documents with edges into a body-edited file re-resolve
27832778 * too (added to the closure below). */
27842779 bool dep_failed =
2785- (dep_target_count > 0 &&
2786- cbm_store_get_dependent_files (store , project , dep_targets , dep_target_count , & dependents ,
2787- & dependent_count ) != CBM_STORE_OK ) ||
2788- (body_target_count > 0 &&
2789- cbm_store_get_dependent_files (store , project , body_targets , body_target_count , & line_docs ,
2790- & line_doc_count ) != CBM_STORE_OK );
2780+ ! why && ( (dep_target_count > 0 &&
2781+ cbm_store_get_dependent_files (store , project , dep_targets , dep_target_count ,
2782+ & dependents , & dependent_count ) != CBM_STORE_OK ) ||
2783+ (body_target_count > 0 &&
2784+ cbm_store_get_dependent_files (store , project , body_targets , body_target_count ,
2785+ & line_docs , & line_doc_count ) != CBM_STORE_OK ) );
27912786 free (dep_targets ); /* body_targets with it */
27922787 body_targets = NULL ;
2788+ if (why ) {
2789+ decline = why ;
2790+ goto done ;
2791+ }
27932792 if (dep_failed ) {
27942793 decline = "dependent_query_failed" ;
27952794 goto done ;
0 commit comments