@@ -643,11 +643,11 @@ static void run_postpasses(cbm_pipeline_ctx_t *ctx, cbm_file_info_t *changed_fil
643643 * Mode-skipped hash rows are preserved across the rebuild so subsequent
644644 * reindexes can correctly distinguish "never indexed" from "indexed but
645645 * not visited this pass". */
646- static void dump_and_persist (cbm_gbuf_t * gbuf , const char * db_path , const char * project ,
647- cbm_file_info_t * files , int file_count ,
648- const cbm_file_hash_t * mode_skipped , int mode_skipped_count ,
649- const char * repo_path , const cbm_coverage_row_t * cov , int cov_count ,
650- const cbm_coverage_meta_t * meta_template ) {
646+ static int dump_and_persist (cbm_gbuf_t * gbuf , const char * db_path , const char * project ,
647+ cbm_file_info_t * files , int file_count ,
648+ const cbm_file_hash_t * mode_skipped , int mode_skipped_count ,
649+ const char * repo_path , const cbm_coverage_row_t * cov , int cov_count ,
650+ const cbm_coverage_meta_t * meta_template ) {
651651 struct timespec t ;
652652 cbm_clock_gettime (CLOCK_MONOTONIC , & t );
653653
@@ -662,12 +662,20 @@ static void dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *
662662 int dump_rc = cbm_gbuf_dump_to_sqlite (gbuf , db_path );
663663 cbm_log_info ("incremental.dump" , "rc" , itoa_buf (dump_rc ), "elapsed_ms" ,
664664 itoa_buf ((int )elapsed_ms (t )));
665-
665+ bool format_stamped = true;
666666 cbm_store_t * hash_store = cbm_store_open_path (db_path );
667667 if (hash_store ) {
668668 bool hash_records_complete = persist_hashes (hash_store , project , files , file_count ,
669669 mode_skipped , mode_skipped_count );
670670
671+ /* #769: cbm_writer_open truncates and rebuilds the DB file from
672+ * scratch on every dump, so the format version written by the last
673+ * full index is gone by the time we get here. */
674+ if (cbm_store_set_format_version (hash_store , CBM_INDEX_FORMAT_VERSION ) != CBM_STORE_OK ) {
675+ cbm_log_error ("incremental.err" , "msg" , "persist_format_version" , "project" , project );
676+ format_stamped = false;
677+ }
678+
671679 /* Coverage rows (#963): re-write the merged set into the rebuilt DB
672680 * (AFTER hashes, so the deleted-file prune sees the live file set). */
673681 cbm_project_t project_info = {0 };
@@ -705,6 +713,8 @@ static void dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *
705713 if (repo_path && cbm_artifact_exists (repo_path )) {
706714 cbm_artifact_export (db_path , repo_path , project , CBM_ARTIFACT_FAST );
707715 }
716+
717+ return format_stamped ? 0 : CBM_NOT_FOUND ;
708718}
709719
710720/* ── Incremental pipeline entry point ────────────────────────────── */
@@ -1010,13 +1020,14 @@ int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_fil
10101020 .ignored_files_total = run_ignored_total ,
10111021 .coverage_version = 1 ,
10121022 };
1013- dump_and_persist (existing , db_path , project , files , file_count , mode_skipped ,
1014- mode_skipped_count , cbm_pipeline_repo_path (p ), cov , cov_n , & coverage_meta );
1023+ int dp_rc =
1024+ dump_and_persist (existing , db_path , project , files , file_count , mode_skipped ,
1025+ mode_skipped_count , cbm_pipeline_repo_path (p ), cov , cov_n , & coverage_meta );
10151026 free (cov );
10161027 cbm_store_free_coverage (old_cov , old_cov_count );
10171028 free_mode_skipped (mode_skipped , mode_skipped_count );
10181029 cbm_gbuf_free (existing );
10191030
10201031 cbm_log_info ("incremental.done" , "elapsed_ms" , itoa_buf ((int )elapsed_ms (t0 )));
1021- return 0 ;
1032+ return dp_rc ;
10221033}
0 commit comments