Fossil SCM

Add the new crnl-glob setting which defines files for which it is OK to have CRNL line endings. Windows projects on which this is preferred can set the crnl-glob pattern to '*'.

drh 2011-02-25 17:40 trunk
Commit 046658848c21cd54749a48bebe7719d62cc9ecef
+58 -4
--- src/checkin.c
+++ src/checkin.c
@@ -739,10 +739,61 @@
739739
md5sum_blob(pOut, &mcksum);
740740
blob_appendf(pOut, "Z %b\n", &mcksum);
741741
if( pnFBcard ) *pnFBcard = nFBcard;
742742
}
743743
744
+/*
745
+** Issue a warning and give the user an opportunity to abandon out
746
+** if a \r\n line ending is seen in a text file.
747
+*/
748
+static void cr_warning(const Blob *p, const char *zFilename){
749
+ int nCrNl = 0; /* Number of \r\n line endings seen */
750
+ const unsigned char *z; /* File text */
751
+ int n; /* Size of the file in bytes */
752
+ int lastNl = 0; /* Characters since last \n */
753
+ int i; /* Loop counter */
754
+ char *zMsg; /* Warning message */
755
+ Blob fname; /* Relative pathname of the file */
756
+ Blob ans; /* Answer to continue prompt */
757
+ static int allOk = 0; /* Set to true to disable this routine */
758
+
759
+ if( allOk ) return;
760
+ z = (unsigned char*)blob_buffer(p);
761
+ n = blob_size(p);
762
+ for(i=0; i<n-1; i++){
763
+ unsigned char c = z[i];
764
+ if( c==0 ) return; /* It's binary */
765
+ if( c=='\n' ){
766
+ if( i>0 && z[i-1]=='\r' ){
767
+ nCrNl++;
768
+ if( i>10000 ) break;
769
+ }
770
+ lastNl = 0;
771
+ }else{
772
+ lastNl++;
773
+ if( lastNl>1000 ) return; /* Binary if any line longer than 1000 */
774
+ }
775
+ }
776
+ if( nCrNl ){
777
+ char c;
778
+ file_relative_name(zFilename, &fname);
779
+ blob_zero(&ans);
780
+ zMsg = mprintf("%s contains CR/NL line endings; commit anyhow (y/N/a)?",
781
+ blob_str(&fname));
782
+ prompt_user(zMsg, &ans);
783
+ fossil_free(zMsg);
784
+ c = blob_str(&ans)[0];
785
+ if( c=='a' ){
786
+ allOk = 1;
787
+ }else if( c!='y' ){
788
+ fossil_fatal("Abandoning commit due to CR+NL line endings in %s",
789
+ blob_str(&fname));
790
+ }
791
+ blob_reset(&ans);
792
+ blob_reset(&fname);
793
+ }
794
+}
744795
745796
/*
746797
** COMMAND: ci
747798
** COMMAND: commit
748799
**
@@ -928,11 +979,11 @@
928979
db_blob(&unmodified,
929980
"SELECT pathname FROM vfile"
930981
" WHERE chnged = 0 AND origname IS NULL AND file_is_selected(id)"
931982
);
932983
if( strlen(blob_str(&unmodified)) ){
933
- fossil_panic("file %s has not changed", blob_str(&unmodified));
984
+ fossil_fatal("file %s has not changed", blob_str(&unmodified));
934985
}
935986
}
936987
937988
/*
938989
** Do not allow a commit that will cause a fork unless the --force flag
@@ -979,25 +1030,28 @@
9791030
/* Step 1: Insert records for all modified files into the blob
9801031
** table. If there were arguments passed to this command, only
9811032
** the identified fils are inserted (if they have been modified).
9821033
*/
9831034
db_prepare(&q,
984
- "SELECT id, %Q || pathname, mrid FROM vfile "
985
- "WHERE chnged==1 AND NOT deleted AND file_is_selected(id)"
986
- , g.zLocalRoot
1035
+ "SELECT id, %Q || pathname, mrid, %s FROM vfile "
1036
+ "WHERE chnged==1 AND NOT deleted AND file_is_selected(id)",
1037
+ g.zLocalRoot, glob_expr("pathname", db_get("crnl-glob",""))
9871038
);
9881039
while( db_step(&q)==SQLITE_ROW ){
9891040
int id, rid;
9901041
const char *zFullname;
9911042
Blob content;
1043
+ int crnlOk;
9921044
9931045
id = db_column_int(&q, 0);
9941046
zFullname = db_column_text(&q, 1);
9951047
rid = db_column_int(&q, 2);
1048
+ crnlOk = db_column_int(&q, 3);
9961049
9971050
blob_zero(&content);
9981051
blob_read_from_file(&content, zFullname);
1052
+ if( !crnlOk ) cr_warning(&content, zFullname);
9991053
nrid = content_put(&content);
10001054
blob_reset(&content);
10011055
if( rid>0 ){
10021056
content_deltify(rid, nrid, 0);
10031057
}
10041058
--- src/checkin.c
+++ src/checkin.c
@@ -739,10 +739,61 @@
739 md5sum_blob(pOut, &mcksum);
740 blob_appendf(pOut, "Z %b\n", &mcksum);
741 if( pnFBcard ) *pnFBcard = nFBcard;
742 }
743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744
745 /*
746 ** COMMAND: ci
747 ** COMMAND: commit
748 **
@@ -928,11 +979,11 @@
928 db_blob(&unmodified,
929 "SELECT pathname FROM vfile"
930 " WHERE chnged = 0 AND origname IS NULL AND file_is_selected(id)"
931 );
932 if( strlen(blob_str(&unmodified)) ){
933 fossil_panic("file %s has not changed", blob_str(&unmodified));
934 }
935 }
936
937 /*
938 ** Do not allow a commit that will cause a fork unless the --force flag
@@ -979,25 +1030,28 @@
979 /* Step 1: Insert records for all modified files into the blob
980 ** table. If there were arguments passed to this command, only
981 ** the identified fils are inserted (if they have been modified).
982 */
983 db_prepare(&q,
984 "SELECT id, %Q || pathname, mrid FROM vfile "
985 "WHERE chnged==1 AND NOT deleted AND file_is_selected(id)"
986 , g.zLocalRoot
987 );
988 while( db_step(&q)==SQLITE_ROW ){
989 int id, rid;
990 const char *zFullname;
991 Blob content;
 
992
993 id = db_column_int(&q, 0);
994 zFullname = db_column_text(&q, 1);
995 rid = db_column_int(&q, 2);
 
996
997 blob_zero(&content);
998 blob_read_from_file(&content, zFullname);
 
999 nrid = content_put(&content);
1000 blob_reset(&content);
1001 if( rid>0 ){
1002 content_deltify(rid, nrid, 0);
1003 }
1004
--- src/checkin.c
+++ src/checkin.c
@@ -739,10 +739,61 @@
739 md5sum_blob(pOut, &mcksum);
740 blob_appendf(pOut, "Z %b\n", &mcksum);
741 if( pnFBcard ) *pnFBcard = nFBcard;
742 }
743
744 /*
745 ** Issue a warning and give the user an opportunity to abandon out
746 ** if a \r\n line ending is seen in a text file.
747 */
748 static void cr_warning(const Blob *p, const char *zFilename){
749 int nCrNl = 0; /* Number of \r\n line endings seen */
750 const unsigned char *z; /* File text */
751 int n; /* Size of the file in bytes */
752 int lastNl = 0; /* Characters since last \n */
753 int i; /* Loop counter */
754 char *zMsg; /* Warning message */
755 Blob fname; /* Relative pathname of the file */
756 Blob ans; /* Answer to continue prompt */
757 static int allOk = 0; /* Set to true to disable this routine */
758
759 if( allOk ) return;
760 z = (unsigned char*)blob_buffer(p);
761 n = blob_size(p);
762 for(i=0; i<n-1; i++){
763 unsigned char c = z[i];
764 if( c==0 ) return; /* It's binary */
765 if( c=='\n' ){
766 if( i>0 && z[i-1]=='\r' ){
767 nCrNl++;
768 if( i>10000 ) break;
769 }
770 lastNl = 0;
771 }else{
772 lastNl++;
773 if( lastNl>1000 ) return; /* Binary if any line longer than 1000 */
774 }
775 }
776 if( nCrNl ){
777 char c;
778 file_relative_name(zFilename, &fname);
779 blob_zero(&ans);
780 zMsg = mprintf("%s contains CR/NL line endings; commit anyhow (y/N/a)?",
781 blob_str(&fname));
782 prompt_user(zMsg, &ans);
783 fossil_free(zMsg);
784 c = blob_str(&ans)[0];
785 if( c=='a' ){
786 allOk = 1;
787 }else if( c!='y' ){
788 fossil_fatal("Abandoning commit due to CR+NL line endings in %s",
789 blob_str(&fname));
790 }
791 blob_reset(&ans);
792 blob_reset(&fname);
793 }
794 }
795
796 /*
797 ** COMMAND: ci
798 ** COMMAND: commit
799 **
@@ -928,11 +979,11 @@
979 db_blob(&unmodified,
980 "SELECT pathname FROM vfile"
981 " WHERE chnged = 0 AND origname IS NULL AND file_is_selected(id)"
982 );
983 if( strlen(blob_str(&unmodified)) ){
984 fossil_fatal("file %s has not changed", blob_str(&unmodified));
985 }
986 }
987
988 /*
989 ** Do not allow a commit that will cause a fork unless the --force flag
@@ -979,25 +1030,28 @@
1030 /* Step 1: Insert records for all modified files into the blob
1031 ** table. If there were arguments passed to this command, only
1032 ** the identified fils are inserted (if they have been modified).
1033 */
1034 db_prepare(&q,
1035 "SELECT id, %Q || pathname, mrid, %s FROM vfile "
1036 "WHERE chnged==1 AND NOT deleted AND file_is_selected(id)",
1037 g.zLocalRoot, glob_expr("pathname", db_get("crnl-glob",""))
1038 );
1039 while( db_step(&q)==SQLITE_ROW ){
1040 int id, rid;
1041 const char *zFullname;
1042 Blob content;
1043 int crnlOk;
1044
1045 id = db_column_int(&q, 0);
1046 zFullname = db_column_text(&q, 1);
1047 rid = db_column_int(&q, 2);
1048 crnlOk = db_column_int(&q, 3);
1049
1050 blob_zero(&content);
1051 blob_read_from_file(&content, zFullname);
1052 if( !crnlOk ) cr_warning(&content, zFullname);
1053 nrid = content_put(&content);
1054 blob_reset(&content);
1055 if( rid>0 ){
1056 content_deltify(rid, nrid, 0);
1057 }
1058
--- src/configure.c
+++ src/configure.c
@@ -76,10 +76,11 @@
7676
{ "logo-image", CONFIGSET_SKIN },
7777
{ "project-name", CONFIGSET_PROJ },
7878
{ "project-description", CONFIGSET_PROJ },
7979
{ "manifest", CONFIGSET_PROJ },
8080
{ "ignore-glob", CONFIGSET_PROJ },
81
+ { "crnl-glob", CONFIGSET_PROJ },
8182
{ "index-page", CONFIGSET_SKIN },
8283
{ "timeline-block-markup", CONFIGSET_SKIN },
8384
{ "timeline-max-comment", CONFIGSET_SKIN },
8485
{ "ticket-table", CONFIGSET_TKT },
8586
{ "ticket-common", CONFIGSET_TKT },
8687
--- src/configure.c
+++ src/configure.c
@@ -76,10 +76,11 @@
76 { "logo-image", CONFIGSET_SKIN },
77 { "project-name", CONFIGSET_PROJ },
78 { "project-description", CONFIGSET_PROJ },
79 { "manifest", CONFIGSET_PROJ },
80 { "ignore-glob", CONFIGSET_PROJ },
 
81 { "index-page", CONFIGSET_SKIN },
82 { "timeline-block-markup", CONFIGSET_SKIN },
83 { "timeline-max-comment", CONFIGSET_SKIN },
84 { "ticket-table", CONFIGSET_TKT },
85 { "ticket-common", CONFIGSET_TKT },
86
--- src/configure.c
+++ src/configure.c
@@ -76,10 +76,11 @@
76 { "logo-image", CONFIGSET_SKIN },
77 { "project-name", CONFIGSET_PROJ },
78 { "project-description", CONFIGSET_PROJ },
79 { "manifest", CONFIGSET_PROJ },
80 { "ignore-glob", CONFIGSET_PROJ },
81 { "crnl-glob", CONFIGSET_PROJ },
82 { "index-page", CONFIGSET_SKIN },
83 { "timeline-block-markup", CONFIGSET_SKIN },
84 { "timeline-max-comment", CONFIGSET_SKIN },
85 { "ticket-table", CONFIGSET_TKT },
86 { "ticket-common", CONFIGSET_TKT },
87
+5
--- src/db.c
+++ src/db.c
@@ -1619,10 +1619,11 @@
16191619
{ "auto-captcha", "autocaptcha", 0, "on" },
16201620
{ "auto-shun", 0, 0, "on" },
16211621
{ "autosync", 0, 0, "on" },
16221622
{ "binary-glob", 0, 32, "" },
16231623
{ "clearsign", 0, 0, "off" },
1624
+ { "crnl-glob", 0, 16, "" },
16241625
{ "default-perms", 0, 16, "u" },
16251626
{ "diff-command", 0, 16, "" },
16261627
{ "dont-push", 0, 0, "off" },
16271628
{ "editor", 0, 16, "" },
16281629
{ "gdiff-command", 0, 16, "gdiff" },
@@ -1674,10 +1675,14 @@
16741675
** purposes. Example: *.xml
16751676
**
16761677
** clearsign When enabled, fossil will attempt to sign all commits
16771678
** with gpg. When disabled (the default), commits will
16781679
** be unsigned. Default: off
1680
+**
1681
+** crnl-glob A comma-separated list of GLOB patterns for text files
1682
+** in which it is ok to have CR+NL line endings.
1683
+** Set to "*" to disable CR+NL checking.
16791684
**
16801685
** default-perms Permissions given automatically to new users. For more
16811686
** information on permissions see Users page in Server
16821687
** Administration of the HTTP UI. Default: u.
16831688
**
16841689
--- src/db.c
+++ src/db.c
@@ -1619,10 +1619,11 @@
1619 { "auto-captcha", "autocaptcha", 0, "on" },
1620 { "auto-shun", 0, 0, "on" },
1621 { "autosync", 0, 0, "on" },
1622 { "binary-glob", 0, 32, "" },
1623 { "clearsign", 0, 0, "off" },
 
1624 { "default-perms", 0, 16, "u" },
1625 { "diff-command", 0, 16, "" },
1626 { "dont-push", 0, 0, "off" },
1627 { "editor", 0, 16, "" },
1628 { "gdiff-command", 0, 16, "gdiff" },
@@ -1674,10 +1675,14 @@
1674 ** purposes. Example: *.xml
1675 **
1676 ** clearsign When enabled, fossil will attempt to sign all commits
1677 ** with gpg. When disabled (the default), commits will
1678 ** be unsigned. Default: off
 
 
 
 
1679 **
1680 ** default-perms Permissions given automatically to new users. For more
1681 ** information on permissions see Users page in Server
1682 ** Administration of the HTTP UI. Default: u.
1683 **
1684
--- src/db.c
+++ src/db.c
@@ -1619,10 +1619,11 @@
1619 { "auto-captcha", "autocaptcha", 0, "on" },
1620 { "auto-shun", 0, 0, "on" },
1621 { "autosync", 0, 0, "on" },
1622 { "binary-glob", 0, 32, "" },
1623 { "clearsign", 0, 0, "off" },
1624 { "crnl-glob", 0, 16, "" },
1625 { "default-perms", 0, 16, "u" },
1626 { "diff-command", 0, 16, "" },
1627 { "dont-push", 0, 0, "off" },
1628 { "editor", 0, 16, "" },
1629 { "gdiff-command", 0, 16, "gdiff" },
@@ -1674,10 +1675,14 @@
1675 ** purposes. Example: *.xml
1676 **
1677 ** clearsign When enabled, fossil will attempt to sign all commits
1678 ** with gpg. When disabled (the default), commits will
1679 ** be unsigned. Default: off
1680 **
1681 ** crnl-glob A comma-separated list of GLOB patterns for text files
1682 ** in which it is ok to have CR+NL line endings.
1683 ** Set to "*" to disable CR+NL checking.
1684 **
1685 ** default-perms Permissions given automatically to new users. For more
1686 ** information on permissions see Users page in Server
1687 ** Administration of the HTTP UI. Default: u.
1688 **
1689

Keyboard Shortcuts

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