Fossil

Check-in [4ff4e1c8]
Login

Check-in [4ff4e1c8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4ff4e1c8a7b5935476faad9f9614be9bad9af0dbd13213c322578e6334fc33b3
User & Date: drh 2020-08-29 13:06:11
Context
2020-08-29
14:07
Plugged a leaky abstraction in wikiedit and fileedit which applied when connecting a 3rd-party editor widget and added an example of how to plug in TinyMCE to the fileedit docs. ... (check-in: 88703f00 user: stephan tags: trunk)
13:06
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. ... (check-in: 4ff4e1c8 user: drh tags: trunk)
2020-08-28
18:38
Define the "hooks" setting and mark it as sensitive. ... (check-in: 23f95bfc user: drh tags: trunk)
18:28
Modify the before-commit hook so that it runs after the check-in comment has been collected from the user. Include the check-in comment in the commit-description file. ... (Closed-Leaf check-in: b4006e2e user: drh tags: comment-in-before-commit)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/checkin.c.

1331
1332
1333
1334
1335
1336
1337
1338


1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
**
** Space to hold the returned filename is obtained from fossil_malloc()
** and should be freed by the caller.  The caller should also unlink
** the file when it is done.
*/
static char *prepare_commit_description_file(
  CheckinInfo *p,     /* Information about this commit */
  int parent_rid      /* parent check-in */


){
  Blob *pDesc;
  char *zTags;
  char *zFilename;
  Blob desc;
  unsigned int r[2];
  blob_init(&desc, 0, 0);
  pDesc = &desc;
  blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot);
  blob_appendf(pDesc, "repository %s\n", g.zRepositoryName);
  blob_appendf(pDesc, "user %s\n",
               p->zUserOvrd ? p->zUserOvrd : login_name());
  blob_appendf(pDesc, "branch %s\n",







|
>
>





<







1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345

1346
1347
1348
1349
1350
1351
1352
**
** Space to hold the returned filename is obtained from fossil_malloc()
** and should be freed by the caller.  The caller should also unlink
** the file when it is done.
*/
static char *prepare_commit_description_file(
  CheckinInfo *p,     /* Information about this commit */
  int parent_rid,     /* parent check-in */
  Blob *pComment,     /* Check-in comment */
  int dryRunFlag      /* True for a dry-run only */
){
  Blob *pDesc;
  char *zTags;
  char *zFilename;
  Blob desc;

  blob_init(&desc, 0, 0);
  pDesc = &desc;
  blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot);
  blob_appendf(pDesc, "repository %s\n", g.zRepositoryName);
  blob_appendf(pDesc, "user %s\n",
               p->zUserOvrd ? p->zUserOvrd : login_name());
  blob_appendf(pDesc, "branch %s\n",
1368
1369
1370
1371
1372
1373
1374










1375
1376
1377
1378

1379
1380
1381
1382
1383
1384
1385
  status_report(pDesc, C_DEFAULT | C_FATAL);
  if( g.markPrivate ){
    blob_append(pDesc, "private-branch\n", -1);
  }
  if( p->integrateFlag ){
    blob_append(pDesc, "integrate\n", -1);
  }










  sqlite3_randomness(sizeof(r), r);
  zFilename = mprintf("%scommit-description-%08x%08x.txt",
                      g.zLocalRoot, r[0], r[1]);
  blob_write_to_file(pDesc, zFilename);

  blob_reset(pDesc);
  return zFilename;
}


/*
** Populate the Global.aCommitFile[] based on the command line arguments







>
>
>
>
>
>
>
>
>
>
|
|
|
|
>







1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
  status_report(pDesc, C_DEFAULT | C_FATAL);
  if( g.markPrivate ){
    blob_append(pDesc, "private-branch\n", -1);
  }
  if( p->integrateFlag ){
    blob_append(pDesc, "integrate\n", -1);
  }
  if( pComment && blob_size(pComment)>0 ){
    blob_appendf(pDesc, "checkin-comment\n%s\n", blob_str(pComment));
  }
  if( dryRunFlag ){
    zFilename = 0;
    fossil_print("******* Commit Description *******\n%s"
                 "***** End Commit Description *****\n",
                 blob_str(pDesc));
  }else{
    unsigned int r[2];
    sqlite3_randomness(sizeof(r), r);
    zFilename = mprintf("%scommit-description-%08x%08x.txt",
                        g.zLocalRoot, r[0], r[1]);
    blob_write_to_file(pDesc, zFilename);
  }
  blob_reset(pDesc);
  return zFilename;
}


/*
** Populate the Global.aCommitFile[] based on the command line arguments
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
    ){
      fossil_fatal("cannot commit against a closed leaf");
    }

    /* Always exit the loop on the second pass */
    if( bRecheck ) break;

    /* Run before-commit hooks */
    if( !noVerify ){
      char *zAuxFile = prepare_commit_description_file(&sCiInfo,vid);
      int rc = hook_run("before-commit",zAuxFile,bTrace);
      file_delete(zAuxFile);
      fossil_free(zAuxFile);
      if( rc ){
        fossil_fatal("Before-commit hook failed\n");
      }
    }
  
    /* Get the check-in comment.  This might involve prompting the
    ** user for the check-in comment, in which case we should resync
    ** to renew the check-in lock and repeat the checks for conflicts.
    */
    if( zComment ){
      blob_zero(&comment);







<
<
<
<
<
<
<
<
<
<







2421
2422
2423
2424
2425
2426
2427










2428
2429
2430
2431
2432
2433
2434
    ){
      fossil_fatal("cannot commit against a closed leaf");
    }

    /* Always exit the loop on the second pass */
    if( bRecheck ) break;











  
    /* Get the check-in comment.  This might involve prompting the
    ** user for the check-in comment, in which case we should resync
    ** to renew the check-in lock and repeat the checks for conflicts.
    */
    if( zComment ){
      blob_zero(&comment);
2476
2477
2478
2479
2480
2481
2482















2483
2484
2485
2486
2487
2488
2489
        cReply = 'N';
      }
      if( cReply!='y' && cReply!='Y' ){
        fossil_exit(1);
      }
    }
  }
















  /*
  ** Step 1: Compute an aggregate MD5 checksum over the disk image
  ** of every file in vid.  The file names are part of the checksum.
  ** The resulting checksum is the same as is expected on the R-card
  ** of a manifest.
  */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
        cReply = 'N';
      }
      if( cReply!='y' && cReply!='Y' ){
        fossil_exit(1);
      }
    }
  }

  if( !noVerify && hook_exists("before-commit") ){
    /* Run before-commit hooks */
    char *zAuxFile;
    zAuxFile = prepare_commit_description_file(
                     &sCiInfo, vid, &comment, dryRunFlag);
    if( zAuxFile ){
      int rc = hook_run("before-commit",zAuxFile,bTrace);
      file_delete(zAuxFile);
      fossil_free(zAuxFile);
      if( rc ){
        fossil_fatal("Before-commit hook failed\n");
      }
    }
  }

  /*
  ** Step 1: Compute an aggregate MD5 checksum over the disk image
  ** of every file in vid.  The file names are part of the checksum.
  ** The resulting checksum is the same as is expected on the R-card
  ** of a manifest.
  */