Fossil

Check-in [eb0bf087]
Login

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

Overview
Comment:Support version 3 format (diff dumps)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:eb0bf08733791043207ab064782fe6104fc00c7c
User & Date: baruch 2014-10-28 10:44:29
Context
2014-10-28
12:19
fix bug with multi-window svndiff check-in: ea54a298 user: baruch tags: svn-import
10:44
Support version 3 format (diff dumps) check-in: eb0bf087 user: baruch tags: svn-import
2014-10-27
08:19
add support for tags check-in: 2889cdc3 user: baruch tags: svn-import
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/import.c.

726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
864
865
866
867
868
869
870

871
872
873
874
875
876
877



878
879
880
881
882
883
884
...
974
975
976
977
978
979
980

981
982
983
984
985
986
987
...
998
999
1000
1001
1002
1003
1004






















































1005
1006
1007
1008
1009
1010
1011
....
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
....
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096

1097
1098




1099
1100
1101
1102
1103
1104
1105
....
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164







1165







1166
1167

1168
1169
1170
1171
1172
1173
1174
1175
1176













1177

1178
1179
1180
1181
1182
1183
1184
....
1186
1187
1188
1189
1190
1191
1192

1193
1194
1195
1196
1197
1198
1199
typedef struct {
  KeyVal *aHeaders;
  int nHeaders;
  char *pRawProps;
  KeyVal *aProps;
  int nProps;
  Blob content;
  int nContent;
} SvnRecord;

#define svn_find_header(rec, zHeader) \
  svn_find_keyval((rec).aHeaders, (rec).nHeaders, (zHeader))
#define svn_find_prop(rec, zProp) \
  svn_find_keyval((rec).aProps, (rec).nProps, (zProp))
static const char *svn_find_keyval(
................................................................................
  const char *zLen;
  int nLen = 0;
  if( svn_read_headers(pIn, rec)==0 ) return 0;
  svn_read_props(pIn, rec);
  blob_zero(&rec->content);
  zLen = svn_find_header(*rec, "Text-content-length");
  if( zLen ){

    nLen = atoi(zLen);
  }
  blob_read_from_channel(&rec->content, pIn, nLen);
  if( blob_size(&rec->content)!=nLen ){
    fossil_fatal("short read: got %d of %d bytes",
      blob_size(&rec->content), nLen
    );



  }
  return 1;
}

static void svn_create_manifests(int flatFlag){
  Blob manifest;
  Stmt qRev;
................................................................................
      const char *zTag = db_column_text(&qTags, 0);
      blob_appendf(&manifest, "T +sym-%s *\n", zTag);
    }
    db_reset(&qTags);
    blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", rev);
    if( zParentBranch ) {
      blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);

    }
    if( zUser ){
      blob_appendf(&manifest, "U %F\n", zUser);
    }else{
      const char *zUserOvrd = find_option("user-override",0,1);
      blob_appendf(&manifest, "U %F\n",
        zUserOvrd ? zUserOvrd : login_name());
................................................................................
  }
  db_finalize(&qRev);
  db_finalize(&qParent);
  db_finalize(&qFiles);
  db_finalize(&qTags);
  db_finalize(&setUuid);
}






















































/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn, int flatFlag){
  SvnRecord rec;
  int ver;
................................................................................
  Stmt setParent;
  int rev = 0;

  /* version */
  if( svn_read_rec(pIn, &rec)
   && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){
    ver = atoi(zTemp);
    if( ver!=2 ){
      fossil_fatal("Unknown svn-dump format version: %d", ver);
    }
  }else{
    fossil_fatal("Input is not an svn-dump!");
  }
  svn_free_rec(&rec);
  /* UUID */
................................................................................
      db_reset(&insRev);
      fossil_free(zDate);
      if( rev>0 ){
        db_multi_exec("INSERT INTO xfiles (trev, tpath, trid, tperm) "
                      "SELECT %d, tpath, trid, tperm FROM xfiles "
                      "WHERE trev=%d", rev, rev-1);
      }

    }else
    if( zTemp = svn_find_header(rec, "Node-path") ){
      const char *zPath = zTemp;
      const char *zAction = svn_find_header(rec, "Node-action");
      const char *zKind = svn_find_header(rec, "Node-kind");
      const char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
      const char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;

      int srcRev = -1;
      int rid = 0;




      if( zSrcPath ){
        zTemp = svn_find_header(rec, "Node-copyfrom-rev");
        if( zTemp ){
          srcRev = atoi(zTemp);
        }else{
          fossil_fatal("Missing copyfrom-rev");
        }
................................................................................
                db_bind_text(&insTag, ":tag", zTemp);
                db_step(&insTag);
                db_reset(&insTag);
              }
            }
          }
        }else{
          if( blob_size(&rec.content)==0 && zSrcPath ){
            rid = db_int(0,
                         "SELECT trid FROM xfiles WHERE trev=%d AND tpath=%Q",
                         srcRev, zSrcPath);







          }else{







            rid = content_put(&rec.content);
          }

          db_bind_int(&insFile, ":rev", rev);
          db_bind_int(&insFile, ":rid", rid);
          db_bind_text(&insFile, ":path", zPath);
          db_bind_text(&insFile, ":perm", zPerm);
          db_step(&insFile);
          db_reset(&insFile);
        }
      }else
      if( strncmp(zAction, "change", 6)==0 ){













        rid = content_put(&rec.content);

        db_bind_int(&insFile, ":rev", rev);
        db_bind_int(&insFile, ":rid", rid);
        db_bind_text(&insFile, ":path", zPath);
        db_bind_text(&insFile, ":perm", zPerm);
        db_step(&insFile);
        db_reset(&insFile);
      }else
................................................................................
      }else{
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
    }
    svn_free_rec(&rec);

  }
  if( !flatFlag ){
    if( *zBranch ){
      db_bind_text(&setBranch, ":branch", zBranch);
      db_bind_int(&setBranch, ":rev", rev);
      db_step(&setBranch);
    }







|







 







>

<
|
|
|
|
|
>
>
>







 







>







 







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







 







|







 







>







>


>
>
>
>







 







|



>
>
>
>
>
>
>
|
>
>
>
>
>
>
>


>









>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







 







>







726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
864
865
866
867
868
869
870
871
872

873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
...
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
....
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
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
1069
....
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
....
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
....
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
....
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
typedef struct {
  KeyVal *aHeaders;
  int nHeaders;
  char *pRawProps;
  KeyVal *aProps;
  int nProps;
  Blob content;
  int contentFlag;
} SvnRecord;

#define svn_find_header(rec, zHeader) \
  svn_find_keyval((rec).aHeaders, (rec).nHeaders, (zHeader))
#define svn_find_prop(rec, zProp) \
  svn_find_keyval((rec).aProps, (rec).nProps, (zProp))
static const char *svn_find_keyval(
................................................................................
  const char *zLen;
  int nLen = 0;
  if( svn_read_headers(pIn, rec)==0 ) return 0;
  svn_read_props(pIn, rec);
  blob_zero(&rec->content);
  zLen = svn_find_header(*rec, "Text-content-length");
  if( zLen ){
    rec->contentFlag = 1;
    nLen = atoi(zLen);

    blob_read_from_channel(&rec->content, pIn, nLen);
    if( blob_size(&rec->content)!=nLen ){
      fossil_fatal("short read: got %d of %d bytes",
        blob_size(&rec->content), nLen
      );
    }
  }else{
    rec->contentFlag = 0;
  }
  return 1;
}

static void svn_create_manifests(int flatFlag){
  Blob manifest;
  Stmt qRev;
................................................................................
      const char *zTag = db_column_text(&qTags, 0);
      blob_appendf(&manifest, "T +sym-%s *\n", zTag);
    }
    db_reset(&qTags);
    blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", rev);
    if( zParentBranch ) {
      blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);
      zParentBranch = 0;
    }
    if( zUser ){
      blob_appendf(&manifest, "U %F\n", zUser);
    }else{
      const char *zUserOvrd = find_option("user-override",0,1);
      blob_appendf(&manifest, "U %F\n",
        zUserOvrd ? zUserOvrd : login_name());
................................................................................
  }
  db_finalize(&qRev);
  db_finalize(&qParent);
  db_finalize(&qFiles);
  db_finalize(&qTags);
  db_finalize(&setUuid);
}

static u64 svn_get_varint(const char **pz){
  unsigned int v = 0;
  do{
    v = (v<<7) | ((*pz)[0]&0x7f);
  }while( (*pz)++[0]&0x80 );
  return v;
}

static void svn_apply_svndiff(Blob *pDiff, Blob *pSrc, Blob *pOut){
  const char *zDiff = blob_buffer(pDiff);
  char *zOut;
  if( blob_size(pDiff)<4 || memcmp(zDiff, "SVN", 4)!=0 ){
    fossil_fatal("Invalid svndiff0 format");
  }
  zDiff += 4;
  blob_zero(pOut);
  while( zDiff<(blob_buffer(pDiff)+blob_size(pDiff)) ){
    u64 offSrc = svn_get_varint(&zDiff);
    u64 lenSrc = svn_get_varint(&zDiff);
    u64 lenOut = svn_get_varint(&zDiff);
    u64 lenInst = svn_get_varint(&zDiff);
    u64 lenData = svn_get_varint(&zDiff);
    const char *zInst = zDiff;
    const char *zData = zInst+lenInst;
    u64 lenOld = blob_size(pOut);
    blob_resize(pOut, lenOut);
    zOut = blob_buffer(pOut) + lenOld;
    while( zDiff<zInst+lenInst ){
      u64 lenCpy = (*zDiff)&0x3f;
      const char *zCpy;
      switch( (*zDiff)&0xC0 ){
        case 0x00: zCpy = blob_buffer(pSrc)+offSrc; break;
        case 0x40: zCpy = blob_buffer(pOut); break;
        case 0x80: zCpy = zData; break;
        default: fossil_fatal("Invalid svndiff0 instruction");
      }
      zDiff++;
      if( lenCpy==0 ){
        lenCpy = svn_get_varint(&zDiff);
      }
      if( zCpy!=zData ){
        zCpy += svn_get_varint(&zDiff);
      }else{
        zData += lenCpy;
      }
      while( lenCpy-- > 0 ){
        *zOut++ = *zCpy++;
      }
    }
    zDiff += lenData;
  }
}

/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn, int flatFlag){
  SvnRecord rec;
  int ver;
................................................................................
  Stmt setParent;
  int rev = 0;

  /* version */
  if( svn_read_rec(pIn, &rec)
   && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){
    ver = atoi(zTemp);
    if( ver!=2 && ver!=3 ){
      fossil_fatal("Unknown svn-dump format version: %d", ver);
    }
  }else{
    fossil_fatal("Input is not an svn-dump!");
  }
  svn_free_rec(&rec);
  /* UUID */
................................................................................
      db_reset(&insRev);
      fossil_free(zDate);
      if( rev>0 ){
        db_multi_exec("INSERT INTO xfiles (trev, tpath, trid, tperm) "
                      "SELECT %d, tpath, trid, tperm FROM xfiles "
                      "WHERE trev=%d", rev, rev-1);
      }
fossil_print("rev: %d\n", rev);
    }else
    if( zTemp = svn_find_header(rec, "Node-path") ){
      const char *zPath = zTemp;
      const char *zAction = svn_find_header(rec, "Node-action");
      const char *zKind = svn_find_header(rec, "Node-kind");
      const char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
      const char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
      int deltaFlag = 0;
      int srcRev = -1;
      int rid = 0;
fossil_print("file: %s ...", zPath);
      if( zTemp = svn_find_header(rec, "Text-delta") ){
        deltaFlag = strncmp(zTemp, "true", 4)==0;
      }
      if( zSrcPath ){
        zTemp = svn_find_header(rec, "Node-copyfrom-rev");
        if( zTemp ){
          srcRev = atoi(zTemp);
        }else{
          fossil_fatal("Missing copyfrom-rev");
        }
................................................................................
                db_bind_text(&insTag, ":tag", zTemp);
                db_step(&insTag);
                db_reset(&insTag);
              }
            }
          }
        }else{
          if( zSrcPath ){
            rid = db_int(0,
                         "SELECT trid FROM xfiles WHERE trev=%d AND tpath=%Q",
                         srcRev, zSrcPath);
          }
          if( deltaFlag ){
            Blob deltaSrc;
            Blob target;
fossil_print("diff-size: %d ", blob_size(&rec.content));
            if( rid!=0 ){
              content_get(rid, &deltaSrc);
            }else{
              blob_zero(&deltaSrc);
            }
            svn_apply_svndiff(&rec.content, &deltaSrc, &target);
fossil_print("real-size: %d ", blob_size(&target));
            rid = content_put(&target);
          }else if( rec.contentFlag ){
fossil_print("size: %d ", blob_size(&rec.content));
            rid = content_put(&rec.content);
          }
fossil_print("rid: %d ", rid);
          db_bind_int(&insFile, ":rev", rev);
          db_bind_int(&insFile, ":rid", rid);
          db_bind_text(&insFile, ":path", zPath);
          db_bind_text(&insFile, ":perm", zPerm);
          db_step(&insFile);
          db_reset(&insFile);
        }
      }else
      if( strncmp(zAction, "change", 6)==0 ){
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }
        if( strncmp(zKind, "dir", 3)==0 ) continue;
        if( deltaFlag ){
          Blob deltaSrc;
          Blob target;
          rid = db_int(0, "SELECT trid FROM xfiles WHERE tpath=%Q AND trev=%d",
                       zPath, rev-1);
          content_get(rid, &deltaSrc);
          svn_apply_svndiff(&rec.content, &deltaSrc, &target);
          rid = content_put(&target);
        }else{
          rid = content_put(&rec.content);
        }
        db_bind_int(&insFile, ":rev", rev);
        db_bind_int(&insFile, ":rid", rid);
        db_bind_text(&insFile, ":path", zPath);
        db_bind_text(&insFile, ":perm", zPerm);
        db_step(&insFile);
        db_reset(&insFile);
      }else
................................................................................
      }else{
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
    }
    svn_free_rec(&rec);
fossil_print("done\n");
  }
  if( !flatFlag ){
    if( *zBranch ){
      db_bind_text(&setBranch, ":branch", zBranch);
      db_bind_int(&setBranch, ":rev", rev);
      db_step(&setBranch);
    }