Fossil SCM
Use a temp table to consolidate how merge-info --html collects its list of files to process.
Commit
04a868ac21ec86b504ce164a027454370a9f9530a76e8c958630d7747822d07d
Parent
e76aceba7cab092…
2 files changed
+56
-50
+2
+56
-50
| --- src/merge.c | ||
| +++ src/merge.c | ||
| @@ -300,71 +300,77 @@ | ||
| 300 | 300 | int bAll, /* All changes, not just merged content */ |
| 301 | 301 | int nContext /* Diff context lines */){ |
| 302 | 302 | Blob out = empty_blob; |
| 303 | 303 | MergeBuilderHtml mbh; |
| 304 | 304 | MergeBuilder * mb = &mbh.base; |
| 305 | + Stmt q; | |
| 306 | + | |
| 307 | + /* Figure out which files to process. We do this level of indirection | |
| 308 | + ** so that the loop which follows is identical for both the all-files and | |
| 309 | + ** the CLI-list-of-files cases work identically. | |
| 310 | + */ | |
| 311 | + db_multi_exec("CREATE TEMP TABLE mi_html (" | |
| 312 | + "mirid INTEGER UNIQUE ON CONFLICT IGNORE" | |
| 313 | + ")"); | |
| 314 | + if( g.argc==2 ){ | |
| 315 | + /* No files named on the command-line. Use every file mentioned | |
| 316 | + ** in the MERGESTAT table to generate the file list. */ | |
| 317 | + db_multi_exec("INSERT INTO mi_html (mirid) " | |
| 318 | + "SELECT rowid FROM mergestat %s ", | |
| 319 | + bAll ? "" | |
| 320 | + : "WHERE op IN ('MERGE','CONFLICT')" /*safe-for-%s*/); | |
| 321 | + }else{ | |
| 322 | + /* Use only files named on the command-line in the file list. | |
| 323 | + ** But verify each file named is actually found in the MERGESTAT | |
| 324 | + ** table first. */ | |
| 325 | + int i; | |
| 326 | + for(i=2; i<g.argc; i++){ | |
| 327 | + char *zFile; /* Input filename */ | |
| 328 | + char const *zTreename;/* Name of the file in the tree */ | |
| 329 | + Blob fname; /* Filename relative to root */ | |
| 330 | + int gotRid; /* mergestat row ID */ | |
| 331 | + zFile = mprintf("%/", g.argv[i]); | |
| 332 | + file_tree_name(zFile, &fname, 0, 1); | |
| 333 | + fossil_free(zFile); | |
| 334 | + zTreename = blob_str(&fname); | |
| 335 | + gotRid = db_int(0, "SELECT rowid FROM mergestat WHERE fnr=%Q or fn=%Q", | |
| 336 | + zTreename, zTreename); | |
| 337 | + if( !gotRid ){ | |
| 338 | + fossil_fatal("Don't have merge info for %s", zTreename); | |
| 339 | + } | |
| 340 | + db_multi_exec("INSERT INTO mi_html (mirid) VALUES (%d)", | |
| 341 | + gotRid); | |
| 342 | + blob_reset(&fname); | |
| 343 | + } | |
| 344 | + } | |
| 305 | 345 | |
| 306 | 346 | mergebuilder_init_html(&mbh); |
| 307 | 347 | mb->nContext = nContext; |
| 308 | 348 | blob_append(&out, diff_webpage_header(bDark), -1); |
| 309 | 349 | merge_info_html_css(&out); |
| 310 | - | |
| 311 | - if( g.argc==2 ){ | |
| 312 | - /* No files named on the command-line. Use every file mentioned | |
| 313 | - ** in the MERGESTAT table to generate the file list. */ | |
| 314 | - Stmt q; | |
| 315 | - int cnt = 0; | |
| 316 | - db_prepare(&q, | |
| 317 | - "SELECT coalesce(fnr,fn), op FROM mergestat %s ORDER BY 1", | |
| 318 | - bAll ? "" : "WHERE op IN ('MERGE','CONFLICT')" /*safe-for-%s*/ | |
| 319 | - ); | |
| 320 | - blob_append(&out, "<ul>\n", 5); | |
| 321 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 322 | - blob_appendf(&out,"<li>%s ", db_column_text(&q,1)); | |
| 323 | - blob_appendf(&out, "%h</li>\n", db_column_text(&q, 0)); | |
| 324 | - cnt++; | |
| 325 | - } | |
| 326 | - db_finalize(&q); | |
| 327 | - if( cnt==0 ){ | |
| 328 | - blob_append(&out, "<li>No interesting changes in this merge. " | |
| 329 | - "Use --all to see everything</li>\n", | |
| 330 | - -1); | |
| 331 | - } | |
| 332 | - blob_append(&out, "</ul>\n", 6); | |
| 333 | - }else{ | |
| 334 | - int i; | |
| 335 | - /* Use only files named on the command-line in the file list. | |
| 336 | - ** But verify each file named is actually found in the MERGESTAT | |
| 337 | - ** table first. */ | |
| 338 | - blob_append(&out, "<ul>\n", 5); | |
| 339 | - for(i=2; i<g.argc; i++){ | |
| 340 | - char *zFile; /* Input filename */ | |
| 341 | - char *zTreename; /* Name of the file in the tree */ | |
| 342 | - Blob fname; /* Filename relative to root */ | |
| 343 | - char *zOp; /* Operation on this file */ | |
| 344 | - zFile = mprintf("%/", g.argv[i]); | |
| 345 | - file_tree_name(zFile, &fname, 0, 1); | |
| 346 | - fossil_free(zFile); | |
| 347 | - zTreename = blob_str(&fname); | |
| 348 | - zOp = db_text(0, "SELECT op FROM mergestat WHERE fn=%Q or fnr=%Q", | |
| 349 | - zTreename, zTreename); | |
| 350 | - if( !zOp ){ | |
| 351 | - fossil_fatal("Don't have merge info for %s", zTreename); | |
| 352 | - } | |
| 353 | - blob_appendf(&out, "<li>%s ", zOp); | |
| 354 | - fossil_free(zOp); | |
| 355 | - blob_appendf(&out, "%h</li>\n", zTreename); | |
| 356 | - blob_reset(&fname); | |
| 357 | - } | |
| 358 | - blob_append(&out, "</ul>\n", 6); | |
| 359 | - } | |
| 350 | + mb->pOut = &out; | |
| 351 | + | |
| 352 | + db_prepare(&q, | |
| 353 | + /* 0 1 2 3 4 5 6 7 8 9 */ | |
| 354 | + "SELECT op, fnp, ridp, fn, ridv, sz, fnm, ridm, fnr, coalesce(fnr,fn) name" | |
| 355 | + " FROM mergestat WHERE rowid IN mi_html ORDER BY name" | |
| 356 | + ); | |
| 357 | + blob_append(&out, "<ul>\n", 5); | |
| 358 | + while( SQLITE_ROW==db_step(&q) ){ | |
| 359 | + blob_appendf(&out, "<li>%s %h</li>\n", | |
| 360 | + db_column_text(&q,0), db_column_text(&q,9)); | |
| 361 | + } | |
| 362 | + blob_append(&out, "</ul>\n", 6); | |
| 363 | + | |
| 364 | + db_finalize(&q); | |
| 360 | 365 | |
| 361 | 366 | blob_append(&out, diff_webpage_footer(), -1); |
| 362 | 367 | blob_append_char(&out, '\n'); |
| 363 | 368 | blob_write_to_file(&out, "-"); |
| 364 | 369 | blob_reset(&out); |
| 365 | 370 | mb->xDestroy(mb); |
| 371 | + db_multi_exec("DROP TABLE mi_html"); | |
| 366 | 372 | } |
| 367 | 373 | |
| 368 | 374 | /* |
| 369 | 375 | ** COMMAND: merge-info |
| 370 | 376 | ** |
| 371 | 377 |
| --- src/merge.c | |
| +++ src/merge.c | |
| @@ -300,71 +300,77 @@ | |
| 300 | int bAll, /* All changes, not just merged content */ |
| 301 | int nContext /* Diff context lines */){ |
| 302 | Blob out = empty_blob; |
| 303 | MergeBuilderHtml mbh; |
| 304 | MergeBuilder * mb = &mbh.base; |
| 305 | |
| 306 | mergebuilder_init_html(&mbh); |
| 307 | mb->nContext = nContext; |
| 308 | blob_append(&out, diff_webpage_header(bDark), -1); |
| 309 | merge_info_html_css(&out); |
| 310 | |
| 311 | if( g.argc==2 ){ |
| 312 | /* No files named on the command-line. Use every file mentioned |
| 313 | ** in the MERGESTAT table to generate the file list. */ |
| 314 | Stmt q; |
| 315 | int cnt = 0; |
| 316 | db_prepare(&q, |
| 317 | "SELECT coalesce(fnr,fn), op FROM mergestat %s ORDER BY 1", |
| 318 | bAll ? "" : "WHERE op IN ('MERGE','CONFLICT')" /*safe-for-%s*/ |
| 319 | ); |
| 320 | blob_append(&out, "<ul>\n", 5); |
| 321 | while( db_step(&q)==SQLITE_ROW ){ |
| 322 | blob_appendf(&out,"<li>%s ", db_column_text(&q,1)); |
| 323 | blob_appendf(&out, "%h</li>\n", db_column_text(&q, 0)); |
| 324 | cnt++; |
| 325 | } |
| 326 | db_finalize(&q); |
| 327 | if( cnt==0 ){ |
| 328 | blob_append(&out, "<li>No interesting changes in this merge. " |
| 329 | "Use --all to see everything</li>\n", |
| 330 | -1); |
| 331 | } |
| 332 | blob_append(&out, "</ul>\n", 6); |
| 333 | }else{ |
| 334 | int i; |
| 335 | /* Use only files named on the command-line in the file list. |
| 336 | ** But verify each file named is actually found in the MERGESTAT |
| 337 | ** table first. */ |
| 338 | blob_append(&out, "<ul>\n", 5); |
| 339 | for(i=2; i<g.argc; i++){ |
| 340 | char *zFile; /* Input filename */ |
| 341 | char *zTreename; /* Name of the file in the tree */ |
| 342 | Blob fname; /* Filename relative to root */ |
| 343 | char *zOp; /* Operation on this file */ |
| 344 | zFile = mprintf("%/", g.argv[i]); |
| 345 | file_tree_name(zFile, &fname, 0, 1); |
| 346 | fossil_free(zFile); |
| 347 | zTreename = blob_str(&fname); |
| 348 | zOp = db_text(0, "SELECT op FROM mergestat WHERE fn=%Q or fnr=%Q", |
| 349 | zTreename, zTreename); |
| 350 | if( !zOp ){ |
| 351 | fossil_fatal("Don't have merge info for %s", zTreename); |
| 352 | } |
| 353 | blob_appendf(&out, "<li>%s ", zOp); |
| 354 | fossil_free(zOp); |
| 355 | blob_appendf(&out, "%h</li>\n", zTreename); |
| 356 | blob_reset(&fname); |
| 357 | } |
| 358 | blob_append(&out, "</ul>\n", 6); |
| 359 | } |
| 360 | |
| 361 | blob_append(&out, diff_webpage_footer(), -1); |
| 362 | blob_append_char(&out, '\n'); |
| 363 | blob_write_to_file(&out, "-"); |
| 364 | blob_reset(&out); |
| 365 | mb->xDestroy(mb); |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | ** COMMAND: merge-info |
| 370 | ** |
| 371 |
| --- src/merge.c | |
| +++ src/merge.c | |
| @@ -300,71 +300,77 @@ | |
| 300 | int bAll, /* All changes, not just merged content */ |
| 301 | int nContext /* Diff context lines */){ |
| 302 | Blob out = empty_blob; |
| 303 | MergeBuilderHtml mbh; |
| 304 | MergeBuilder * mb = &mbh.base; |
| 305 | Stmt q; |
| 306 | |
| 307 | /* Figure out which files to process. We do this level of indirection |
| 308 | ** so that the loop which follows is identical for both the all-files and |
| 309 | ** the CLI-list-of-files cases work identically. |
| 310 | */ |
| 311 | db_multi_exec("CREATE TEMP TABLE mi_html (" |
| 312 | "mirid INTEGER UNIQUE ON CONFLICT IGNORE" |
| 313 | ")"); |
| 314 | if( g.argc==2 ){ |
| 315 | /* No files named on the command-line. Use every file mentioned |
| 316 | ** in the MERGESTAT table to generate the file list. */ |
| 317 | db_multi_exec("INSERT INTO mi_html (mirid) " |
| 318 | "SELECT rowid FROM mergestat %s ", |
| 319 | bAll ? "" |
| 320 | : "WHERE op IN ('MERGE','CONFLICT')" /*safe-for-%s*/); |
| 321 | }else{ |
| 322 | /* Use only files named on the command-line in the file list. |
| 323 | ** But verify each file named is actually found in the MERGESTAT |
| 324 | ** table first. */ |
| 325 | int i; |
| 326 | for(i=2; i<g.argc; i++){ |
| 327 | char *zFile; /* Input filename */ |
| 328 | char const *zTreename;/* Name of the file in the tree */ |
| 329 | Blob fname; /* Filename relative to root */ |
| 330 | int gotRid; /* mergestat row ID */ |
| 331 | zFile = mprintf("%/", g.argv[i]); |
| 332 | file_tree_name(zFile, &fname, 0, 1); |
| 333 | fossil_free(zFile); |
| 334 | zTreename = blob_str(&fname); |
| 335 | gotRid = db_int(0, "SELECT rowid FROM mergestat WHERE fnr=%Q or fn=%Q", |
| 336 | zTreename, zTreename); |
| 337 | if( !gotRid ){ |
| 338 | fossil_fatal("Don't have merge info for %s", zTreename); |
| 339 | } |
| 340 | db_multi_exec("INSERT INTO mi_html (mirid) VALUES (%d)", |
| 341 | gotRid); |
| 342 | blob_reset(&fname); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | mergebuilder_init_html(&mbh); |
| 347 | mb->nContext = nContext; |
| 348 | blob_append(&out, diff_webpage_header(bDark), -1); |
| 349 | merge_info_html_css(&out); |
| 350 | mb->pOut = &out; |
| 351 | |
| 352 | db_prepare(&q, |
| 353 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 354 | "SELECT op, fnp, ridp, fn, ridv, sz, fnm, ridm, fnr, coalesce(fnr,fn) name" |
| 355 | " FROM mergestat WHERE rowid IN mi_html ORDER BY name" |
| 356 | ); |
| 357 | blob_append(&out, "<ul>\n", 5); |
| 358 | while( SQLITE_ROW==db_step(&q) ){ |
| 359 | blob_appendf(&out, "<li>%s %h</li>\n", |
| 360 | db_column_text(&q,0), db_column_text(&q,9)); |
| 361 | } |
| 362 | blob_append(&out, "</ul>\n", 6); |
| 363 | |
| 364 | db_finalize(&q); |
| 365 | |
| 366 | blob_append(&out, diff_webpage_footer(), -1); |
| 367 | blob_append_char(&out, '\n'); |
| 368 | blob_write_to_file(&out, "-"); |
| 369 | blob_reset(&out); |
| 370 | mb->xDestroy(mb); |
| 371 | db_multi_exec("DROP TABLE mi_html"); |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | ** COMMAND: merge-info |
| 376 | ** |
| 377 |
+2
| --- src/merge3.c | ||
| +++ src/merge3.c | ||
| @@ -707,10 +707,11 @@ | ||
| 707 | 707 | /* TODO: open HTML table */ |
| 708 | 708 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 709 | 709 | blob_zero(&pH->aCol[i]); |
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | + | |
| 712 | 713 | /* MergeBuilderHtml::xEnd() */ |
| 713 | 714 | static void htmlEnd(MergeBuilder *p){ |
| 714 | 715 | MergeBuilderHtml *pH = (MergeBuilderHtml*)p; |
| 715 | 716 | unsigned int i; |
| 716 | 717 | |
| @@ -717,10 +718,11 @@ | ||
| 717 | 718 | /* TODO: flush pH->aCol to p->pOut and close HTML table */ |
| 718 | 719 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 719 | 720 | blob_reset(&pH->aCol[i]); |
| 720 | 721 | } |
| 721 | 722 | } |
| 723 | + | |
| 722 | 724 | /* MergeBuilderHtml::xSame() */ |
| 723 | 725 | static void htmlSame(MergeBuilder *p, unsigned int N){ |
| 724 | 726 | } |
| 725 | 727 | /* MergeBuilderHtml::xChngV1() */ |
| 726 | 728 | static void htmlChngV1(MergeBuilder *p, unsigned int nPivot, unsigned int nV1){ |
| 727 | 729 |
| --- src/merge3.c | |
| +++ src/merge3.c | |
| @@ -707,10 +707,11 @@ | |
| 707 | /* TODO: open HTML table */ |
| 708 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 709 | blob_zero(&pH->aCol[i]); |
| 710 | } |
| 711 | } |
| 712 | /* MergeBuilderHtml::xEnd() */ |
| 713 | static void htmlEnd(MergeBuilder *p){ |
| 714 | MergeBuilderHtml *pH = (MergeBuilderHtml*)p; |
| 715 | unsigned int i; |
| 716 | |
| @@ -717,10 +718,11 @@ | |
| 717 | /* TODO: flush pH->aCol to p->pOut and close HTML table */ |
| 718 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 719 | blob_reset(&pH->aCol[i]); |
| 720 | } |
| 721 | } |
| 722 | /* MergeBuilderHtml::xSame() */ |
| 723 | static void htmlSame(MergeBuilder *p, unsigned int N){ |
| 724 | } |
| 725 | /* MergeBuilderHtml::xChngV1() */ |
| 726 | static void htmlChngV1(MergeBuilder *p, unsigned int nPivot, unsigned int nV1){ |
| 727 |
| --- src/merge3.c | |
| +++ src/merge3.c | |
| @@ -707,10 +707,11 @@ | |
| 707 | /* TODO: open HTML table */ |
| 708 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 709 | blob_zero(&pH->aCol[i]); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /* MergeBuilderHtml::xEnd() */ |
| 714 | static void htmlEnd(MergeBuilder *p){ |
| 715 | MergeBuilderHtml *pH = (MergeBuilderHtml*)p; |
| 716 | unsigned int i; |
| 717 | |
| @@ -717,10 +718,11 @@ | |
| 718 | /* TODO: flush pH->aCol to p->pOut and close HTML table */ |
| 719 | for(i = 0; i < sizeof(pH->aCol)/sizeof(Blob); ++i){ |
| 720 | blob_reset(&pH->aCol[i]); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | /* MergeBuilderHtml::xSame() */ |
| 725 | static void htmlSame(MergeBuilder *p, unsigned int N){ |
| 726 | } |
| 727 | /* MergeBuilderHtml::xChngV1() */ |
| 728 | static void htmlChngV1(MergeBuilder *p, unsigned int nPivot, unsigned int nV1){ |
| 729 |