Fossil

Changes On Branch cr-warning
Login

Changes On Branch cr-warning

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

Changes In Branch cr-warning Excluding Merge-Ins

This is equivalent to a diff from 276b3495 to 5a886cfd

2013-03-19
08:59
Merge "cr-warning" branch to trunk: Fossil now warns before committing files with CR line-endings and offers to convert them to LF line-endings; fossil's diff cannot handle those. In checkin.c, use LOOK_BINARY in stead of LOOK_NUL, in case more flags are added to the BINARY detection. Rename LOOK_LENGTH to LOOK_LONG. ... (check-in: ea2598e4 user: jan.nijtmans tags: trunk)
2013-03-15
14:07
Fix ticket [38cecac15f]: test-move-repository requires access to original repository ... (check-in: e5905473 user: jan.nijtmans tags: trunk)
12:53
(expirimental) First implementation of "CR line endings" warning. ... (Closed-Leaf check-in: 5a886cfd user: jan.nijtmans tags: cr-warning)
12:29
merge trunk ... (Closed-Leaf check-in: 59f26447 user: jan.nijtmans tags: bomRefactor)
12:23
Don't let looks_like_utf8/16 decide any more whether the blob is text or binary. Calling code can do that based on the returned flags. This simplifies looks_like_utf8/16 a lot. ... (check-in: 276b3495 user: jan.nijtmans tags: trunk)
11:32
Allow blob_remove_cr() to be used for both \r\n -> \n as well as \r -> \n conversions. ... (check-in: 4b2c2a51 user: jan.nijtmans tags: trunk)

Changes to src/checkin.c.

905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946


947

948
949

950
951
952
953
954
955
956



957

958
959
960
961
962



963

964
965
966
967
968
969
970
  int crnlOk,           /* Non-zero if CR/NL warnings should be disabled. */
  int binOk,            /* Non-zero if binary warnings should be disabled. */
  int encodingOk,        /* Non-zero if encoding warnings should be disabled. */
  const char *zFilename /* The full name of the file being committed. */
){
  int fUnicode;           /* return value of starts_with_utf16_bom() */
  int lookFlags;          /* output flags from looks_like_utf8/utf16() */
  int fHasNul;            /* the blob contains one or more NUL chars */
  int fHasCrLf;           /* the blob contains one or more CR/LF pairs */
  int fHasLength;         /* the blob contains an overly long line */
  char *zMsg;             /* Warning message */
  Blob fname;             /* Relative pathname of the file */
  static int allOk = 0;   /* Set to true to disable this routine */

  if( allOk ) return 0;
  fUnicode = starts_with_utf16_bom(p, 0, 0);
  if( fUnicode ){
    lookFlags = looks_like_utf16(p);
    if( lookFlags&LOOK_ODD ){
      /* Content with an odd number of bytes cannot be UTF-16. */
      fUnicode = 0;
      /* Therefore, check if the content appears to be UTF-8. */
      lookFlags = looks_like_utf8(p);
    }
  }else{
    lookFlags = looks_like_utf8(p);
  }
  fHasNul = (lookFlags & LOOK_NUL);
  fHasCrLf = (lookFlags & LOOK_CRLF);
  fHasLength = (lookFlags & LOOK_LENGTH);
  if( fHasNul || fHasLength || fHasCrLf || fUnicode ){
    const char *zWarning;
    const char *zDisable;
    const char *zConvert = "c=convert/";
    Blob ans;
    char cReply;

    if( fHasNul || fHasLength ){
      if( binOk ){
        return 0; /* We don't want binary warnings for this file. */
      }
      if( !fHasNul && fHasLength ){


        zWarning = "long lines";

      }else{
        zWarning = "binary data";

      }
      zDisable = "\"binary-glob\" setting";
      zConvert = ""; /* We cannot convert binary files. */
    }else if( fHasCrLf && fUnicode ){
      if( crnlOk && encodingOk ){
        return 0; /* We don't want CR/NL and Unicode warnings for this file. */
      }



      zWarning = "CR/NL line endings and Unicode";

      zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
    }else if( fHasCrLf ){
      if( crnlOk ){
        return 0; /* We don't want CR/NL warnings for this file. */
      }



      zWarning = "CR/NL line endings";

      zDisable = "\"crnl-glob\" setting";
    }else{
      if( encodingOk ){
        return 0; /* We don't want encoding warnings for this file. */
      }
      zWarning = "Unicode";
      zDisable = "\"encoding-glob\" setting";







<
<
<

















|
<
<
<






|



|
>
>

>


>


<
|



>
>
>
|
>

|



>
>
>
|
>







905
906
907
908
909
910
911



912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929



930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949

950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
  int crnlOk,           /* Non-zero if CR/NL warnings should be disabled. */
  int binOk,            /* Non-zero if binary warnings should be disabled. */
  int encodingOk,        /* Non-zero if encoding warnings should be disabled. */
  const char *zFilename /* The full name of the file being committed. */
){
  int fUnicode;           /* return value of starts_with_utf16_bom() */
  int lookFlags;          /* output flags from looks_like_utf8/utf16() */



  char *zMsg;             /* Warning message */
  Blob fname;             /* Relative pathname of the file */
  static int allOk = 0;   /* Set to true to disable this routine */

  if( allOk ) return 0;
  fUnicode = starts_with_utf16_bom(p, 0, 0);
  if( fUnicode ){
    lookFlags = looks_like_utf16(p);
    if( lookFlags&LOOK_ODD ){
      /* Content with an odd number of bytes cannot be UTF-16. */
      fUnicode = 0;
      /* Therefore, check if the content appears to be UTF-8. */
      lookFlags = looks_like_utf8(p);
    }
  }else{
    lookFlags = looks_like_utf8(p);
  }
  if( lookFlags&(LOOK_NUL|LOOK_LENGTH|LOOK_LONE_CR|LOOK_CRLF) || fUnicode ){



    const char *zWarning;
    const char *zDisable;
    const char *zConvert = "c=convert/";
    Blob ans;
    char cReply;

    if( lookFlags&(LOOK_NUL|LOOK_LENGTH) ){
      if( binOk ){
        return 0; /* We don't want binary warnings for this file. */
      }
      if( (lookFlags&LOOK_LONE_CR) && !(lookFlags&LOOK_NUL) ){
        zWarning = "CR line endings (would be handled as binary)";
      }else if( (lookFlags&LOOK_LENGTH) && !(lookFlags&LOOK_NUL) ){
        zWarning = "long lines";
        zConvert = ""; /* We cannot convert binary files. */
      }else{
        zWarning = "binary data";
        zConvert = ""; /* We cannot convert binary files. */
      }
      zDisable = "\"binary-glob\" setting";

    }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) && fUnicode ){
      if( crnlOk && encodingOk ){
        return 0; /* We don't want CR/NL and Unicode warnings for this file. */
      }
      if( lookFlags&LOOK_LONE_CR ){
        zWarning = "CR line endings and Unicode";
      }else{
        zWarning = "CR/NL line endings and Unicode";
      }
      zDisable = "\"crnl-glob\" and \"encoding-glob\" settings";
    }else if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){
      if( crnlOk ){
        return 0; /* We don't want CR/NL warnings for this file. */
      }
      if( lookFlags&LOOK_LONE_CR ){
        zWarning = "CR line endings";
      }else{
        zWarning = "CR/NL line endings";
      }
      zDisable = "\"crnl-glob\" setting";
    }else{
      if( encodingOk ){
        return 0; /* We don't want encoding warnings for this file. */
      }
      zWarning = "Unicode";
      zDisable = "\"encoding-glob\" setting";
991
992
993
994
995
996
997

998

999
1000
1001
1002
1003
1004
1005
      f = fossil_fopen(zFilename, "wb");
      if( fUnicode ) {
        int bomSize;
        const unsigned char *bom = get_utf8_bom(&bomSize);
        fwrite(bom, 1, bomSize, f);
        blob_to_utf8_no_bom(p, 0);
      }

      blob_remove_cr(p);

      fwrite(blob_buffer(p), 1, blob_size(p), f);
      fclose(f);
      return 1;
    }else if( cReply!='y' && cReply!='Y' ){
      fossil_fatal("Abandoning commit due to %s in %s",
                   zWarning, blob_str(&fname));
    }







>
|
>







996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
      f = fossil_fopen(zFilename, "wb");
      if( fUnicode ) {
        int bomSize;
        const unsigned char *bom = get_utf8_bom(&bomSize);
        fwrite(bom, 1, bomSize, f);
        blob_to_utf8_no_bom(p, 0);
      }
      if( lookFlags&(LOOK_LONE_CR|LOOK_CRLF) ){
        blob_remove_cr(p);
      }
      fwrite(blob_buffer(p), 1, blob_size(p), f);
      fclose(f);
      return 1;
    }else if( cReply!='y' && cReply!='Y' ){
      fossil_fatal("Abandoning commit due to %s in %s",
                   zWarning, blob_str(&fname));
    }