Fossil SCM

Another unfinished revision

baruch 2015-01-01 15:02 svn-import
Commit 65f9525be50929df48a084d25b3ef64c48325291
1 file changed +52 -51
+52 -51
--- src/import.c
+++ src/import.c
@@ -1084,52 +1084,65 @@
10841084
** Returns: 1 - It is on the trunk
10851085
** 2 - It is on a branch
10861086
** 3 - It is a tag
10871087
** 0 - It is none of the above
10881088
*/
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;
10901094
if( gsvn.lenTrunk==0 ){
1091
- *zBranch = "trunk";
1095
+ zBranch = "trunk";
10921096
*zFile = zPath;
1093
- return 1;
1097
+ type = 1;
10941098
}else
10951099
if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
1096
- *zBranch = "trunk";
1100
+ zBranch = "trunk";
10971101
if( zPath[gsvn.lenTrunk-1]=='/' ){
10981102
*zFile = zPath+gsvn.lenTrunk;;
10991103
}else if( zPath[gsvn.lenTrunk-1]==0 ){
11001104
*zFile = 0;
11011105
}else{
1102
- *zFile = *zBranch = 0;
1103
- return 0;
1106
+ *zFile = zBranch = 0;
1107
+ type = 0;
11041108
}
1105
- return 1;
1109
+ type = 1;
11061110
}else
11071111
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;
11091124
while( **zFile && **zFile!='/' ){ (*zFile)++; }
11101125
if( *zFile ){
11111126
**zFile = '\0';
11121127
(*zFile)++;
11131128
}else{
11141129
*zFile = 0;
11151130
}
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;
1126
- }
1127
- return 3;
1128
- }
1129
- *zFile = *zBranch = 0;
1130
- return 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();
1141
+ }
1142
+ }
1143
+ return branchId;
11311144
}
11321145
11331146
/*
11341147
** Read the svn-dump format from pIn and insert the corresponding
11351148
** content into the database.
@@ -1170,16 +1183,13 @@
11701183
db_prepare(&delPath,
11711184
"DELETE FROM xfiles"
11721185
" WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
11731186
" AND tbranch=:branch"
11741187
);
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)"
11811191
);
11821192
db_prepare(&cpyPath,
11831193
"INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
11841194
" SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
11851195
" FROM xfoci"
@@ -1203,32 +1213,28 @@
12031213
zDate = svn_find_prop(rec, "svn:date");
12041214
if( zDate ){
12051215
zDate = date_in_standard_format(zDate);
12061216
}
12071217
gsvn.zDate = zDate;
1218
+ db_bind_int(&addRev, ":rev", gsvn.rev);
12081219
fossil_print("\rImporting SVN revision: %d", gsvn.rev);
12091220
}else
12101221
if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
12111222
char *zAction = svn_find_header(rec, "Node-action");
12121223
char *zKind = svn_find_header(rec, "Node-kind");
12131224
char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
12141225
char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
1215
- char *zBranch;
12161226
char *zFile;
1217
- char *zSrcBranch;
1227
+ int srcBranch;
12181228
char *zSrcFile;
12191229
int deltaFlag = 0;
12201230
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 ){
12231233
svn_free_rec(&rec);
12241234
continue;
12251235
}
1226
- db_bind_text(&addBranch, ":branch", zBranch);
1227
- db_bind_int(&addBranch, ":type", branchType);
1228
- db_step(&addBranch);
1229
- db_reset(&addBranch);
12301236
if( (zTemp = svn_find_header(rec, "Text-delta")) ){
12311237
deltaFlag = strncmp(zTemp, "true", 4)==0;
12321238
}
12331239
if( zSrcPath ){
12341240
zTemp = svn_find_header(rec, "Node-copyfrom-rev");
@@ -1235,26 +1241,20 @@
12351241
if( zTemp ){
12361242
srcRev = atoi(zTemp);
12371243
}else{
12381244
fossil_fatal("Missing copyfrom-rev");
12391245
}
1240
- if( svn_parse_path(zSrcPath, &zSrcBranch, &zSrcFile)==0 ){
1246
+ srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
1247
+ if( srcBranch==0 ){
12411248
fossil_fatal("Copy from path outside the import paths");
12421249
}
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);
12501250
}
12511251
if( strncmp(zAction, "delete", 6)==0
12521252
|| strncmp(zAction, "replace", 7)==0 )
12531253
{
12541254
db_bind_text(&delPath, ":path", zFile);
1255
- db_bind_text(&delPath, ":branch", zBranch);
1255
+ db_bind_text(&delPath, ":branch", branchId);
12561256
db_step(&delPath);
12571257
db_reset(&delPath);
12581258
} /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
12591259
if( strncmp(zAction, "add", 3)==0
12601260
|| strncmp(zAction, "replace", 7)==0 )
@@ -1456,19 +1456,20 @@
14561456
db_finalize(&q);
14571457
}else
14581458
if( strncmp(g.argv[2], "svn", 3)==0 ){
14591459
db_multi_exec(
14601460
"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)"
14631463
");"
14641464
"CREATE TEMP TABLE xfiles("
1465
- " tpath TEXT, tbranch TEXT, tuuid TEXT, tperm TEXT,"
1465
+ " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT, tsrcpath TEXT"
14661466
" UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
14671467
");"
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)"
14701471
");"
14711472
"CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
14721473
);
14731474
if( zBase==0 ){ zBase = ""; }
14741475
if( strlen(zBase)>0 ){
14751476
--- src/import.c
+++ src/import.c
@@ -1084,52 +1084,65 @@
1084 ** Returns: 1 - It is on the trunk
1085 ** 2 - It is on a branch
1086 ** 3 - It is a tag
1087 ** 0 - It is none of the above
1088 */
1089 static int svn_parse_path(char *zPath, char **zBranch, char **zFile){
 
 
 
 
1090 if( gsvn.lenTrunk==0 ){
1091 *zBranch = "trunk";
1092 *zFile = zPath;
1093 return 1;
1094 }else
1095 if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
1096 *zBranch = "trunk";
1097 if( zPath[gsvn.lenTrunk-1]=='/' ){
1098 *zFile = zPath+gsvn.lenTrunk;;
1099 }else if( zPath[gsvn.lenTrunk-1]==0 ){
1100 *zFile = 0;
1101 }else{
1102 *zFile = *zBranch = 0;
1103 return 0;
1104 }
1105 return 1;
1106 }else
1107 if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
1108 *zFile = *zBranch = zPath+gsvn.lenBranches;
 
 
 
 
 
 
 
 
 
 
 
1109 while( **zFile && **zFile!='/' ){ (*zFile)++; }
1110 if( *zFile ){
1111 **zFile = '\0';
1112 (*zFile)++;
1113 }else{
1114 *zFile = 0;
1115 }
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;
1126 }
1127 return 3;
1128 }
1129 *zFile = *zBranch = 0;
1130 return 0;
1131 }
1132
1133 /*
1134 ** Read the svn-dump format from pIn and insert the corresponding
1135 ** content into the database.
@@ -1170,16 +1183,13 @@
1170 db_prepare(&delPath,
1171 "DELETE FROM xfiles"
1172 " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
1173 " AND tbranch=:branch"
1174 );
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)"
1181 );
1182 db_prepare(&cpyPath,
1183 "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
1184 " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
1185 " FROM xfoci"
@@ -1203,32 +1213,28 @@
1203 zDate = svn_find_prop(rec, "svn:date");
1204 if( zDate ){
1205 zDate = date_in_standard_format(zDate);
1206 }
1207 gsvn.zDate = zDate;
 
1208 fossil_print("\rImporting SVN revision: %d", gsvn.rev);
1209 }else
1210 if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
1211 char *zAction = svn_find_header(rec, "Node-action");
1212 char *zKind = svn_find_header(rec, "Node-kind");
1213 char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
1214 char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
1215 char *zBranch;
1216 char *zFile;
1217 char *zSrcBranch;
1218 char *zSrcFile;
1219 int deltaFlag = 0;
1220 int srcRev = 0;
1221 int branchType = svn_parse_path(zTemp, &zBranch, &zFile);
1222 if( branchType==0 ){
1223 svn_free_rec(&rec);
1224 continue;
1225 }
1226 db_bind_text(&addBranch, ":branch", zBranch);
1227 db_bind_int(&addBranch, ":type", branchType);
1228 db_step(&addBranch);
1229 db_reset(&addBranch);
1230 if( (zTemp = svn_find_header(rec, "Text-delta")) ){
1231 deltaFlag = strncmp(zTemp, "true", 4)==0;
1232 }
1233 if( zSrcPath ){
1234 zTemp = svn_find_header(rec, "Node-copyfrom-rev");
@@ -1235,26 +1241,20 @@
1235 if( zTemp ){
1236 srcRev = atoi(zTemp);
1237 }else{
1238 fossil_fatal("Missing copyfrom-rev");
1239 }
1240 if( svn_parse_path(zSrcPath, &zSrcBranch, &zSrcFile)==0 ){
 
1241 fossil_fatal("Copy from path outside the import paths");
1242 }
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 }
1251 if( strncmp(zAction, "delete", 6)==0
1252 || strncmp(zAction, "replace", 7)==0 )
1253 {
1254 db_bind_text(&delPath, ":path", zFile);
1255 db_bind_text(&delPath, ":branch", zBranch);
1256 db_step(&delPath);
1257 db_reset(&delPath);
1258 } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
1259 if( strncmp(zAction, "add", 3)==0
1260 || strncmp(zAction, "replace", 7)==0 )
@@ -1456,19 +1456,20 @@
1456 db_finalize(&q);
1457 }else
1458 if( strncmp(g.argv[2], "svn", 3)==0 ){
1459 db_multi_exec(
1460 "CREATE TEMP TABLE xrevisions("
1461 " tid INTEGER PRIMARY KEY, trev INTEGER, tbranch TEXT, ttype INT, trid INT,"
1462 " UNIQUE(tbranch, ttype, trev)"
1463 ");"
1464 "CREATE TEMP TABLE xfiles("
1465 " tpath TEXT, tbranch TEXT, tuuid TEXT, tperm TEXT,"
1466 " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
1467 ");"
1468 "CREATE TEMP TABLE xsrc("
1469 " tpath TEXT, tbranch TEXT, tsrc TEXT, tsrcbranch TEXT, tsrcrev INT"
 
1470 ");"
1471 "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
1472 );
1473 if( zBase==0 ){ zBase = ""; }
1474 if( strlen(zBase)>0 ){
1475
--- src/import.c
+++ src/import.c
@@ -1084,52 +1084,65 @@
1084 ** Returns: 1 - It is on the trunk
1085 ** 2 - It is on a branch
1086 ** 3 - It is a tag
1087 ** 0 - It is none of the above
1088 */
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;
1094 if( gsvn.lenTrunk==0 ){
1095 zBranch = "trunk";
1096 *zFile = zPath;
1097 type = 1;
1098 }else
1099 if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
1100 zBranch = "trunk";
1101 if( zPath[gsvn.lenTrunk-1]=='/' ){
1102 *zFile = zPath+gsvn.lenTrunk;;
1103 }else if( zPath[gsvn.lenTrunk-1]==0 ){
1104 *zFile = 0;
1105 }else{
1106 *zFile = zBranch = 0;
1107 type = 0;
1108 }
1109 type = 1;
1110 }else
1111 if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
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;
1124 while( **zFile && **zFile!='/' ){ (*zFile)++; }
1125 if( *zFile ){
1126 **zFile = '\0';
1127 (*zFile)++;
1128 }else{
1129 *zFile = 0;
1130 }
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();
1141 }
1142 }
1143 return branchId;
 
 
1144 }
1145
1146 /*
1147 ** Read the svn-dump format from pIn and insert the corresponding
1148 ** content into the database.
@@ -1170,16 +1183,13 @@
1183 db_prepare(&delPath,
1184 "DELETE FROM xfiles"
1185 " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
1186 " AND tbranch=:branch"
1187 );
1188 db_prepare(&addRev,
1189 "INSERT OR IGNORE INTO xrevisions (trev, tbranch, tparent)"
1190 " VALUES(:rev, :branch, :parent)"
 
 
 
1191 );
1192 db_prepare(&cpyPath,
1193 "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
1194 " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
1195 " FROM xfoci"
@@ -1203,32 +1213,28 @@
1213 zDate = svn_find_prop(rec, "svn:date");
1214 if( zDate ){
1215 zDate = date_in_standard_format(zDate);
1216 }
1217 gsvn.zDate = zDate;
1218 db_bind_int(&addRev, ":rev", gsvn.rev);
1219 fossil_print("\rImporting SVN revision: %d", gsvn.rev);
1220 }else
1221 if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
1222 char *zAction = svn_find_header(rec, "Node-action");
1223 char *zKind = svn_find_header(rec, "Node-kind");
1224 char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
1225 char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
 
1226 char *zFile;
1227 int srcBranch;
1228 char *zSrcFile;
1229 int deltaFlag = 0;
1230 int srcRev = 0;
1231 int branchId = svn_parse_path(zTemp, &zFile);
1232 if( branchId==0 ){
1233 svn_free_rec(&rec);
1234 continue;
1235 }
 
 
 
 
1236 if( (zTemp = svn_find_header(rec, "Text-delta")) ){
1237 deltaFlag = strncmp(zTemp, "true", 4)==0;
1238 }
1239 if( zSrcPath ){
1240 zTemp = svn_find_header(rec, "Node-copyfrom-rev");
@@ -1235,26 +1241,20 @@
1241 if( zTemp ){
1242 srcRev = atoi(zTemp);
1243 }else{
1244 fossil_fatal("Missing copyfrom-rev");
1245 }
1246 srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
1247 if( srcBranch==0 ){
1248 fossil_fatal("Copy from path outside the import paths");
1249 }
 
 
 
 
 
 
 
1250 }
1251 if( strncmp(zAction, "delete", 6)==0
1252 || strncmp(zAction, "replace", 7)==0 )
1253 {
1254 db_bind_text(&delPath, ":path", zFile);
1255 db_bind_text(&delPath, ":branch", branchId);
1256 db_step(&delPath);
1257 db_reset(&delPath);
1258 } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
1259 if( strncmp(zAction, "add", 3)==0
1260 || strncmp(zAction, "replace", 7)==0 )
@@ -1456,19 +1456,20 @@
1456 db_finalize(&q);
1457 }else
1458 if( strncmp(g.argv[2], "svn", 3)==0 ){
1459 db_multi_exec(
1460 "CREATE TEMP TABLE xrevisions("
1461 " trev INTEGER, tbranch INT, trid INT, tparent INT,"
1462 " UNIQUE(tbranch, trev), UNIQUE(trid)"
1463 ");"
1464 "CREATE TEMP TABLE xfiles("
1465 " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT, tsrcpath TEXT"
1466 " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
1467 ");"
1468 "CREATE TEMP TABLE xbranches("
1469 " tid INTEGER PRIMARY KEY, tbranch TEXT, ttype INT,"
1470 " UNIQUE(tbranch, ttype)"
1471 ");"
1472 "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;"
1473 );
1474 if( zBase==0 ){ zBase = ""; }
1475 if( strlen(zBase)>0 ){
1476

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button