Fossil

Check-in [ea876c3f]
Login

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

Overview
Comment:Seems to work again on a simple test case. Not finished or well tested
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:ea876c3f17ed018bf19c9dde82bdee640f0af153
User & Date: baruch 2015-01-06 11:45:28
Context
2015-01-06
20:17
Fix a typo and tagging issue check-in: 2b6fc1dd user: baruch tags: svn-import
11:45
Seems to work again on a simple test case. Not finished or well tested check-in: ea876c3f user: baruch tags: svn-import
2015-01-01
15:02
Another unfinished revision check-in: 65f9525b user: baruch tags: svn-import
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/import.c.

898
899
900
901
902
903
904


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
976


977
978
979
980
981


982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
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
....
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
....
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
....
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196



1197
1198
1199
1200
1201
1202
1203
....
1208
1209
1210
1211
1212
1213
1214
1215


1216
1217
1218
1219
1220
1221
1222
1223
1224
....
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
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333



1334
1335
1336
1337
1338
1339
1340
....
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
....
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
    rec->contentFlag = 0;
  }
  return 1;
}

static void svn_finish_revision(){
  Blob manifest;


  static Stmt insRev;
  Blob mcksum;

  blob_zero(&manifest);
  db_static_prepare(&getChanges, "SELECT tbranch, ttype FROM xchanged");


  db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm,"
                               " tsrc, tsrcbranch, trev tsrcrev"
                               " FROM xfiles, xsrc"
                               " ON tpath, tbranch)"
                               " WHERE tbranch=:branch ORDER BY tpath");

  db_static_prepare(&setRid, "REPLACE INTO xrevisions(trev, tbranch, trid)"
                             " VALUES (%d, :branch, :rid)", gsvn.rev);
  if( !gsvn.flatFlag ){
    if( gsvn.parentRev<0 ){
      gsvn.parentRev = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions "
                                  "WHERE tbranch=%Q", gsvn.zBranch);
      if( gsvn.parentRev<0 ){
        gsvn.parentRev =
            db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions");
      }
      gsvn.zParentBranch = gsvn.zBranch;
    }else if( gsvn.zParentBranch==0 ){
      gsvn.zParentBranch = mprintf("trunk");
    }
    /*db_bind_int(&insRev, ":rev", gsvn.rev);
    db_bind_text(&insRev, ":branch", gsvn.zBranch);
    db_bind_int(&insRev, ":rid", 0);
    db_step(&insRev);
    db_reset(&insRev);*/
  }else{
    static int prevRev = -1;
    gsvn.parentRev = prevRev;
    gsvn.zParentBranch = gsvn.zBranch = "";
    prevRev = gsvn.rev;
  }

  if( gsvn.zComment ){
    blob_appendf(&manifest, "C %F\n", gsvn.zComment);
  }else{
    blob_append(&manifest, "C (no\\scomment)\n", 16);
  }
  if( gsvn.zDate ){
    blob_appendf(&manifest, "D %s\n", gsvn.zDate);
  }else{
    goto skip_revision;
  }
  nFilter = blob_size(&gsvn.filter)-1;
  db_bind_text(&qFiles, ":filter", blob_str(&gsvn.filter));

  while( db_step(&qFiles)==SQLITE_ROW ){
    const char *zFile = db_column_text(&qFiles, 0);
    int rid = db_column_int(&qFiles, 1);

    const char *zPerm = db_column_text(&qFiles, 2);
    char *zUuid;
    zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
    blob_appendf(&manifest, "F %F %s %s\n", zFile+nFilter, zUuid, zPerm);
    fossil_free(zUuid);
  }
  db_reset(&qFiles);
  if( gsvn.parentRev>=0 ){
    const char *zParentUuid;
    db_bind_int(&qParent, ":rev", gsvn.parentRev);
    db_bind_text(&qParent, ":branch", gsvn.zParentBranch);
    db_step(&qParent);
    zParentUuid = db_column_text(&qParent, 0);
    if( zParentUuid==0 ){
      db_bind_text(&qParent2, ":branch", gsvn.zParentBranch);
      db_step(&qParent2);
      zParentUuid = db_column_text(&qParent2, 0);




    }


    blob_appendf(&manifest, "P %s\n", zParentUuid);
    if( !gsvn.flatFlag ){
      if( strcmp(gsvn.zBranch, gsvn.zParentBranch)!=0 ){


        blob_appendf(&manifest, "T *branch * %F\n", gsvn.zBranch);
        blob_appendf(&manifest, "T *sym-%F *\n", gsvn.zBranch);
        zParentBranch = mprintf("%F", gsvn.zParentBranch);
      }else{
        zParentBranch = 0;


      }
    }
    db_reset(&qParent);
    db_reset(&qParent2);
  }else{
    blob_appendf(&manifest, "T *branch * trunk\n");
    blob_appendf(&manifest, "T *sym-trunk *\n");
  }
  db_bind_int(&qTags, ":rev", gsvn.rev);
  while( db_step(&qTags)==SQLITE_ROW ){
    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", gsvn.rev);
  if( zParentBranch ) {
    blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);
    fossil_free(zParentBranch);
  }
  if( gsvn.zUser ){
    blob_appendf(&manifest, "U %F\n", gsvn.zUser);
  }else{
    const char *zUserOvrd = find_option("user-override",0,1);
    blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
  }
  md5sum_blob(&manifest, &mcksum);
  blob_appendf(&manifest, "Z %b\n", &mcksum);
  blob_reset(&mcksum);



  rid = content_put(&manifest);
  db_bind_int(&insRev, ":rev", gsvn.rev);
  db_bind_text(&insRev, ":branch", gsvn.zBranch);

  db_bind_int(&insRev, ":rid", rid);
  db_step(&insRev);
  db_reset(&insRev);


skip_revision:
  blob_resize(&gsvn.filter, nBaseFilter);
  if( gsvn.zParentBranch == gsvn.zBranch ){
    gsvn.zParentBranch = 0;
  }
  if( gsvn.flatFlag ){
    gsvn.zBranch = 0;
  }
  blob_reset(&manifest);

}

static u64 svn_get_varint(const char **pz){
  unsigned int v = 0;
  do{
    v = (v<<7) | ((*pz)[0]&0x7f);
  }while( (*pz)++[0]&0x80 );
................................................................................
    }else{
      *zFile = 0;
    }
    type = 3;
  }
  if( type>0 ){
    branchId = db_int(0,
                      "SELECT tid FROM xbranches WHERE tbranch=%Q AND ttype=%d",
                      zBranch, branchType);
    if( branchId==0 ){
      db_multi_exec("INSERT INTO xbranches (tbranch, ttype) VALUES(%Q, %d)",
                    zBranch, branchType);
      branchId = db_last_insert_rowid();
    }
  }
  return branchId;
}

/*
................................................................................
static void svn_dump_import(FILE *pIn){
  SvnRecord rec;
  int ver;
  char *zTemp;
  const char *zUuid;
  Stmt addFile;
  Stmt delPath;
  Stmt addSrc;
  Stmt addBranch;
  Stmt cpyPath;

  /* 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);
................................................................................
  );
  db_prepare(&delPath,
    "DELETE FROM xfiles"
    " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
    "     AND tbranch=:branch"
  );
  db_prepare(&addRev,
    "INSERT OR IGNORE INTO xrevisions (trev, tbranch, tparent)"
    " VALUES(:rev, :branch, :parent)"
  );
  db_prepare(&cpyPath,
    "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
    " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
    " FROM xfoci"
    " WHERE chekinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'"



  );
  gsvn.rev = -1;
  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      char *zDate = NULL;
      if( gsvn.rev>=0 ){
................................................................................
      }
      /* start new revision */
      gsvn.rev = atoi(zTemp);
      gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author"));
      gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log"));
      zDate = svn_find_prop(rec, "svn:date");
      if( zDate ){
        zDate = date_in_standard_format(zDate);


      }
      gsvn.zDate = zDate;
      db_bind_int(&addRev, ":rev", gsvn.rev);
      fossil_print("\rImporting SVN revision: %d", gsvn.rev);
    }else
    if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
      char *zAction = svn_find_header(rec, "Node-action");
      char *zKind = svn_find_header(rec, "Node-kind");
      char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
................................................................................
          fossil_fatal("Copy from path outside the import paths");
        }
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        db_bind_text(&delPath, ":path", zFile);
        db_bind_text(&delPath, ":branch", branchId);
        db_step(&delPath);
        db_reset(&delPath);



      } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
      if( strncmp(zAction, "add", 3)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                                   " WHERE trev<=%d AND tbranch=%Q",
                                srcRev, zSrcBranch);
            db_bind_text(&cpyPath, ":path", zFile);
            db_bind_text(&cpyPath, ":branch", zBranch);
            db_bind_text(&cpyPath, ":srcpath", zSrcFile);
            db_bind_int(&cpyPath, ":rid", srcRid);
            db_step(&cpyPath);
            db_reset(&cpyPath);










          }
        }else{
          int rid = 0;
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                            " WHERE trev<=%d AND tbranch=%Q",
                         srcRev, zSrcBranch);
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfoci"
                            "  WHERE chekinID=%d AND filename=%Q"
                            ")",
                         srcRid, zSrcFile);
          }
          if( deltaFlag ){
................................................................................
            }
            svn_apply_svndiff(&rec.content, &deltaSrc, &target);
            rid = content_put(&target);
          }else if( rec.contentFlag ){
            rid = content_put(&rec.content);
          }
          db_bind_text(&addFile, ":path", zFile);
          db_bind_text(&addFile, ":branch", zBranch);
          db_bind_int(&addFile, ":rid", rid);
          db_bind_text(&addFile, ":perm", zPerm);
          db_step(&addFile);
          db_reset(&addFile);



        }
      }else
      if( strncmp(zAction, "change", 6)==0 ){
        int rid = 0;
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }
        if( strncmp(zKind, "dir", 3)!=0 ){
          if( deltaFlag ){
            Blob deltaSrc;
            Blob target;
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfiles"
                            "  WHERE tpath=%Q AND tbranch=%Q"
                            ")", zFile, zBranch);
            content_get(rid, &deltaSrc);
            svn_apply_svndiff(&rec.content, &deltaSrc, &target);
            rid = content_put(&target);
          }else{
            rid = content_put(&rec.content);
          }
          db_bind_text(&addFile, ":path", zFile);
          db_bind_text(&addFile, ":branch", zBranch);
          db_bind_int(&addFile, ":rid", rid);
          db_bind_text(&addFile, ":perm", zPerm);
          db_step(&addFile);
          db_reset(&addFile);



        }
      }else
      if( strncmp(zAction, "delete", 6)!=0 ){ /* already did this one above */
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
................................................................................
  }
  svn_finish_revision();
  fossil_free(gsvn.zUser);
  fossil_free(gsvn.zComment);
  fossil_free(gsvn.zDate);
  db_finalize(&addFile);
  db_finalize(&delPath);
  db_finalize(&addSrc);
  db_finalize(&addBranch);
  db_finalize(&cpyPath);
  fossil_print(" Done!\n");
}

/*
** COMMAND: import
**
** Usage: %fossil import FORMAT ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?
................................................................................
  if( strncmp(g.argv[2], "svn", 3)==0 ){
    db_multi_exec(
       "CREATE TEMP TABLE xrevisions("
       " trev INTEGER, tbranch INT, trid INT, tparent INT,"
       " UNIQUE(tbranch, trev), UNIQUE(trid)"
       ");"
       "CREATE TEMP TABLE xfiles("
       " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT, tsrcpath TEXT"
       " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xbranches("
       " tid INTEGER PRIMARY KEY, tbranch TEXT, ttype INT,"
       " UNIQUE(tbranch, ttype)"
       ");"
       "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
    );
    if( zBase==0 ){ zBase = ""; }
    if( strlen(zBase)>0 ){
      if( zBase[strlen(zBase)-1]!='/' ){
        zBase = mprintf("%s/", zBase);







>
>
|



|
>
>
|
<
<
<

>
|
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
<
|
<
<
<
<
<
>
|
|
<
>
|
<
<
|
<
|
|
<
<
<
<
<
<
<
<
<
<
>
>
>
>
|
>
>
|
<
<
>
>
|
|
<
<
<
>
>
|
<
<
<
|
|
|
<
<
<
<
<
<
<
|
<
<
<
|
|
|
|
|
|
|
|
|
|
>
>
|
|
<
<
>
|
|
|
>
|
<
<
<
<
<
<
<
<
|
>







 







|
|

|
|







 







|
|
|







 







|
|





|
>
>
>







 







|
>
>

<







 







|


>
>
>









|
|

|




>
>
>
>
>
>
>
>
>
>





|
|







 







|




>
>
>













|
|







|




>
>
>







 







|
|
|







 







|



|
|







898
899
900
901
902
903
904
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
976
977
978








979
980
981
982
983
984
985
986
987
....
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
....
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
....
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
....
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
....
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
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
....
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
....
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
....
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
    rec->contentFlag = 0;
  }
  return 1;
}

static void svn_finish_revision(){
  Blob manifest;
  static Stmt getChanges;
  static Stmt getFiles;
  static Stmt setRid;
  Blob mcksum;

  blob_zero(&manifest);
  db_static_prepare(&getChanges, "SELECT tid, tname, ttype, tparent"
                                 " FROM xrevisions, xbranches ON (tbranch=tid)"
                                 " WHERE trid ISNULL");
  db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm FROM xfiles"



                               " WHERE tbranch=:branch ORDER BY tpath");
  db_prepare(&setRid, "UPDATE xrevisions SET trid=:rid"
                             " WHERE trev=%d AND tbranch=:branch", gsvn.rev);
  while( db_step(&getChanges)==SQLITE_ROW ){
    int branchId = db_column_int(&getChanges, 0);
    const char *zBranch = db_column_text(&getChanges, 1);
    int branchType = db_column_int(&getChanges, 2);
    int parentRid = db_column_int(&getChanges, 3);
    int onBranch = 0;
    int rid;
    if( branchType!=3 ){

















      if( gsvn.zComment ){
        blob_appendf(&manifest, "C %F\n", gsvn.zComment);
      }else{
        blob_append(&manifest, "C (no\\scomment)\n", 16);
      }

      blob_appendf(&manifest, "D %s\n", gsvn.zDate);





      db_bind_int(&getFiles, ":branch", branchId);
      while( db_step(&getFiles)==SQLITE_ROW ){
        const char *zFile = db_column_text(&getFiles, 0);

        const char *zUuid = db_column_text(&getFiles, 1);
        const char *zPerm = db_column_text(&getFiles, 2);


        blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm);

      }
      db_reset(&getFiles);










      if( parentRid==0 ){
        parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                              " WHERE trev<%d AND tbranch=%d", gsvn.rev, branchId);
        onBranch = 1;
      }
      if( parentRid>0 ){
        const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid);
        blob_appendf(&manifest, "P %s\n", zParentUuid);


        if( onBranch==0 ){
          const char *zParentBranch = db_text(0, "SELECT tbranch FROM xbranches WHERE tid=(SELECT tbranch FROM xrevisions WHERE trid=%d)", parentRid);
          blob_appendf(&manifest, "T *branch * %F\n", zBranch);
          blob_appendf(&manifest, "T *sym-%F *\n", zBranch);



          blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
          blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);
        }



      }else{
        blob_appendf(&manifest, "T *branch * %F\n", zBranch);
        blob_appendf(&manifest, "T *sym-%F *\n", zBranch);







        blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);



      }
      if( gsvn.zUser ){
        blob_appendf(&manifest, "U %F\n", gsvn.zUser);
      }else{
        const char *zUserOvrd = find_option("user-override",0,1);
        blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
      }
      md5sum_blob(&manifest, &mcksum);
      blob_appendf(&manifest, "Z %b\n", &mcksum);
      blob_reset(&mcksum);
    }else{
//      TODO tag
    }
    rid = content_put(&manifest);


    db_bind_int(&setRid, ":branch", branchId);
    db_bind_int(&setRid, ":rid", rid);
    db_step(&setRid);
    db_reset(&setRid);
    blob_reset(&manifest);
  }








  db_reset(&getChanges);
  db_finalize(&setRid);
}

static u64 svn_get_varint(const char **pz){
  unsigned int v = 0;
  do{
    v = (v<<7) | ((*pz)[0]&0x7f);
  }while( (*pz)++[0]&0x80 );
................................................................................
    }else{
      *zFile = 0;
    }
    type = 3;
  }
  if( type>0 ){
    branchId = db_int(0,
                      "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d",
                      zBranch, type);
    if( branchId==0 ){
      db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)",
                    zBranch, type);
      branchId = db_last_insert_rowid();
    }
  }
  return branchId;
}

/*
................................................................................
static void svn_dump_import(FILE *pIn){
  SvnRecord rec;
  int ver;
  char *zTemp;
  const char *zUuid;
  Stmt addFile;
  Stmt delPath;
  Stmt addRev;
  Stmt cpyPath;
  Stmt revSrc;

  /* 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);
................................................................................
  );
  db_prepare(&delPath,
    "DELETE FROM xfiles"
    " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
    "     AND tbranch=:branch"
  );
  db_prepare(&addRev,
    "INSERT OR IGNORE INTO xrevisions (trev, tbranch)"
    " VALUES(:rev, :branch)"
  );
  db_prepare(&cpyPath,
    "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
    " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
    " FROM xfoci"
    " WHERE checkinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'"
  );
  db_prepare(&revSrc,
    "UPDATE xrevisions SET tparent=:parent WHERE trev=:rev AND tbranch=:branch"
  );
  gsvn.rev = -1;
  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      char *zDate = NULL;
      if( gsvn.rev>=0 ){
................................................................................
      }
      /* start new revision */
      gsvn.rev = atoi(zTemp);
      gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author"));
      gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log"));
      zDate = svn_find_prop(rec, "svn:date");
      if( zDate ){
        gsvn.zDate = date_in_standard_format(zDate);
      }else{
        gsvn.zDate = date_in_standard_format("now");
      }

      db_bind_int(&addRev, ":rev", gsvn.rev);
      fossil_print("\rImporting SVN revision: %d", gsvn.rev);
    }else
    if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
      char *zAction = svn_find_header(rec, "Node-action");
      char *zKind = svn_find_header(rec, "Node-kind");
      char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
................................................................................
          fossil_fatal("Copy from path outside the import paths");
        }
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        db_bind_text(&delPath, ":path", zFile);
        db_bind_int(&delPath, ":branch", branchId);
        db_step(&delPath);
        db_reset(&delPath);
        db_bind_int(&addRev, ":branch", branchId);
        db_step(&addRev);
        db_reset(&addRev);
      } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
      if( strncmp(zAction, "add", 3)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                                   " WHERE trev<=%d AND tbranch=%d",
                                srcRev, srcBranch);
            db_bind_text(&cpyPath, ":path", zFile);
            db_bind_int(&cpyPath, ":branch", branchId);
            db_bind_text(&cpyPath, ":srcpath", zSrcFile);
            db_bind_int(&cpyPath, ":rid", srcRid);
            db_step(&cpyPath);
            db_reset(&cpyPath);
            db_bind_int(&addRev, ":branch", branchId);
            db_step(&addRev);
            db_reset(&addRev);
            if( zFile==0 ){
              db_bind_int(&revSrc, ":parent", srcRid);
              db_bind_int(&revSrc, ":rev", srcRev);
              db_bind_int(&revSrc, ":branch", branchId);
              db_step(&revSrc);
              db_reset(&revSrc);
            }
          }
        }else{
          int rid = 0;
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                            " WHERE trev<=%d AND tbranch=%d",
                         srcRev, srcBranch);
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfoci"
                            "  WHERE chekinID=%d AND filename=%Q"
                            ")",
                         srcRid, zSrcFile);
          }
          if( deltaFlag ){
................................................................................
            }
            svn_apply_svndiff(&rec.content, &deltaSrc, &target);
            rid = content_put(&target);
          }else if( rec.contentFlag ){
            rid = content_put(&rec.content);
          }
          db_bind_text(&addFile, ":path", zFile);
          db_bind_int(&addFile, ":branch", branchId);
          db_bind_int(&addFile, ":rid", rid);
          db_bind_text(&addFile, ":perm", zPerm);
          db_step(&addFile);
          db_reset(&addFile);
          db_bind_int(&addRev, ":branch", branchId);
          db_step(&addRev);
          db_reset(&addRev);
        }
      }else
      if( strncmp(zAction, "change", 6)==0 ){
        int rid = 0;
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }
        if( strncmp(zKind, "dir", 3)!=0 ){
          if( deltaFlag ){
            Blob deltaSrc;
            Blob target;
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfiles"
                            "  WHERE tpath=%Q AND tbranch=%d"
                            ")", zFile, branchId);
            content_get(rid, &deltaSrc);
            svn_apply_svndiff(&rec.content, &deltaSrc, &target);
            rid = content_put(&target);
          }else{
            rid = content_put(&rec.content);
          }
          db_bind_text(&addFile, ":path", zFile);
          db_bind_int(&addFile, ":branch", branchId);
          db_bind_int(&addFile, ":rid", rid);
          db_bind_text(&addFile, ":perm", zPerm);
          db_step(&addFile);
          db_reset(&addFile);
          db_bind_int(&addRev, ":branch", branchId);
          db_step(&addRev);
          db_reset(&addRev);
        }
      }else
      if( strncmp(zAction, "delete", 6)!=0 ){ /* already did this one above */
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
................................................................................
  }
  svn_finish_revision();
  fossil_free(gsvn.zUser);
  fossil_free(gsvn.zComment);
  fossil_free(gsvn.zDate);
  db_finalize(&addFile);
  db_finalize(&delPath);
  db_finalize(&addRev);
  db_finalize(&cpyPath);
  db_finalize(&revSrc);
  fossil_print(" Done!\n");
}

/*
** COMMAND: import
**
** Usage: %fossil import FORMAT ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?
................................................................................
  if( strncmp(g.argv[2], "svn", 3)==0 ){
    db_multi_exec(
       "CREATE TEMP TABLE xrevisions("
       " trev INTEGER, tbranch INT, trid INT, tparent INT,"
       " UNIQUE(tbranch, trev), UNIQUE(trid)"
       ");"
       "CREATE TEMP TABLE xfiles("
       " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT,"
       " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xbranches("
       " tid INTEGER PRIMARY KEY, tname TEXT, ttype INT,"
       " UNIQUE(tname, ttype)"
       ");"
       "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
    );
    if( zBase==0 ){ zBase = ""; }
    if( strlen(zBase)>0 ){
      if( zBase[strlen(zBase)-1]!='/' ){
        zBase = mprintf("%s/", zBase);