Fossil

Check-in [4f060f6a]
Login

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

Overview
Comment:Add optional iso8859-1 to utf-8 conversion. Still to do: special cp1252 characters.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | improve_commit_warning
Files: files | file ages | folders
SHA1:4f060f6afb7d7a1cc268ce3b8b6a1b5180393152
User & Date: jan.nijtmans 2012-12-12 13:53:35
Context
2012-12-12
15:35
completed cp1252 table and conversion check-in: bab2f28b user: jan.nijtmans tags: improve_commit_warning
13:53
Add optional iso8859-1 to utf-8 conversion. Still to do: special cp1252 characters. check-in: 4f060f6a user: jan.nijtmans tags: improve_commit_warning
13:08
merge trunk check-in: b70a3202 user: jan.nijtmans tags: improve_commit_warning
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/blob.c.

1025
1026
1027
1028
1029
1030
1031






























1032
1033
1034
1035
1036
1037
1038
  z = p->aData;
  for(i=j=0; z[i]; i++){
    if( z[i]!='\r' ) z[j++] = z[i];
  }
  z[j] = 0;
  p->nUsed = j;
}































/*
** Shell-escape the given string.  Append the result to a blob.
*/
void shell_escape(Blob *pBlob, const char *zIn){
  int n = blob_size(pBlob);
  int k = strlen(zIn);







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







1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
  z = p->aData;
  for(i=j=0; z[i]; i++){
    if( z[i]!='\r' ) z[j++] = z[i];
  }
  z[j] = 0;
  p->nUsed = j;
}

/*
** Convert blob from cp1252 to utf-8. As cp1252 is a superset
** of iso8895-1, this is useful on UNIX as well.
**
** TODO: the bytes 0x80..0xBF need a special table, iso8895-1 works.
*/
void blob_cp1252_to_utf8(Blob *p){
  unsigned char *z = (unsigned char *)p->aData;
  int j   = p->nUsed;
  int i, n;
  for(i=n=0; i<j; i++){
    if( z[i]>=0x80 ) n++;
  }
  j += n;
  if( j>=p->nAlloc ){
    blob_resize(p, j);
    z = (unsigned char *)p->aData;
  }
  p->nUsed = j;
  z[j] = 0;
  while( j>i ){
    if( z[--i]>=0x80 ){
      z[--j] = 0x80 | (z[i]&0x3F);
      z[--j] = 0xC0 | (z[i]>>6);
    }else{
      z[--j] = z[i];
    }
  }
}

/*
** Shell-escape the given string.  Append the result to a blob.
*/
void shell_escape(Blob *pBlob, const char *zIn){
  int n = blob_size(pBlob);
  int k = strlen(zIn);

Changes to src/checkin.c.

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
  static int allOk = 0;   /* Set to true to disable this routine */

  if( allOk ) return 0;
  fUnicode = starts_with_utf16_bom(p, 0);
  eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p);
  if( eType<-2){
    const char *zWarning;

    Blob ans;
    char cReply;

    if(eType==-4){
      zWarning = "long lines";

    }else{
      zWarning = "invalid UTF-8";

    }
    blob_zero(&ans);
    file_relative_name(zFilename, &fname, 0);
    zMsg = mprintf(
         "%s appears to be text, but contains %s.  commit anyhow (y/N)? ",
         blob_str(&fname), zWarning);
    prompt_user(zMsg, &ans);
    fossil_free(zMsg);
    cReply = blob_str(&ans)[0];










    if( cReply!='y' && cReply!='Y' ){
      fossil_fatal("Abandoning commit due to %s in %s",
                   zWarning, blob_str(&fname));
    }
    blob_reset(&ans);
    eType +=4 ;
  }
  if( eType==0 || eType==-1 || fUnicode ){







>





>


>




|
|



>
>
>
>
>
>
>
>
>
>
|







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
  static int allOk = 0;   /* Set to true to disable this routine */

  if( allOk ) return 0;
  fUnicode = starts_with_utf16_bom(p, 0);
  eType = fUnicode ? looks_like_utf16(p) : looks_like_utf8(p);
  if( eType<-2){
    const char *zWarning;
    const char *zConvert;
    Blob ans;
    char cReply;

    if(eType==-4){
      zWarning = "long lines";
      zConvert = "";
    }else{
      zWarning = "invalid UTF-8";
      zConvert = "c=convert/";
    }
    blob_zero(&ans);
    file_relative_name(zFilename, &fname, 0);
    zMsg = mprintf(
         "%s appears to be text, but contains %s.  commit anyhow (%sy/N)? ",
         blob_str(&fname), zWarning, zConvert);
    prompt_user(zMsg, &ans);
    fossil_free(zMsg);
    cReply = blob_str(&ans)[0];
    if( *zConvert && (cReply=='c' || cReply=='C') ){
      char *zOrig = file_newname(zFilename, "original", 1);
      FILE *f;
      blob_write_to_file(p, zOrig);
      fossil_free(zOrig);
      f = fossil_fopen(zFilename, "wb");
      blob_cp1252_to_utf8(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));
    }
    blob_reset(&ans);
    eType +=4 ;
  }
  if( eType==0 || eType==-1 || fUnicode ){