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.

drh 2020-08-29 13:06 trunk merge
Commit 4ff4e1c8a7b5935476faad9f9614be9bad9af0dbd13213c322578e6334fc33b3
1 file changed +33 -16
+33 -16
--- src/checkin.c
+++ src/checkin.c
@@ -1333,17 +1333,18 @@
13331333
** and should be freed by the caller. The caller should also unlink
13341334
** the file when it is done.
13351335
*/
13361336
static char *prepare_commit_description_file(
13371337
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 */
13391341
){
13401342
Blob *pDesc;
13411343
char *zTags;
13421344
char *zFilename;
13431345
Blob desc;
1344
- unsigned int r[2];
13451346
blob_init(&desc, 0, 0);
13461347
pDesc = &desc;
13471348
blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot);
13481349
blob_appendf(pDesc, "repository %s\n", g.zRepositoryName);
13491350
blob_appendf(pDesc, "user %s\n",
@@ -1370,14 +1371,25 @@
13701371
blob_append(pDesc, "private-branch\n", -1);
13711372
}
13721373
if( p->integrateFlag ){
13731374
blob_append(pDesc, "integrate\n", -1);
13741375
}
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
+ }
13791391
blob_reset(pDesc);
13801392
return zFilename;
13811393
}
13821394
13831395
@@ -2411,20 +2423,10 @@
24112423
}
24122424
24132425
/* Always exit the loop on the second pass */
24142426
if( bRecheck ) break;
24152427
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
- }
24262428
24272429
/* Get the check-in comment. This might involve prompting the
24282430
** user for the check-in comment, in which case we should resync
24292431
** to renew the check-in lock and repeat the checks for conflicts.
24302432
*/
@@ -2478,10 +2480,25 @@
24782480
if( cReply!='y' && cReply!='Y' ){
24792481
fossil_exit(1);
24802482
}
24812483
}
24822484
}
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
+ }
24832500
24842501
/*
24852502
** Step 1: Compute an aggregate MD5 checksum over the disk image
24862503
** of every file in vid. The file names are part of the checksum.
24872504
** The resulting checksum is the same as is expected on the R-card
24882505
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button