Fossil SCM
When "fossil set editor" is unset and when there is no EDITOR or VISUAL environment variable set, then gather the check-in comment from standard input (with appropriate prompting) rather than trying to run "ed" or "notepad".
Commit
aa929c4d1e8e9e9a7e27ae81088d347c054460c8
Parent
115d90d8b0aab28…
1 file changed
+28
-21
+28
-21
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -411,36 +411,43 @@ | ||
| 411 | 411 | } |
| 412 | 412 | if( zEditor==0 ){ |
| 413 | 413 | zEditor = getenv("EDITOR"); |
| 414 | 414 | } |
| 415 | 415 | if( zEditor==0 ){ |
| 416 | -#if defined(_WIN32) | |
| 417 | - zEditor = "notepad"; | |
| 418 | - fossil_warning( | |
| 419 | - "no default text editor selected using \"fossil set editor\"\n" | |
| 420 | - "or the EDITOR or VISUAL environment variables - using \"notepad\""); | |
| 421 | -#else | |
| 422 | - zEditor = "ed"; | |
| 423 | - fossil_warning( | |
| 424 | - "no default text editor selected using \"fossil set editor\"\n" | |
| 425 | - "or the EDITOR or VISUAL environment variables - using \"ed\" -\n" | |
| 426 | - "enter \"q\" to quit."); | |
| 427 | -#endif | |
| 428 | - } | |
| 429 | - zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'", | |
| 430 | - g.zLocalRoot); | |
| 416 | + blob_append(&text, | |
| 417 | + "#\n" | |
| 418 | + "# Since no default text editor is set using EDITOR or VISUAL\n" | |
| 419 | + "# environment variables or the \"fossil set editor\" command,\n" | |
| 420 | + "# and because no check-in comment was specified using the \"-m\"\n" | |
| 421 | + "# or \"-M\" command-line options, you will need to enter the\n" | |
| 422 | + "# check-in comment below. Type \".\" on a line by itself when\n" | |
| 423 | + "# you are done:\n", -1); | |
| 424 | + zFile = mprintf("-"); | |
| 425 | + }else{ | |
| 426 | + zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'", | |
| 427 | + g.zLocalRoot); | |
| 428 | + } | |
| 431 | 429 | #if defined(_WIN32) |
| 432 | 430 | blob_add_cr(&text); |
| 433 | 431 | #endif |
| 434 | 432 | blob_write_to_file(&text, zFile); |
| 435 | - zCmd = mprintf("%s \"%s\"", zEditor, zFile); | |
| 436 | - printf("%s\n", zCmd); | |
| 437 | - if( fossil_system(zCmd) ){ | |
| 438 | - fossil_panic("editor aborted"); | |
| 433 | + if( zEditor ){ | |
| 434 | + zCmd = mprintf("%s \"%s\"", zEditor, zFile); | |
| 435 | + printf("%s\n", zCmd); | |
| 436 | + if( fossil_system(zCmd) ){ | |
| 437 | + fossil_panic("editor aborted"); | |
| 438 | + } | |
| 439 | + blob_reset(&text); | |
| 440 | + blob_read_from_file(&text, zFile); | |
| 441 | + }else{ | |
| 442 | + char zIn[300]; | |
| 443 | + blob_reset(&text); | |
| 444 | + while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ | |
| 445 | + if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ) break; | |
| 446 | + blob_append(&text, zIn, -1); | |
| 447 | + } | |
| 439 | 448 | } |
| 440 | - blob_reset(&text); | |
| 441 | - blob_read_from_file(&text, zFile); | |
| 442 | 449 | blob_remove_cr(&text); |
| 443 | 450 | unlink(zFile); |
| 444 | 451 | free(zFile); |
| 445 | 452 | blob_zero(pComment); |
| 446 | 453 | while( blob_line(&text, &line) ){ |
| 447 | 454 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -411,36 +411,43 @@ | |
| 411 | } |
| 412 | if( zEditor==0 ){ |
| 413 | zEditor = getenv("EDITOR"); |
| 414 | } |
| 415 | if( zEditor==0 ){ |
| 416 | #if defined(_WIN32) |
| 417 | zEditor = "notepad"; |
| 418 | fossil_warning( |
| 419 | "no default text editor selected using \"fossil set editor\"\n" |
| 420 | "or the EDITOR or VISUAL environment variables - using \"notepad\""); |
| 421 | #else |
| 422 | zEditor = "ed"; |
| 423 | fossil_warning( |
| 424 | "no default text editor selected using \"fossil set editor\"\n" |
| 425 | "or the EDITOR or VISUAL environment variables - using \"ed\" -\n" |
| 426 | "enter \"q\" to quit."); |
| 427 | #endif |
| 428 | } |
| 429 | zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'", |
| 430 | g.zLocalRoot); |
| 431 | #if defined(_WIN32) |
| 432 | blob_add_cr(&text); |
| 433 | #endif |
| 434 | blob_write_to_file(&text, zFile); |
| 435 | zCmd = mprintf("%s \"%s\"", zEditor, zFile); |
| 436 | printf("%s\n", zCmd); |
| 437 | if( fossil_system(zCmd) ){ |
| 438 | fossil_panic("editor aborted"); |
| 439 | } |
| 440 | blob_reset(&text); |
| 441 | blob_read_from_file(&text, zFile); |
| 442 | blob_remove_cr(&text); |
| 443 | unlink(zFile); |
| 444 | free(zFile); |
| 445 | blob_zero(pComment); |
| 446 | while( blob_line(&text, &line) ){ |
| 447 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -411,36 +411,43 @@ | |
| 411 | } |
| 412 | if( zEditor==0 ){ |
| 413 | zEditor = getenv("EDITOR"); |
| 414 | } |
| 415 | if( zEditor==0 ){ |
| 416 | blob_append(&text, |
| 417 | "#\n" |
| 418 | "# Since no default text editor is set using EDITOR or VISUAL\n" |
| 419 | "# environment variables or the \"fossil set editor\" command,\n" |
| 420 | "# and because no check-in comment was specified using the \"-m\"\n" |
| 421 | "# or \"-M\" command-line options, you will need to enter the\n" |
| 422 | "# check-in comment below. Type \".\" on a line by itself when\n" |
| 423 | "# you are done:\n", -1); |
| 424 | zFile = mprintf("-"); |
| 425 | }else{ |
| 426 | zFile = db_text(0, "SELECT '%qci-comment-' || hex(randomblob(6)) || '.txt'", |
| 427 | g.zLocalRoot); |
| 428 | } |
| 429 | #if defined(_WIN32) |
| 430 | blob_add_cr(&text); |
| 431 | #endif |
| 432 | blob_write_to_file(&text, zFile); |
| 433 | if( zEditor ){ |
| 434 | zCmd = mprintf("%s \"%s\"", zEditor, zFile); |
| 435 | printf("%s\n", zCmd); |
| 436 | if( fossil_system(zCmd) ){ |
| 437 | fossil_panic("editor aborted"); |
| 438 | } |
| 439 | blob_reset(&text); |
| 440 | blob_read_from_file(&text, zFile); |
| 441 | }else{ |
| 442 | char zIn[300]; |
| 443 | blob_reset(&text); |
| 444 | while( fgets(zIn, sizeof(zIn), stdin)!=0 ){ |
| 445 | if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ) break; |
| 446 | blob_append(&text, zIn, -1); |
| 447 | } |
| 448 | } |
| 449 | blob_remove_cr(&text); |
| 450 | unlink(zFile); |
| 451 | free(zFile); |
| 452 | blob_zero(pComment); |
| 453 | while( blob_line(&text, &line) ){ |
| 454 |