Fossil

Check-in [65f9525b]
Login

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

Overview
Comment:Another unfinished revision
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:65f9525be50929df48a084d25b3ef64c48325291
User & Date: baruch 2015-01-01 15:02:37
Context
2015-01-06
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
2014-12-31
23:33
More work. Still not usable check-in: 2ea79975 user: baruch tags: svn-import
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/import.c.

  1082   1082   /*
  1083   1083   ** Extract the name of the branch or tag that the given path is on.
  1084   1084   ** Returns: 1 - It is on the trunk
  1085   1085   **          2 - It is on a branch
  1086   1086   **          3 - It is a tag
  1087   1087   **          0 - It is none of the above
  1088   1088    */
  1089         -static int svn_parse_path(char *zPath, char **zBranch, char **zFile){
         1089  +static int svn_parse_path(char *zPath, char **zFile){
         1090  +  int type = 0;
         1091  +  char *zBranch = 0;
         1092  +  int branchId = 0;
         1093  +  *zFile = 0;
  1090   1094     if( gsvn.lenTrunk==0 ){
  1091         -    *zBranch = "trunk";
         1095  +    zBranch = "trunk";
  1092   1096       *zFile = zPath;
  1093         -    return 1;
         1097  +    type = 1;
  1094   1098     }else
  1095   1099     if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
  1096         -    *zBranch = "trunk";
         1100  +    zBranch = "trunk";
  1097   1101       if( zPath[gsvn.lenTrunk-1]=='/' ){
  1098   1102         *zFile = zPath+gsvn.lenTrunk;;
  1099   1103       }else if( zPath[gsvn.lenTrunk-1]==0 ){
  1100   1104         *zFile = 0;
  1101   1105       }else{
  1102         -      *zFile = *zBranch = 0;
  1103         -      return 0;
         1106  +      *zFile = zBranch = 0;
         1107  +      type = 0;
  1104   1108       }
  1105         -    return 1;
         1109  +    type = 1;
  1106   1110     }else
  1107   1111     if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
  1108         -    *zFile = *zBranch = zPath+gsvn.lenBranches;
         1112  +    *zFile = zBranch = zPath+gsvn.lenBranches;
         1113  +    while( **zFile && **zFile!='/' ){ (*zFile)++; }
         1114  +    if( *zFile ){
         1115  +      **zFile = '\0';
         1116  +      (*zFile)++;
         1117  +    }else{
         1118  +      *zFile = 0;
         1119  +    }
         1120  +    type = 2;
         1121  +  }else
         1122  +  if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
         1123  +    *zFile = zBranch = zPath+gsvn.lenTags;
  1109   1124       while( **zFile && **zFile!='/' ){ (*zFile)++; }
  1110   1125       if( *zFile ){
  1111   1126         **zFile = '\0';
  1112   1127         (*zFile)++;
  1113   1128       }else{
  1114   1129         *zFile = 0;
  1115   1130       }
  1116         -    return 2;
  1117         -  }else
  1118         -  if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
  1119         -    *zFile = *zBranch = zPath+gsvn.lenTags;
  1120         -    while( **zFile && **zFile!='/' ){ (*zFile)++; }
  1121         -    if( *zFile ){
  1122         -      **zFile = '\0';
  1123         -      (*zFile)++;
  1124         -    }else{
  1125         -      *zFile = 0;
         1131  +    type = 3;
         1132  +  }
         1133  +  if( type>0 ){
         1134  +    branchId = db_int(0,
         1135  +                      "SELECT tid FROM xbranches WHERE tbranch=%Q AND ttype=%d",
         1136  +                      zBranch, branchType);
         1137  +    if( branchId==0 ){
         1138  +      db_multi_exec("INSERT INTO xbranches (tbranch, ttype) VALUES(%Q, %d)",
         1139  +                    zBranch, branchType);
         1140  +      branchId = db_last_insert_rowid();
  1126   1141       }
  1127         -    return 3;
  1128   1142     }
  1129         -  *zFile = *zBranch = 0;
  1130         -  return 0;
         1143  +  return branchId;
  1131   1144   }
  1132   1145   
  1133   1146   /*
  1134   1147   ** Read the svn-dump format from pIn and insert the corresponding
  1135   1148   ** content into the database.
  1136   1149   */
  1137   1150   static void svn_dump_import(FILE *pIn){
................................................................................
  1168   1181       " VALUES(:path, :branch, (SELECT uuid FROM blob WHERE rid=:rid), :perm)"
  1169   1182     );
  1170   1183     db_prepare(&delPath,
  1171   1184       "DELETE FROM xfiles"
  1172   1185       " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
  1173   1186       "     AND tbranch=:branch"
  1174   1187     );
  1175         -  db_prepare(&addSrc,
  1176         -    "INSERT INTO xsrc (tpath, tbranch, tsrc, tsrcbranch, tsrcrev)"
  1177         -    " VALUES(:path, :branch, :srcpath, :srcbranch, :srcrev)"
  1178         -  );
  1179         -  db_prepare(&addBranch,
  1180         -    "INSERT INTO xchanges (tbranch, ttype) VALUES(:branch, :type)"
         1188  +  db_prepare(&addRev,
         1189  +    "INSERT OR IGNORE INTO xrevisions (trev, tbranch, tparent)"
         1190  +    " VALUES(:rev, :branch, :parent)"
  1181   1191     );
  1182   1192     db_prepare(&cpyPath,
  1183   1193       "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
  1184   1194       " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
  1185   1195       " FROM xfoci"
  1186   1196       " WHERE chekinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'"
  1187   1197     );
................................................................................
  1201   1211         gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author"));
  1202   1212         gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log"));
  1203   1213         zDate = svn_find_prop(rec, "svn:date");
  1204   1214         if( zDate ){
  1205   1215           zDate = date_in_standard_format(zDate);
  1206   1216         }
  1207   1217         gsvn.zDate = zDate;
         1218  +      db_bind_int(&addRev, ":rev", gsvn.rev);
  1208   1219         fossil_print("\rImporting SVN revision: %d", gsvn.rev);
  1209   1220       }else
  1210   1221       if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
  1211   1222         char *zAction = svn_find_header(rec, "Node-action");
  1212   1223         char *zKind = svn_find_header(rec, "Node-kind");
  1213   1224         char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
  1214   1225         char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
  1215         -      char *zBranch;
  1216   1226         char *zFile;
  1217         -      char *zSrcBranch;
         1227  +      int srcBranch;
  1218   1228         char *zSrcFile;
  1219   1229         int deltaFlag = 0;
  1220   1230         int srcRev = 0;
  1221         -      int branchType = svn_parse_path(zTemp, &zBranch, &zFile);
  1222         -      if( branchType==0 ){
         1231  +      int branchId = svn_parse_path(zTemp, &zFile);
         1232  +      if( branchId==0 ){
  1223   1233           svn_free_rec(&rec);
  1224   1234           continue;
  1225   1235         }
  1226         -      db_bind_text(&addBranch, ":branch", zBranch);
  1227         -      db_bind_int(&addBranch, ":type", branchType);
  1228         -      db_step(&addBranch);
  1229         -      db_reset(&addBranch);
  1230   1236         if( (zTemp = svn_find_header(rec, "Text-delta")) ){
  1231   1237           deltaFlag = strncmp(zTemp, "true", 4)==0;
  1232   1238         }
  1233   1239         if( zSrcPath ){
  1234   1240           zTemp = svn_find_header(rec, "Node-copyfrom-rev");
  1235   1241           if( zTemp ){
  1236   1242             srcRev = atoi(zTemp);
  1237   1243           }else{
  1238   1244             fossil_fatal("Missing copyfrom-rev");
  1239   1245           }
  1240         -        if( svn_parse_path(zSrcPath, &zSrcBranch, &zSrcFile)==0 ){
         1246  +        srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
         1247  +        if( srcBranch==0 ){
  1241   1248             fossil_fatal("Copy from path outside the import paths");
  1242   1249           }
  1243         -        db_bind_text(&addSrc, ":path", zFile);
  1244         -        db_bind_text(&addSrc, ":branch", zBranch);
  1245         -        db_bind_text(&addSrc, ":srcpath", zSrcFile);
  1246         -        db_bind_text(&addSrc, ":srcbranch", zSrcBranch);
  1247         -        db_bind_int(&addSrc, ":srcrev", srcRev);
  1248         -        db_step(&addSrc);
  1249         -        db_reset(&addSrc);
  1250   1250         }
  1251   1251         if( strncmp(zAction, "delete", 6)==0
  1252   1252          || strncmp(zAction, "replace", 7)==0 )
  1253   1253         {
  1254   1254           db_bind_text(&delPath, ":path", zFile);
  1255         -        db_bind_text(&delPath, ":branch", zBranch);
         1255  +        db_bind_text(&delPath, ":branch", branchId);
  1256   1256           db_step(&delPath);
  1257   1257           db_reset(&delPath);
  1258   1258         } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
  1259   1259         if( strncmp(zAction, "add", 3)==0
  1260   1260          || strncmp(zAction, "replace", 7)==0 )
  1261   1261         {
  1262   1262           if( zKind==0 ){
................................................................................
  1454   1454         import_reset(0);
  1455   1455       }
  1456   1456       db_finalize(&q);
  1457   1457     }else
  1458   1458     if( strncmp(g.argv[2], "svn", 3)==0 ){
  1459   1459       db_multi_exec(
  1460   1460          "CREATE TEMP TABLE xrevisions("
  1461         -       " tid INTEGER PRIMARY KEY, trev INTEGER, tbranch TEXT, ttype INT, trid INT,"
  1462         -       " UNIQUE(tbranch, ttype, trev)"
         1461  +       " trev INTEGER, tbranch INT, trid INT, tparent INT,"
         1462  +       " UNIQUE(tbranch, trev), UNIQUE(trid)"
  1463   1463          ");"
  1464   1464          "CREATE TEMP TABLE xfiles("
  1465         -       " tpath TEXT, tbranch TEXT, tuuid TEXT, tperm TEXT,"
         1465  +       " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT, tsrcpath TEXT"
  1466   1466          " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
  1467   1467          ");"
  1468         -       "CREATE TEMP TABLE xsrc("
  1469         -       " tpath TEXT, tbranch TEXT, tsrc TEXT, tsrcbranch TEXT, tsrcrev INT"
         1468  +       "CREATE TEMP TABLE xbranches("
         1469  +       " tid INTEGER PRIMARY KEY, tbranch TEXT, ttype INT,"
         1470  +       " UNIQUE(tbranch, ttype)"
  1470   1471          ");"
  1471   1472          "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
  1472   1473       );
  1473   1474       if( zBase==0 ){ zBase = ""; }
  1474   1475       if( strlen(zBase)>0 ){
  1475   1476         if( zBase[strlen(zBase)-1]!='/' ){
  1476   1477           zBase = mprintf("%s/", zBase);