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 Unified Diffs Show Whitespace Changes Patch

Changes to src/import.c.

1082
1083
1084
1085
1086
1087
1088
1089




1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108











1109
1110
1111
1112
1113
1114
1115
1116
1117

1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
....
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
....
1201
1202
1203
1204
1205
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
1260
1261
1262
....
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469

1470
1471
1472
1473
1474
1475
1476
/*
** Extract the name of the branch or tag that the given path is on.
** Returns: 1 - It is on the trunk
**          2 - It is on a branch
**          3 - It is a tag
**          0 - It is none of the above
 */
static int svn_parse_path(char *zPath, char **zBranch, char **zFile){




  if( gsvn.lenTrunk==0 ){
    *zBranch = "trunk";
    *zFile = zPath;
    return 1;

  }else
  if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
    *zBranch = "trunk";
    if( zPath[gsvn.lenTrunk-1]=='/' ){
      *zFile = zPath+gsvn.lenTrunk;;
    }else if( zPath[gsvn.lenTrunk-1]==0 ){
      *zFile = 0;
    }else{
      *zFile = *zBranch = 0;
      return 0;
    }
    return 1;
  }else
  if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
    *zFile = *zBranch = zPath+gsvn.lenBranches;











    while( **zFile && **zFile!='/' ){ (*zFile)++; }
    if( *zFile ){
      **zFile = '\0';
      (*zFile)++;
    }else{
      *zFile = 0;
    }
    return 2;
  }else

  if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
    *zFile = *zBranch = zPath+gsvn.lenTags;
    while( **zFile && **zFile!='/' ){ (*zFile)++; }
    if( *zFile ){
      **zFile = '\0';
      (*zFile)++;
    }else{
      *zFile = 0;
    }
    return 3;
  }
  *zFile = *zBranch = 0;
  return 0;
}

/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn){
................................................................................
    " VALUES(:path, :branch, (SELECT uuid FROM blob WHERE rid=:rid), :perm)"
  );
  db_prepare(&delPath,
    "DELETE FROM xfiles"
    " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
    "     AND tbranch=:branch"
  );
  db_prepare(&addSrc,
    "INSERT INTO xsrc (tpath, tbranch, tsrc, tsrcbranch, tsrcrev)"
    " VALUES(:path, :branch, :srcpath, :srcbranch, :srcrev)"
  );
  db_prepare(&addBranch,
    "INSERT INTO xchanges (tbranch, ttype) VALUES(:branch, :type)"
  );
  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.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;

      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");
      char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
      char *zBranch;
      char *zFile;
      char *zSrcBranch;
      char *zSrcFile;
      int deltaFlag = 0;
      int srcRev = 0;
      int branchType = svn_parse_path(zTemp, &zBranch, &zFile);
      if( branchType==0 ){
        svn_free_rec(&rec);
        continue;
      }
      db_bind_text(&addBranch, ":branch", zBranch);
      db_bind_int(&addBranch, ":type", branchType);
      db_step(&addBranch);
      db_reset(&addBranch);
      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");
        }
        if( svn_parse_path(zSrcPath, &zSrcBranch, &zSrcFile)==0 ){

          fossil_fatal("Copy from path outside the import paths");
        }
        db_bind_text(&addSrc, ":path", zFile);
        db_bind_text(&addSrc, ":branch", zBranch);
        db_bind_text(&addSrc, ":srcpath", zSrcFile);
        db_bind_text(&addSrc, ":srcbranch", zSrcBranch);
        db_bind_int(&addSrc, ":srcrev", srcRev);
        db_step(&addSrc);
        db_reset(&addSrc);
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        db_bind_text(&delPath, ":path", zFile);
        db_bind_text(&delPath, ":branch", zBranch);
        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 ){
................................................................................
      import_reset(0);
    }
    db_finalize(&q);
  }else
  if( strncmp(g.argv[2], "svn", 3)==0 ){
    db_multi_exec(
       "CREATE TEMP TABLE xrevisions("
       " tid INTEGER PRIMARY KEY, trev INTEGER, tbranch TEXT, ttype INT, trid INT,"
       " UNIQUE(tbranch, ttype, trev)"
       ");"
       "CREATE TEMP TABLE xfiles("
       " tpath TEXT, tbranch TEXT, tuuid TEXT, tperm TEXT,"
       " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xsrc("
       " tpath TEXT, tbranch TEXT, tsrc TEXT, tsrcbranch TEXT, tsrcrev INT"

       ");"
       "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);







|
>
>
>
>

|

<
>


|





|
|

|


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







|
<
>
|
|
|
|
|
|
|
|

<

<
|







 







|
|
|
<
<
<







 







>







<

|



|
|



<
<
<
<










|
>


<
<
<
<
<
<
<





|







 







|
|


|


|
|
>







1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131

1132
1133
1134
1135
1136
1137
1138
1139
1140
1141

1142

1143
1144
1145
1146
1147
1148
1149
1150
....
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190



1191
1192
1193
1194
1195
1196
1197
....
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
1260
1261
1262
....
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
/*
** Extract the name of the branch or tag that the given path is on.
** Returns: 1 - It is on the trunk
**          2 - It is on a branch
**          3 - It is a tag
**          0 - It is none of the above
 */
static int svn_parse_path(char *zPath, char **zFile){
  int type = 0;
  char *zBranch = 0;
  int branchId = 0;
  *zFile = 0;
  if( gsvn.lenTrunk==0 ){
    zBranch = "trunk";
    *zFile = zPath;

    type = 1;
  }else
  if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
    zBranch = "trunk";
    if( zPath[gsvn.lenTrunk-1]=='/' ){
      *zFile = zPath+gsvn.lenTrunk;;
    }else if( zPath[gsvn.lenTrunk-1]==0 ){
      *zFile = 0;
    }else{
      *zFile = zBranch = 0;
      type = 0;
    }
    type = 1;
  }else
  if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
    *zFile = zBranch = zPath+gsvn.lenBranches;
    while( **zFile && **zFile!='/' ){ (*zFile)++; }
    if( *zFile ){
      **zFile = '\0';
      (*zFile)++;
    }else{
      *zFile = 0;
    }
    type = 2;
  }else
  if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
    *zFile = zBranch = zPath+gsvn.lenTags;
    while( **zFile && **zFile!='/' ){ (*zFile)++; }
    if( *zFile ){
      **zFile = '\0';
      (*zFile)++;
    }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;
}

/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn){
................................................................................
    " VALUES(:path, :branch, (SELECT uuid FROM blob WHERE rid=:rid), :perm)"
  );
  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.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");
      char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;

      char *zFile;
      int srcBranch;
      char *zSrcFile;
      int deltaFlag = 0;
      int srcRev = 0;
      int branchId = svn_parse_path(zTemp, &zFile);
      if( branchId==0 ){
        svn_free_rec(&rec);
        continue;
      }




      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");
        }
        srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
        if( srcBranch==0 ){
          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 ){
................................................................................
      import_reset(0);
    }
    db_finalize(&q);
  }else
  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);