Fossil SCM
Run the before-commit hook after the check-in comment has been collected from the user and include the check-in comment in the information provided to the hook.
Commit
4ff4e1c8a7b5935476faad9f9614be9bad9af0dbd13213c322578e6334fc33b3
Parent
23f95bfc06b7ebb…
1 file changed
+33
-16
+33
-16
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -1333,17 +1333,18 @@ | ||
| 1333 | 1333 | ** and should be freed by the caller. The caller should also unlink |
| 1334 | 1334 | ** the file when it is done. |
| 1335 | 1335 | */ |
| 1336 | 1336 | static char *prepare_commit_description_file( |
| 1337 | 1337 | CheckinInfo *p, /* Information about this commit */ |
| 1338 | - int parent_rid /* parent check-in */ | |
| 1338 | + int parent_rid, /* parent check-in */ | |
| 1339 | + Blob *pComment, /* Check-in comment */ | |
| 1340 | + int dryRunFlag /* True for a dry-run only */ | |
| 1339 | 1341 | ){ |
| 1340 | 1342 | Blob *pDesc; |
| 1341 | 1343 | char *zTags; |
| 1342 | 1344 | char *zFilename; |
| 1343 | 1345 | Blob desc; |
| 1344 | - unsigned int r[2]; | |
| 1345 | 1346 | blob_init(&desc, 0, 0); |
| 1346 | 1347 | pDesc = &desc; |
| 1347 | 1348 | blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot); |
| 1348 | 1349 | blob_appendf(pDesc, "repository %s\n", g.zRepositoryName); |
| 1349 | 1350 | blob_appendf(pDesc, "user %s\n", |
| @@ -1370,14 +1371,25 @@ | ||
| 1370 | 1371 | blob_append(pDesc, "private-branch\n", -1); |
| 1371 | 1372 | } |
| 1372 | 1373 | if( p->integrateFlag ){ |
| 1373 | 1374 | blob_append(pDesc, "integrate\n", -1); |
| 1374 | 1375 | } |
| 1375 | - sqlite3_randomness(sizeof(r), r); | |
| 1376 | - zFilename = mprintf("%scommit-description-%08x%08x.txt", | |
| 1377 | - g.zLocalRoot, r[0], r[1]); | |
| 1378 | - blob_write_to_file(pDesc, zFilename); | |
| 1376 | + if( pComment && blob_size(pComment)>0 ){ | |
| 1377 | + blob_appendf(pDesc, "checkin-comment\n%s\n", blob_str(pComment)); | |
| 1378 | + } | |
| 1379 | + if( dryRunFlag ){ | |
| 1380 | + zFilename = 0; | |
| 1381 | + fossil_print("******* Commit Description *******\n%s" | |
| 1382 | + "***** End Commit Description *****\n", | |
| 1383 | + blob_str(pDesc)); | |
| 1384 | + }else{ | |
| 1385 | + unsigned int r[2]; | |
| 1386 | + sqlite3_randomness(sizeof(r), r); | |
| 1387 | + zFilename = mprintf("%scommit-description-%08x%08x.txt", | |
| 1388 | + g.zLocalRoot, r[0], r[1]); | |
| 1389 | + blob_write_to_file(pDesc, zFilename); | |
| 1390 | + } | |
| 1379 | 1391 | blob_reset(pDesc); |
| 1380 | 1392 | return zFilename; |
| 1381 | 1393 | } |
| 1382 | 1394 | |
| 1383 | 1395 | |
| @@ -2411,20 +2423,10 @@ | ||
| 2411 | 2423 | } |
| 2412 | 2424 | |
| 2413 | 2425 | /* Always exit the loop on the second pass */ |
| 2414 | 2426 | if( bRecheck ) break; |
| 2415 | 2427 | |
| 2416 | - /* Run before-commit hooks */ | |
| 2417 | - if( !noVerify ){ | |
| 2418 | - char *zAuxFile = prepare_commit_description_file(&sCiInfo,vid); | |
| 2419 | - int rc = hook_run("before-commit",zAuxFile,bTrace); | |
| 2420 | - file_delete(zAuxFile); | |
| 2421 | - fossil_free(zAuxFile); | |
| 2422 | - if( rc ){ | |
| 2423 | - fossil_fatal("Before-commit hook failed\n"); | |
| 2424 | - } | |
| 2425 | - } | |
| 2426 | 2428 | |
| 2427 | 2429 | /* Get the check-in comment. This might involve prompting the |
| 2428 | 2430 | ** user for the check-in comment, in which case we should resync |
| 2429 | 2431 | ** to renew the check-in lock and repeat the checks for conflicts. |
| 2430 | 2432 | */ |
| @@ -2478,10 +2480,25 @@ | ||
| 2478 | 2480 | if( cReply!='y' && cReply!='Y' ){ |
| 2479 | 2481 | fossil_exit(1); |
| 2480 | 2482 | } |
| 2481 | 2483 | } |
| 2482 | 2484 | } |
| 2485 | + | |
| 2486 | + if( !noVerify && hook_exists("before-commit") ){ | |
| 2487 | + /* Run before-commit hooks */ | |
| 2488 | + char *zAuxFile; | |
| 2489 | + zAuxFile = prepare_commit_description_file( | |
| 2490 | + &sCiInfo, vid, &comment, dryRunFlag); | |
| 2491 | + if( zAuxFile ){ | |
| 2492 | + int rc = hook_run("before-commit",zAuxFile,bTrace); | |
| 2493 | + file_delete(zAuxFile); | |
| 2494 | + fossil_free(zAuxFile); | |
| 2495 | + if( rc ){ | |
| 2496 | + fossil_fatal("Before-commit hook failed\n"); | |
| 2497 | + } | |
| 2498 | + } | |
| 2499 | + } | |
| 2483 | 2500 | |
| 2484 | 2501 | /* |
| 2485 | 2502 | ** Step 1: Compute an aggregate MD5 checksum over the disk image |
| 2486 | 2503 | ** of every file in vid. The file names are part of the checksum. |
| 2487 | 2504 | ** The resulting checksum is the same as is expected on the R-card |
| 2488 | 2505 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1333,17 +1333,18 @@ | |
| 1333 | ** and should be freed by the caller. The caller should also unlink |
| 1334 | ** the file when it is done. |
| 1335 | */ |
| 1336 | static char *prepare_commit_description_file( |
| 1337 | CheckinInfo *p, /* Information about this commit */ |
| 1338 | int parent_rid /* parent check-in */ |
| 1339 | ){ |
| 1340 | Blob *pDesc; |
| 1341 | char *zTags; |
| 1342 | char *zFilename; |
| 1343 | Blob desc; |
| 1344 | unsigned int r[2]; |
| 1345 | blob_init(&desc, 0, 0); |
| 1346 | pDesc = &desc; |
| 1347 | blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot); |
| 1348 | blob_appendf(pDesc, "repository %s\n", g.zRepositoryName); |
| 1349 | blob_appendf(pDesc, "user %s\n", |
| @@ -1370,14 +1371,25 @@ | |
| 1370 | blob_append(pDesc, "private-branch\n", -1); |
| 1371 | } |
| 1372 | if( p->integrateFlag ){ |
| 1373 | blob_append(pDesc, "integrate\n", -1); |
| 1374 | } |
| 1375 | sqlite3_randomness(sizeof(r), r); |
| 1376 | zFilename = mprintf("%scommit-description-%08x%08x.txt", |
| 1377 | g.zLocalRoot, r[0], r[1]); |
| 1378 | blob_write_to_file(pDesc, zFilename); |
| 1379 | blob_reset(pDesc); |
| 1380 | return zFilename; |
| 1381 | } |
| 1382 | |
| 1383 | |
| @@ -2411,20 +2423,10 @@ | |
| 2411 | } |
| 2412 | |
| 2413 | /* Always exit the loop on the second pass */ |
| 2414 | if( bRecheck ) break; |
| 2415 | |
| 2416 | /* Run before-commit hooks */ |
| 2417 | if( !noVerify ){ |
| 2418 | char *zAuxFile = prepare_commit_description_file(&sCiInfo,vid); |
| 2419 | int rc = hook_run("before-commit",zAuxFile,bTrace); |
| 2420 | file_delete(zAuxFile); |
| 2421 | fossil_free(zAuxFile); |
| 2422 | if( rc ){ |
| 2423 | fossil_fatal("Before-commit hook failed\n"); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | /* Get the check-in comment. This might involve prompting the |
| 2428 | ** user for the check-in comment, in which case we should resync |
| 2429 | ** to renew the check-in lock and repeat the checks for conflicts. |
| 2430 | */ |
| @@ -2478,10 +2480,25 @@ | |
| 2478 | if( cReply!='y' && cReply!='Y' ){ |
| 2479 | fossil_exit(1); |
| 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | ** Step 1: Compute an aggregate MD5 checksum over the disk image |
| 2486 | ** of every file in vid. The file names are part of the checksum. |
| 2487 | ** The resulting checksum is the same as is expected on the R-card |
| 2488 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -1333,17 +1333,18 @@ | |
| 1333 | ** and should be freed by the caller. The caller should also unlink |
| 1334 | ** the file when it is done. |
| 1335 | */ |
| 1336 | static char *prepare_commit_description_file( |
| 1337 | CheckinInfo *p, /* Information about this commit */ |
| 1338 | int parent_rid, /* parent check-in */ |
| 1339 | Blob *pComment, /* Check-in comment */ |
| 1340 | int dryRunFlag /* True for a dry-run only */ |
| 1341 | ){ |
| 1342 | Blob *pDesc; |
| 1343 | char *zTags; |
| 1344 | char *zFilename; |
| 1345 | Blob desc; |
| 1346 | blob_init(&desc, 0, 0); |
| 1347 | pDesc = &desc; |
| 1348 | blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot); |
| 1349 | blob_appendf(pDesc, "repository %s\n", g.zRepositoryName); |
| 1350 | blob_appendf(pDesc, "user %s\n", |
| @@ -1370,14 +1371,25 @@ | |
| 1371 | blob_append(pDesc, "private-branch\n", -1); |
| 1372 | } |
| 1373 | if( p->integrateFlag ){ |
| 1374 | blob_append(pDesc, "integrate\n", -1); |
| 1375 | } |
| 1376 | if( pComment && blob_size(pComment)>0 ){ |
| 1377 | blob_appendf(pDesc, "checkin-comment\n%s\n", blob_str(pComment)); |
| 1378 | } |
| 1379 | if( dryRunFlag ){ |
| 1380 | zFilename = 0; |
| 1381 | fossil_print("******* Commit Description *******\n%s" |
| 1382 | "***** End Commit Description *****\n", |
| 1383 | blob_str(pDesc)); |
| 1384 | }else{ |
| 1385 | unsigned int r[2]; |
| 1386 | sqlite3_randomness(sizeof(r), r); |
| 1387 | zFilename = mprintf("%scommit-description-%08x%08x.txt", |
| 1388 | g.zLocalRoot, r[0], r[1]); |
| 1389 | blob_write_to_file(pDesc, zFilename); |
| 1390 | } |
| 1391 | blob_reset(pDesc); |
| 1392 | return zFilename; |
| 1393 | } |
| 1394 | |
| 1395 | |
| @@ -2411,20 +2423,10 @@ | |
| 2423 | } |
| 2424 | |
| 2425 | /* Always exit the loop on the second pass */ |
| 2426 | if( bRecheck ) break; |
| 2427 | |
| 2428 | |
| 2429 | /* Get the check-in comment. This might involve prompting the |
| 2430 | ** user for the check-in comment, in which case we should resync |
| 2431 | ** to renew the check-in lock and repeat the checks for conflicts. |
| 2432 | */ |
| @@ -2478,10 +2480,25 @@ | |
| 2480 | if( cReply!='y' && cReply!='Y' ){ |
| 2481 | fossil_exit(1); |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | if( !noVerify && hook_exists("before-commit") ){ |
| 2487 | /* Run before-commit hooks */ |
| 2488 | char *zAuxFile; |
| 2489 | zAuxFile = prepare_commit_description_file( |
| 2490 | &sCiInfo, vid, &comment, dryRunFlag); |
| 2491 | if( zAuxFile ){ |
| 2492 | int rc = hook_run("before-commit",zAuxFile,bTrace); |
| 2493 | file_delete(zAuxFile); |
| 2494 | fossil_free(zAuxFile); |
| 2495 | if( rc ){ |
| 2496 | fossil_fatal("Before-commit hook failed\n"); |
| 2497 | } |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | /* |
| 2502 | ** Step 1: Compute an aggregate MD5 checksum over the disk image |
| 2503 | ** of every file in vid. The file names are part of the checksum. |
| 2504 | ** The resulting checksum is the same as is expected on the R-card |
| 2505 |