Fossil

Check-in [41561125cd]
Login

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

Overview
Comment:Added safemerge option to commit, update and settings
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 41561125cd744d8b1adbc7a7fb6f0cb0a32571a1
User & Date: jnc 2007-09-26 04:17:37.000
Context
2007-09-26
12:21
Fix a bug in clone - have it open the global settings database file so that it can access the default-user setting. check-in: cbe0ace8f3 user: drh tags: trunk
04:17
Added safemerge option to commit, update and settings check-in: 41561125cd user: jnc tags: trunk
03:38
Merged in new revision support for diff and revert commands into mainstream check-in: 8d55aa3597 user: jnc tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/branch.c.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  Blob manifest;
  Blob mcksum;           /* Self-checksum on the manifest */
  Blob cksum1, cksum2;   /* Before and after commit checksums */
  Blob cksum1b;          /* Checksum recorded in the manifest */
 
  noSign = find_option("nosign","",0)!=0;
  db_must_be_within_tree();
  noSign = db_get_int("omit-ci-sig", 0)|noSign;
  zColor = find_option("bgcolor","c",1);
  
  verify_all_options();
  
  /* fossil branch new name */
  if( g.argc<3 ){
    usage("branch new ?-bgcolor COLOR BRANCH-NAME");







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  Blob manifest;
  Blob mcksum;           /* Self-checksum on the manifest */
  Blob cksum1, cksum2;   /* Before and after commit checksums */
  Blob cksum1b;          /* Checksum recorded in the manifest */
 
  noSign = find_option("nosign","",0)!=0;
  db_must_be_within_tree();
  noSign = db_get_int("omit-sign", 0)|noSign;
  zColor = find_option("bgcolor","c",1);
  
  verify_all_options();
  
  /* fossil branch new name */
  if( g.argc<3 ){
    usage("branch new ?-bgcolor COLOR BRANCH-NAME");
Changes to src/checkin.c.
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
** prompted for your GPG passphrase in order to sign the new manifest
** unless the "--nosign" options is used.  All files that have
** changed will be committed unless some subset of files is specified
** on the command line.
*/
void commit_cmd(void){
  int rc;
  int vid, nrid, nvid;
  Blob comment;
  const char *zComment;
  Stmt q;
  Stmt q2;
  char *zUuid, *zDate;
  int noSign = 0;        /* True to omit signing the manifest using GPG */
  int isAMerge = 0;      /* True if checking in a merge */
  int forceFlag = 0;     /* Force a fork */
  char *zManifestFile;   /* Name of the manifest file */
  Blob manifest;
  Blob muuid;            /* Manifest uuid */
  Blob mcksum;           /* Self-checksum on the manifest */
  Blob cksum1, cksum2;   /* Before and after commit checksums */
  Blob cksum1b;          /* Checksum recorded in the manifest */
 
  noSign = find_option("nosign","",0)!=0;
  zComment = find_option("comment","m",1);
  forceFlag = find_option("force", "r", 0)!=0;
  db_must_be_within_tree();
  noSign = db_get_int("omit-ci-sig", 0)|noSign;
  verify_all_options();
  
  /*
  ** Autosync if requested.
  */
  autosync(1);
  







|



















|







313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
** prompted for your GPG passphrase in order to sign the new manifest
** unless the "--nosign" options is used.  All files that have
** changed will be committed unless some subset of files is specified
** on the command line.
*/
void commit_cmd(void){
  int rc;
  int vid, nrid, nvid, wouldFork=0;
  Blob comment;
  const char *zComment;
  Stmt q;
  Stmt q2;
  char *zUuid, *zDate;
  int noSign = 0;        /* True to omit signing the manifest using GPG */
  int isAMerge = 0;      /* True if checking in a merge */
  int forceFlag = 0;     /* Force a fork */
  char *zManifestFile;   /* Name of the manifest file */
  Blob manifest;
  Blob muuid;            /* Manifest uuid */
  Blob mcksum;           /* Self-checksum on the manifest */
  Blob cksum1, cksum2;   /* Before and after commit checksums */
  Blob cksum1b;          /* Checksum recorded in the manifest */
 
  noSign = find_option("nosign","",0)!=0;
  zComment = find_option("comment","m",1);
  forceFlag = find_option("force", "r", 0)!=0;
  db_must_be_within_tree();
  noSign = db_get_int("omit-sign", 0)|noSign;
  verify_all_options();
  
  /*
  ** Autosync if requested.
  */
  autosync(1);
  
380
381
382
383
384
385
386
387


388

389
390
391
392
393
394
395
    );
    if( strlen(blob_str(&unmodified)) ){
      fossil_panic("file %s has not changed", blob_str(&unmodified));
    }
  }

  vid = db_lget_int("checkout", 0);
  if( !forceFlag && db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){


    fossil_fatal("would fork.  use -f or --force");

  }
  vfile_aggregate_checksum_disk(vid, &cksum1);
  if( zComment ){
    blob_zero(&comment);
    blob_append(&comment, zComment, -1);
  }else{
    prepare_commit_comment(&comment);







|
>
>
|
>







380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
    );
    if( strlen(blob_str(&unmodified)) ){
      fossil_panic("file %s has not changed", blob_str(&unmodified));
    }
  }

  vid = db_lget_int("checkout", 0);
  if( db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
    wouldFork=1;
    if( forceFlag==0 && db_get_int("safemerge", 0)==0 ){
      fossil_fatal("would fork.  use -f or --force");
    }
  }
  vfile_aggregate_checksum_disk(vid, &cksum1);
  if( zComment ){
    blob_zero(&comment);
    blob_append(&comment, zComment, -1);
  }else{
    prepare_commit_comment(&comment);
532
533
534
535
536
537
538

539




540



541


  /* Clear the undo/redo stack */
  undo_reset();

  /* Commit */
  db_end_transaction(0);
  

  /* Do an autosync push if requested */




  autosync(0);



}








>
|
>
>
>
>
|
>
>
>
|
>
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553

  /* Clear the undo/redo stack */
  undo_reset();

  /* Commit */
  db_end_transaction(0);
  
  if( wouldFork==0 ){
    /* Do an autosync push if requested. If wouldFork == 1, then they either
    ** forced this commit or safe merge is on, and this commit did indeed
    ** create a fork. In this case, we want the user to merge before sending
    ** their new commit back to the rest of the world, so do not auto-push.
    */
    autosync(0);
  }else{
    printf("Warning: commit caused a fork to occur. Please merge and push\n");
    printf("         your changes as soon as possible.\n");
  }
}
Changes to src/db.c.
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698

699
700
701
702
703
704
705
** not server and project codes are invented for this repository.
*/
void db_initial_setup (int makeInitialVersion, int makeServerCodes){
  char *zDate;
  char *zUser;
  Blob hash;
  Blob manifest;

  db_set("content-schema", CONTENT_SCHEMA);
  db_set("aux-schema", AUX_SCHEMA);
  if( makeServerCodes ){
    db_multi_exec(
      "INSERT INTO config(name,value)"
      " VALUES('server-code', lower(hex(randomblob(20))));"
      "INSERT INTO config(name,value)"
      " VALUES('project-code', lower(hex(randomblob(20))));"
    );
  }
  db_set_int("autosync", 1);

  db_set_int("localauth", 0);
  zUser = db_global_get("default-user", 0);
  if( zUser==0 ){
    zUser = getenv("USER");
  }
  if( zUser==0 ){
    zUser = "root";







|











>







680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
** not server and project codes are invented for this repository.
*/
void db_initial_setup (int makeInitialVersion, int makeServerCodes){
  char *zDate;
  char *zUser;
  Blob hash;
  Blob manifest;
  
  db_set("content-schema", CONTENT_SCHEMA);
  db_set("aux-schema", AUX_SCHEMA);
  if( makeServerCodes ){
    db_multi_exec(
      "INSERT INTO config(name,value)"
      " VALUES('server-code', lower(hex(randomblob(20))));"
      "INSERT INTO config(name,value)"
      " VALUES('project-code', lower(hex(randomblob(20))));"
    );
  }
  db_set_int("autosync", 1);
  db_set_int("safemerge", 0);
  db_set_int("localauth", 0);
  zUser = db_global_get("default-user", 0);
  if( zUser==0 ){
    zUser = getenv("USER");
  }
  if( zUser==0 ){
    zUser = "root";
916
917
918
919
920
921
922



923
924
925
926
927
928
929
**
** Recognized settings include:
**
**   editor        Text editor command used for check-in comments.
**
**   clear-sign    Command used to clear-sign manifests at check-in.
**                 The default is "gpg --clearsign -o ".



*/
void cmd_config(void){
  db_open_config();
  if( g.argc>2 ){
    int i;
    db_begin_transaction();
    for(i=2; i<g.argc; i++){







>
>
>







917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
**
** Recognized settings include:
**
**   editor        Text editor command used for check-in comments.
**
**   clear-sign    Command used to clear-sign manifests at check-in.
**                 The default is "gpg --clearsign -o ".
**
**   omit-sign     When enabled, fossil will not attempt to sign any
**                 commit with gpg. All commits will be unsigned.
*/
void cmd_config(void){
  db_open_config();
  if( g.argc>2 ){
    int i;
    db_begin_transaction();
    for(i=2; i<g.argc; i++){
972
973
974
975
976
977
978
979
980
981
982




983
984
985
986
987

988
989
990
991
992
993
994
** a property name, show the value of that property.  With a value
** argument, change the property for the current repository.
**
**    autosync         If enabled, automatically pull prior to
**                     commit or update and automatically push
**                     after commit or tag or branch creation.
**
**    localauth        If true, require that HTTP connections from
**                     127.0.0.1 be authenticated by password.  If
**                     false, all HTTP requests from localhost have
**                     unrestricted access to the repository.




*/
void setting_cmd(void){
  static const char *azName[] = {
    "autosync",
    "localauth"

  };
  int i;
  db_find_and_open_repository();
  if( g.argc==2 ){
    for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
      printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
    }







|



>
>
>
>




|
>







976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
** a property name, show the value of that property.  With a value
** argument, change the property for the current repository.
**
**    autosync         If enabled, automatically pull prior to
**                     commit or update and automatically push
**                     after commit or tag or branch creation.
**
**    localauth        If enabled, require that HTTP connections from
**                     127.0.0.1 be authenticated by password.  If
**                     false, all HTTP requests from localhost have
**                     unrestricted access to the repository.
**
**    safemerge        If enabled, when commit will cause a fork, the
**                     commit will not abort with warning. Also update
**                     will not be allowed if local changes exist.
*/
void setting_cmd(void){
  static const char *azName[] = {
    "autosync",
    "localauth",
    "safemerge",
  };
  int i;
  db_find_and_open_repository();
  if( g.argc==2 ){
    for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
      printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
    }
Changes to src/update.c.
63
64
65
66
67
68
69



70
71
72
73
74
75
76
77
78
79
80


81




82
83

84
85
86
87
88
89
90
  vid = db_lget_int("checkout", 0);
  if( vid==0 ){
    fossil_fatal("cannot find current version");
  }
  if( db_exists("SELECT 1 FROM vmerge") ){
    fossil_fatal("cannot update an uncommitted merge");
  }



      
  if( g.argc==3 ){
    tid = name_to_rid(g.argv[2]);
    if( tid==0 ){
      fossil_fatal("not a version: %s", g.argv[2]);
    }
    if( !is_a_version(tid) ){
      fossil_fatal("not a version: %s", g.argv[2]);
    }
  }



  /* Do an autosync pull prior to the update, if autosync is on */




  autosync(1);


  if( tid==0 ){
    compute_leaves(vid);
    if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
      db_prepare(&q, 
        "%s "
        "   AND event.objid IN leaves"
        " ORDER BY event.mtime DESC",







>
>
>











>
>
|
>
>
>
>
|
|
>







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  vid = db_lget_int("checkout", 0);
  if( vid==0 ){
    fossil_fatal("cannot find current version");
  }
  if( db_exists("SELECT 1 FROM vmerge") ){
    fossil_fatal("cannot update an uncommitted merge");
  }
  if( unsaved_changes() && db_get_int("safemerge", 0) ){
    fossil_fatal("you have uncommitted changes and safemerge is enabled");
  }
      
  if( g.argc==3 ){
    tid = name_to_rid(g.argv[2]);
    if( tid==0 ){
      fossil_fatal("not a version: %s", g.argv[2]);
    }
    if( !is_a_version(tid) ){
      fossil_fatal("not a version: %s", g.argv[2]);
    }
  }

  if( tid==0 ){
    /* 
    ** Do an autosync pull prior to the update, if autosync is on and they
    ** did not want a specific version (i.e. another branch, a past revision).
    ** By not giving a specific version, they are asking for the latest, thus
    ** pull to get the latest, then update.
    */
    autosync(1);
  }
  
  if( tid==0 ){
    compute_leaves(vid);
    if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
      db_prepare(&q, 
        "%s "
        "   AND event.objid IN leaves"
        " ORDER BY event.mtime DESC",