Fossil SCM
Seems to work again on a simple test case. Not finished or well tested
Commit
ea876c3f17ed018bf19c9dde82bdee640f0af153
Parent
65f9525be50929d…
1 file changed
+122
-145
+122
-145
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -900,132 +900,86 @@ | ||
| 900 | 900 | return 1; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | static void svn_finish_revision(){ |
| 904 | 904 | Blob manifest; |
| 905 | - static Stmt insRev; | |
| 905 | + static Stmt getChanges; | |
| 906 | + static Stmt getFiles; | |
| 907 | + static Stmt setRid; | |
| 906 | 908 | Blob mcksum; |
| 907 | 909 | |
| 908 | 910 | blob_zero(&manifest); |
| 909 | - db_static_prepare(&getChanges, "SELECT tbranch, ttype FROM xchanged"); | |
| 910 | - db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm," | |
| 911 | - " tsrc, tsrcbranch, trev tsrcrev" | |
| 912 | - " FROM xfiles, xsrc" | |
| 913 | - " ON tpath, tbranch)" | |
| 914 | - " WHERE tbranch=:branch ORDER BY tpath"); | |
| 915 | - db_static_prepare(&setRid, "REPLACE INTO xrevisions(trev, tbranch, trid)" | |
| 916 | - " VALUES (%d, :branch, :rid)", gsvn.rev); | |
| 917 | - if( !gsvn.flatFlag ){ | |
| 918 | - if( gsvn.parentRev<0 ){ | |
| 919 | - gsvn.parentRev = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions " | |
| 920 | - "WHERE tbranch=%Q", gsvn.zBranch); | |
| 921 | - if( gsvn.parentRev<0 ){ | |
| 922 | - gsvn.parentRev = | |
| 923 | - db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions"); | |
| 924 | - } | |
| 925 | - gsvn.zParentBranch = gsvn.zBranch; | |
| 926 | - }else if( gsvn.zParentBranch==0 ){ | |
| 927 | - gsvn.zParentBranch = mprintf("trunk"); | |
| 928 | - } | |
| 929 | - /*db_bind_int(&insRev, ":rev", gsvn.rev); | |
| 930 | - db_bind_text(&insRev, ":branch", gsvn.zBranch); | |
| 931 | - db_bind_int(&insRev, ":rid", 0); | |
| 932 | - db_step(&insRev); | |
| 933 | - db_reset(&insRev);*/ | |
| 934 | - }else{ | |
| 935 | - static int prevRev = -1; | |
| 936 | - gsvn.parentRev = prevRev; | |
| 937 | - gsvn.zParentBranch = gsvn.zBranch = ""; | |
| 938 | - prevRev = gsvn.rev; | |
| 939 | - } | |
| 940 | - | |
| 941 | - if( gsvn.zComment ){ | |
| 942 | - blob_appendf(&manifest, "C %F\n", gsvn.zComment); | |
| 943 | - }else{ | |
| 944 | - blob_append(&manifest, "C (no\\scomment)\n", 16); | |
| 945 | - } | |
| 946 | - if( gsvn.zDate ){ | |
| 947 | - blob_appendf(&manifest, "D %s\n", gsvn.zDate); | |
| 948 | - }else{ | |
| 949 | - goto skip_revision; | |
| 950 | - } | |
| 951 | - nFilter = blob_size(&gsvn.filter)-1; | |
| 952 | - db_bind_text(&qFiles, ":filter", blob_str(&gsvn.filter)); | |
| 953 | - while( db_step(&qFiles)==SQLITE_ROW ){ | |
| 954 | - const char *zFile = db_column_text(&qFiles, 0); | |
| 955 | - int rid = db_column_int(&qFiles, 1); | |
| 956 | - const char *zPerm = db_column_text(&qFiles, 2); | |
| 957 | - char *zUuid; | |
| 958 | - zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); | |
| 959 | - blob_appendf(&manifest, "F %F %s %s\n", zFile+nFilter, zUuid, zPerm); | |
| 960 | - fossil_free(zUuid); | |
| 961 | - } | |
| 962 | - db_reset(&qFiles); | |
| 963 | - if( gsvn.parentRev>=0 ){ | |
| 964 | - const char *zParentUuid; | |
| 965 | - db_bind_int(&qParent, ":rev", gsvn.parentRev); | |
| 966 | - db_bind_text(&qParent, ":branch", gsvn.zParentBranch); | |
| 967 | - db_step(&qParent); | |
| 968 | - zParentUuid = db_column_text(&qParent, 0); | |
| 969 | - if( zParentUuid==0 ){ | |
| 970 | - db_bind_text(&qParent2, ":branch", gsvn.zParentBranch); | |
| 971 | - db_step(&qParent2); | |
| 972 | - zParentUuid = db_column_text(&qParent2, 0); | |
| 973 | - } | |
| 974 | - blob_appendf(&manifest, "P %s\n", zParentUuid); | |
| 975 | - if( !gsvn.flatFlag ){ | |
| 976 | - if( strcmp(gsvn.zBranch, gsvn.zParentBranch)!=0 ){ | |
| 977 | - blob_appendf(&manifest, "T *branch * %F\n", gsvn.zBranch); | |
| 978 | - blob_appendf(&manifest, "T *sym-%F *\n", gsvn.zBranch); | |
| 979 | - zParentBranch = mprintf("%F", gsvn.zParentBranch); | |
| 980 | - }else{ | |
| 981 | - zParentBranch = 0; | |
| 982 | - } | |
| 983 | - } | |
| 984 | - db_reset(&qParent); | |
| 985 | - db_reset(&qParent2); | |
| 986 | - }else{ | |
| 987 | - blob_appendf(&manifest, "T *branch * trunk\n"); | |
| 988 | - blob_appendf(&manifest, "T *sym-trunk *\n"); | |
| 989 | - } | |
| 990 | - db_bind_int(&qTags, ":rev", gsvn.rev); | |
| 991 | - while( db_step(&qTags)==SQLITE_ROW ){ | |
| 992 | - const char *zTag = db_column_text(&qTags, 0); | |
| 993 | - blob_appendf(&manifest, "T +sym-%s *\n", zTag); | |
| 994 | - } | |
| 995 | - db_reset(&qTags); | |
| 996 | - blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); | |
| 997 | - if( zParentBranch ) { | |
| 998 | - blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch); | |
| 999 | - fossil_free(zParentBranch); | |
| 1000 | - } | |
| 1001 | - if( gsvn.zUser ){ | |
| 1002 | - blob_appendf(&manifest, "U %F\n", gsvn.zUser); | |
| 1003 | - }else{ | |
| 1004 | - const char *zUserOvrd = find_option("user-override",0,1); | |
| 1005 | - blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name()); | |
| 1006 | - } | |
| 1007 | - md5sum_blob(&manifest, &mcksum); | |
| 1008 | - blob_appendf(&manifest, "Z %b\n", &mcksum); | |
| 1009 | - blob_reset(&mcksum); | |
| 1010 | - | |
| 1011 | - rid = content_put(&manifest); | |
| 1012 | - db_bind_int(&insRev, ":rev", gsvn.rev); | |
| 1013 | - db_bind_text(&insRev, ":branch", gsvn.zBranch); | |
| 1014 | - db_bind_int(&insRev, ":rid", rid); | |
| 1015 | - db_step(&insRev); | |
| 1016 | - db_reset(&insRev); | |
| 1017 | - | |
| 1018 | -skip_revision: | |
| 1019 | - blob_resize(&gsvn.filter, nBaseFilter); | |
| 1020 | - if( gsvn.zParentBranch == gsvn.zBranch ){ | |
| 1021 | - gsvn.zParentBranch = 0; | |
| 1022 | - } | |
| 1023 | - if( gsvn.flatFlag ){ | |
| 1024 | - gsvn.zBranch = 0; | |
| 1025 | - } | |
| 1026 | - blob_reset(&manifest); | |
| 911 | + db_static_prepare(&getChanges, "SELECT tid, tname, ttype, tparent" | |
| 912 | + " FROM xrevisions, xbranches ON (tbranch=tid)" | |
| 913 | + " WHERE trid ISNULL"); | |
| 914 | + db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm FROM xfiles" | |
| 915 | + " WHERE tbranch=:branch ORDER BY tpath"); | |
| 916 | + db_prepare(&setRid, "UPDATE xrevisions SET trid=:rid" | |
| 917 | + " WHERE trev=%d AND tbranch=:branch", gsvn.rev); | |
| 918 | + while( db_step(&getChanges)==SQLITE_ROW ){ | |
| 919 | + int branchId = db_column_int(&getChanges, 0); | |
| 920 | + const char *zBranch = db_column_text(&getChanges, 1); | |
| 921 | + int branchType = db_column_int(&getChanges, 2); | |
| 922 | + int parentRid = db_column_int(&getChanges, 3); | |
| 923 | + int onBranch = 0; | |
| 924 | + int rid; | |
| 925 | + if( branchType!=3 ){ | |
| 926 | + if( gsvn.zComment ){ | |
| 927 | + blob_appendf(&manifest, "C %F\n", gsvn.zComment); | |
| 928 | + }else{ | |
| 929 | + blob_append(&manifest, "C (no\\scomment)\n", 16); | |
| 930 | + } | |
| 931 | + blob_appendf(&manifest, "D %s\n", gsvn.zDate); | |
| 932 | + db_bind_int(&getFiles, ":branch", branchId); | |
| 933 | + while( db_step(&getFiles)==SQLITE_ROW ){ | |
| 934 | + const char *zFile = db_column_text(&getFiles, 0); | |
| 935 | + const char *zUuid = db_column_text(&getFiles, 1); | |
| 936 | + const char *zPerm = db_column_text(&getFiles, 2); | |
| 937 | + blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm); | |
| 938 | + } | |
| 939 | + db_reset(&getFiles); | |
| 940 | + if( parentRid==0 ){ | |
| 941 | + parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" | |
| 942 | + " WHERE trev<%d AND tbranch=%d", gsvn.rev, branchId); | |
| 943 | + onBranch = 1; | |
| 944 | + } | |
| 945 | + if( parentRid>0 ){ | |
| 946 | + const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid); | |
| 947 | + blob_appendf(&manifest, "P %s\n", zParentUuid); | |
| 948 | + if( onBranch==0 ){ | |
| 949 | + const char *zParentBranch = db_text(0, "SELECT tbranch FROM xbranches WHERE tid=(SELECT tbranch FROM xrevisions WHERE trid=%d)", parentRid); | |
| 950 | + blob_appendf(&manifest, "T *branch * %F\n", zBranch); | |
| 951 | + blob_appendf(&manifest, "T *sym-%F *\n", zBranch); | |
| 952 | + blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); | |
| 953 | + blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch); | |
| 954 | + } | |
| 955 | + }else{ | |
| 956 | + blob_appendf(&manifest, "T *branch * %F\n", zBranch); | |
| 957 | + blob_appendf(&manifest, "T *sym-%F *\n", zBranch); | |
| 958 | + blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); | |
| 959 | + } | |
| 960 | + if( gsvn.zUser ){ | |
| 961 | + blob_appendf(&manifest, "U %F\n", gsvn.zUser); | |
| 962 | + }else{ | |
| 963 | + const char *zUserOvrd = find_option("user-override",0,1); | |
| 964 | + blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name()); | |
| 965 | + } | |
| 966 | + md5sum_blob(&manifest, &mcksum); | |
| 967 | + blob_appendf(&manifest, "Z %b\n", &mcksum); | |
| 968 | + blob_reset(&mcksum); | |
| 969 | + }else{ | |
| 970 | +// TODO tag | |
| 971 | + } | |
| 972 | + rid = content_put(&manifest); | |
| 973 | + db_bind_int(&setRid, ":branch", branchId); | |
| 974 | + db_bind_int(&setRid, ":rid", rid); | |
| 975 | + db_step(&setRid); | |
| 976 | + db_reset(&setRid); | |
| 977 | + blob_reset(&manifest); | |
| 978 | + } | |
| 979 | + db_reset(&getChanges); | |
| 980 | + db_finalize(&setRid); | |
| 1027 | 981 | } |
| 1028 | 982 | |
| 1029 | 983 | static u64 svn_get_varint(const char **pz){ |
| 1030 | 984 | unsigned int v = 0; |
| 1031 | 985 | do{ |
| @@ -1130,15 +1084,15 @@ | ||
| 1130 | 1084 | } |
| 1131 | 1085 | type = 3; |
| 1132 | 1086 | } |
| 1133 | 1087 | if( type>0 ){ |
| 1134 | 1088 | branchId = db_int(0, |
| 1135 | - "SELECT tid FROM xbranches WHERE tbranch=%Q AND ttype=%d", | |
| 1136 | - zBranch, branchType); | |
| 1089 | + "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d", | |
| 1090 | + zBranch, type); | |
| 1137 | 1091 | if( branchId==0 ){ |
| 1138 | - db_multi_exec("INSERT INTO xbranches (tbranch, ttype) VALUES(%Q, %d)", | |
| 1139 | - zBranch, branchType); | |
| 1092 | + db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)", | |
| 1093 | + zBranch, type); | |
| 1140 | 1094 | branchId = db_last_insert_rowid(); |
| 1141 | 1095 | } |
| 1142 | 1096 | } |
| 1143 | 1097 | return branchId; |
| 1144 | 1098 | } |
| @@ -1152,13 +1106,13 @@ | ||
| 1152 | 1106 | int ver; |
| 1153 | 1107 | char *zTemp; |
| 1154 | 1108 | const char *zUuid; |
| 1155 | 1109 | Stmt addFile; |
| 1156 | 1110 | Stmt delPath; |
| 1157 | - Stmt addSrc; | |
| 1158 | - Stmt addBranch; | |
| 1111 | + Stmt addRev; | |
| 1159 | 1112 | Stmt cpyPath; |
| 1113 | + Stmt revSrc; | |
| 1160 | 1114 | |
| 1161 | 1115 | /* version */ |
| 1162 | 1116 | if( svn_read_rec(pIn, &rec) |
| 1163 | 1117 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1164 | 1118 | ver = atoi(zTemp); |
| @@ -1184,18 +1138,21 @@ | ||
| 1184 | 1138 | "DELETE FROM xfiles" |
| 1185 | 1139 | " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))" |
| 1186 | 1140 | " AND tbranch=:branch" |
| 1187 | 1141 | ); |
| 1188 | 1142 | db_prepare(&addRev, |
| 1189 | - "INSERT OR IGNORE INTO xrevisions (trev, tbranch, tparent)" | |
| 1190 | - " VALUES(:rev, :branch, :parent)" | |
| 1143 | + "INSERT OR IGNORE INTO xrevisions (trev, tbranch)" | |
| 1144 | + " VALUES(:rev, :branch)" | |
| 1191 | 1145 | ); |
| 1192 | 1146 | db_prepare(&cpyPath, |
| 1193 | 1147 | "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)" |
| 1194 | 1148 | " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm" |
| 1195 | 1149 | " FROM xfoci" |
| 1196 | - " WHERE chekinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'" | |
| 1150 | + " WHERE checkinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'" | |
| 1151 | + ); | |
| 1152 | + db_prepare(&revSrc, | |
| 1153 | + "UPDATE xrevisions SET tparent=:parent WHERE trev=:rev AND tbranch=:branch" | |
| 1197 | 1154 | ); |
| 1198 | 1155 | gsvn.rev = -1; |
| 1199 | 1156 | while( svn_read_rec(pIn, &rec) ){ |
| 1200 | 1157 | if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */ |
| 1201 | 1158 | /* finish previous revision */ |
| @@ -1210,13 +1167,14 @@ | ||
| 1210 | 1167 | gsvn.rev = atoi(zTemp); |
| 1211 | 1168 | gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author")); |
| 1212 | 1169 | gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log")); |
| 1213 | 1170 | zDate = svn_find_prop(rec, "svn:date"); |
| 1214 | 1171 | if( zDate ){ |
| 1215 | - zDate = date_in_standard_format(zDate); | |
| 1172 | + gsvn.zDate = date_in_standard_format(zDate); | |
| 1173 | + }else{ | |
| 1174 | + gsvn.zDate = date_in_standard_format("now"); | |
| 1216 | 1175 | } |
| 1217 | - gsvn.zDate = zDate; | |
| 1218 | 1176 | db_bind_int(&addRev, ":rev", gsvn.rev); |
| 1219 | 1177 | fossil_print("\rImporting SVN revision: %d", gsvn.rev); |
| 1220 | 1178 | }else |
| 1221 | 1179 | if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */ |
| 1222 | 1180 | char *zAction = svn_find_header(rec, "Node-action"); |
| @@ -1250,37 +1208,50 @@ | ||
| 1250 | 1208 | } |
| 1251 | 1209 | if( strncmp(zAction, "delete", 6)==0 |
| 1252 | 1210 | || strncmp(zAction, "replace", 7)==0 ) |
| 1253 | 1211 | { |
| 1254 | 1212 | db_bind_text(&delPath, ":path", zFile); |
| 1255 | - db_bind_text(&delPath, ":branch", branchId); | |
| 1213 | + db_bind_int(&delPath, ":branch", branchId); | |
| 1256 | 1214 | db_step(&delPath); |
| 1257 | 1215 | db_reset(&delPath); |
| 1216 | + db_bind_int(&addRev, ":branch", branchId); | |
| 1217 | + db_step(&addRev); | |
| 1218 | + db_reset(&addRev); | |
| 1258 | 1219 | } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */ |
| 1259 | 1220 | if( strncmp(zAction, "add", 3)==0 |
| 1260 | 1221 | || strncmp(zAction, "replace", 7)==0 ) |
| 1261 | 1222 | { |
| 1262 | 1223 | if( zKind==0 ){ |
| 1263 | 1224 | fossil_fatal("Missing Node-kind"); |
| 1264 | 1225 | }else if( strncmp(zKind, "dir", 3)==0 ){ |
| 1265 | 1226 | if( zSrcPath ){ |
| 1266 | 1227 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1267 | - " WHERE trev<=%d AND tbranch=%Q", | |
| 1268 | - srcRev, zSrcBranch); | |
| 1228 | + " WHERE trev<=%d AND tbranch=%d", | |
| 1229 | + srcRev, srcBranch); | |
| 1269 | 1230 | db_bind_text(&cpyPath, ":path", zFile); |
| 1270 | - db_bind_text(&cpyPath, ":branch", zBranch); | |
| 1231 | + db_bind_int(&cpyPath, ":branch", branchId); | |
| 1271 | 1232 | db_bind_text(&cpyPath, ":srcpath", zSrcFile); |
| 1272 | 1233 | db_bind_int(&cpyPath, ":rid", srcRid); |
| 1273 | 1234 | db_step(&cpyPath); |
| 1274 | 1235 | db_reset(&cpyPath); |
| 1236 | + db_bind_int(&addRev, ":branch", branchId); | |
| 1237 | + db_step(&addRev); | |
| 1238 | + db_reset(&addRev); | |
| 1239 | + if( zFile==0 ){ | |
| 1240 | + db_bind_int(&revSrc, ":parent", srcRid); | |
| 1241 | + db_bind_int(&revSrc, ":rev", srcRev); | |
| 1242 | + db_bind_int(&revSrc, ":branch", branchId); | |
| 1243 | + db_step(&revSrc); | |
| 1244 | + db_reset(&revSrc); | |
| 1245 | + } | |
| 1275 | 1246 | } |
| 1276 | 1247 | }else{ |
| 1277 | 1248 | int rid = 0; |
| 1278 | 1249 | if( zSrcPath ){ |
| 1279 | 1250 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1280 | - " WHERE trev<=%d AND tbranch=%Q", | |
| 1281 | - srcRev, zSrcBranch); | |
| 1251 | + " WHERE trev<=%d AND tbranch=%d", | |
| 1252 | + srcRev, srcBranch); | |
| 1282 | 1253 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1283 | 1254 | " SELECT uuid FROM xfoci" |
| 1284 | 1255 | " WHERE chekinID=%d AND filename=%Q" |
| 1285 | 1256 | ")", |
| 1286 | 1257 | srcRid, zSrcFile); |
| @@ -1297,15 +1268,18 @@ | ||
| 1297 | 1268 | rid = content_put(&target); |
| 1298 | 1269 | }else if( rec.contentFlag ){ |
| 1299 | 1270 | rid = content_put(&rec.content); |
| 1300 | 1271 | } |
| 1301 | 1272 | db_bind_text(&addFile, ":path", zFile); |
| 1302 | - db_bind_text(&addFile, ":branch", zBranch); | |
| 1273 | + db_bind_int(&addFile, ":branch", branchId); | |
| 1303 | 1274 | db_bind_int(&addFile, ":rid", rid); |
| 1304 | 1275 | db_bind_text(&addFile, ":perm", zPerm); |
| 1305 | 1276 | db_step(&addFile); |
| 1306 | 1277 | db_reset(&addFile); |
| 1278 | + db_bind_int(&addRev, ":branch", branchId); | |
| 1279 | + db_step(&addRev); | |
| 1280 | + db_reset(&addRev); | |
| 1307 | 1281 | } |
| 1308 | 1282 | }else |
| 1309 | 1283 | if( strncmp(zAction, "change", 6)==0 ){ |
| 1310 | 1284 | int rid = 0; |
| 1311 | 1285 | if( zKind==0 ){ |
| @@ -1315,24 +1289,27 @@ | ||
| 1315 | 1289 | if( deltaFlag ){ |
| 1316 | 1290 | Blob deltaSrc; |
| 1317 | 1291 | Blob target; |
| 1318 | 1292 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1319 | 1293 | " SELECT uuid FROM xfiles" |
| 1320 | - " WHERE tpath=%Q AND tbranch=%Q" | |
| 1321 | - ")", zFile, zBranch); | |
| 1294 | + " WHERE tpath=%Q AND tbranch=%d" | |
| 1295 | + ")", zFile, branchId); | |
| 1322 | 1296 | content_get(rid, &deltaSrc); |
| 1323 | 1297 | svn_apply_svndiff(&rec.content, &deltaSrc, &target); |
| 1324 | 1298 | rid = content_put(&target); |
| 1325 | 1299 | }else{ |
| 1326 | 1300 | rid = content_put(&rec.content); |
| 1327 | 1301 | } |
| 1328 | 1302 | db_bind_text(&addFile, ":path", zFile); |
| 1329 | - db_bind_text(&addFile, ":branch", zBranch); | |
| 1303 | + db_bind_int(&addFile, ":branch", branchId); | |
| 1330 | 1304 | db_bind_int(&addFile, ":rid", rid); |
| 1331 | 1305 | db_bind_text(&addFile, ":perm", zPerm); |
| 1332 | 1306 | db_step(&addFile); |
| 1333 | 1307 | db_reset(&addFile); |
| 1308 | + db_bind_int(&addRev, ":branch", branchId); | |
| 1309 | + db_step(&addRev); | |
| 1310 | + db_reset(&addRev); | |
| 1334 | 1311 | } |
| 1335 | 1312 | }else |
| 1336 | 1313 | if( strncmp(zAction, "delete", 6)!=0 ){ /* already did this one above */ |
| 1337 | 1314 | fossil_fatal("Unknown Node-action"); |
| 1338 | 1315 | } |
| @@ -1345,13 +1322,13 @@ | ||
| 1345 | 1322 | fossil_free(gsvn.zUser); |
| 1346 | 1323 | fossil_free(gsvn.zComment); |
| 1347 | 1324 | fossil_free(gsvn.zDate); |
| 1348 | 1325 | db_finalize(&addFile); |
| 1349 | 1326 | db_finalize(&delPath); |
| 1350 | - db_finalize(&addSrc); | |
| 1351 | - db_finalize(&addBranch); | |
| 1327 | + db_finalize(&addRev); | |
| 1352 | 1328 | db_finalize(&cpyPath); |
| 1329 | + db_finalize(&revSrc); | |
| 1353 | 1330 | fossil_print(" Done!\n"); |
| 1354 | 1331 | } |
| 1355 | 1332 | |
| 1356 | 1333 | /* |
| 1357 | 1334 | ** COMMAND: import |
| @@ -1460,16 +1437,16 @@ | ||
| 1460 | 1437 | "CREATE TEMP TABLE xrevisions(" |
| 1461 | 1438 | " trev INTEGER, tbranch INT, trid INT, tparent INT," |
| 1462 | 1439 | " UNIQUE(tbranch, trev), UNIQUE(trid)" |
| 1463 | 1440 | ");" |
| 1464 | 1441 | "CREATE TEMP TABLE xfiles(" |
| 1465 | - " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT, tsrcpath TEXT" | |
| 1442 | + " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT," | |
| 1466 | 1443 | " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE" |
| 1467 | 1444 | ");" |
| 1468 | 1445 | "CREATE TEMP TABLE xbranches(" |
| 1469 | - " tid INTEGER PRIMARY KEY, tbranch TEXT, ttype INT," | |
| 1470 | - " UNIQUE(tbranch, ttype)" | |
| 1446 | + " tid INTEGER PRIMARY KEY, tname TEXT, ttype INT," | |
| 1447 | + " UNIQUE(tname, ttype)" | |
| 1471 | 1448 | ");" |
| 1472 | 1449 | "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;" |
| 1473 | 1450 | ); |
| 1474 | 1451 | if( zBase==0 ){ zBase = ""; } |
| 1475 | 1452 | if( strlen(zBase)>0 ){ |
| 1476 | 1453 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -900,132 +900,86 @@ | |
| 900 | return 1; |
| 901 | } |
| 902 | |
| 903 | static void svn_finish_revision(){ |
| 904 | Blob manifest; |
| 905 | static Stmt insRev; |
| 906 | Blob mcksum; |
| 907 | |
| 908 | blob_zero(&manifest); |
| 909 | db_static_prepare(&getChanges, "SELECT tbranch, ttype FROM xchanged"); |
| 910 | db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm," |
| 911 | " tsrc, tsrcbranch, trev tsrcrev" |
| 912 | " FROM xfiles, xsrc" |
| 913 | " ON tpath, tbranch)" |
| 914 | " WHERE tbranch=:branch ORDER BY tpath"); |
| 915 | db_static_prepare(&setRid, "REPLACE INTO xrevisions(trev, tbranch, trid)" |
| 916 | " VALUES (%d, :branch, :rid)", gsvn.rev); |
| 917 | if( !gsvn.flatFlag ){ |
| 918 | if( gsvn.parentRev<0 ){ |
| 919 | gsvn.parentRev = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions " |
| 920 | "WHERE tbranch=%Q", gsvn.zBranch); |
| 921 | if( gsvn.parentRev<0 ){ |
| 922 | gsvn.parentRev = |
| 923 | db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions"); |
| 924 | } |
| 925 | gsvn.zParentBranch = gsvn.zBranch; |
| 926 | }else if( gsvn.zParentBranch==0 ){ |
| 927 | gsvn.zParentBranch = mprintf("trunk"); |
| 928 | } |
| 929 | /*db_bind_int(&insRev, ":rev", gsvn.rev); |
| 930 | db_bind_text(&insRev, ":branch", gsvn.zBranch); |
| 931 | db_bind_int(&insRev, ":rid", 0); |
| 932 | db_step(&insRev); |
| 933 | db_reset(&insRev);*/ |
| 934 | }else{ |
| 935 | static int prevRev = -1; |
| 936 | gsvn.parentRev = prevRev; |
| 937 | gsvn.zParentBranch = gsvn.zBranch = ""; |
| 938 | prevRev = gsvn.rev; |
| 939 | } |
| 940 | |
| 941 | if( gsvn.zComment ){ |
| 942 | blob_appendf(&manifest, "C %F\n", gsvn.zComment); |
| 943 | }else{ |
| 944 | blob_append(&manifest, "C (no\\scomment)\n", 16); |
| 945 | } |
| 946 | if( gsvn.zDate ){ |
| 947 | blob_appendf(&manifest, "D %s\n", gsvn.zDate); |
| 948 | }else{ |
| 949 | goto skip_revision; |
| 950 | } |
| 951 | nFilter = blob_size(&gsvn.filter)-1; |
| 952 | db_bind_text(&qFiles, ":filter", blob_str(&gsvn.filter)); |
| 953 | while( db_step(&qFiles)==SQLITE_ROW ){ |
| 954 | const char *zFile = db_column_text(&qFiles, 0); |
| 955 | int rid = db_column_int(&qFiles, 1); |
| 956 | const char *zPerm = db_column_text(&qFiles, 2); |
| 957 | char *zUuid; |
| 958 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 959 | blob_appendf(&manifest, "F %F %s %s\n", zFile+nFilter, zUuid, zPerm); |
| 960 | fossil_free(zUuid); |
| 961 | } |
| 962 | db_reset(&qFiles); |
| 963 | if( gsvn.parentRev>=0 ){ |
| 964 | const char *zParentUuid; |
| 965 | db_bind_int(&qParent, ":rev", gsvn.parentRev); |
| 966 | db_bind_text(&qParent, ":branch", gsvn.zParentBranch); |
| 967 | db_step(&qParent); |
| 968 | zParentUuid = db_column_text(&qParent, 0); |
| 969 | if( zParentUuid==0 ){ |
| 970 | db_bind_text(&qParent2, ":branch", gsvn.zParentBranch); |
| 971 | db_step(&qParent2); |
| 972 | zParentUuid = db_column_text(&qParent2, 0); |
| 973 | } |
| 974 | blob_appendf(&manifest, "P %s\n", zParentUuid); |
| 975 | if( !gsvn.flatFlag ){ |
| 976 | if( strcmp(gsvn.zBranch, gsvn.zParentBranch)!=0 ){ |
| 977 | blob_appendf(&manifest, "T *branch * %F\n", gsvn.zBranch); |
| 978 | blob_appendf(&manifest, "T *sym-%F *\n", gsvn.zBranch); |
| 979 | zParentBranch = mprintf("%F", gsvn.zParentBranch); |
| 980 | }else{ |
| 981 | zParentBranch = 0; |
| 982 | } |
| 983 | } |
| 984 | db_reset(&qParent); |
| 985 | db_reset(&qParent2); |
| 986 | }else{ |
| 987 | blob_appendf(&manifest, "T *branch * trunk\n"); |
| 988 | blob_appendf(&manifest, "T *sym-trunk *\n"); |
| 989 | } |
| 990 | db_bind_int(&qTags, ":rev", gsvn.rev); |
| 991 | while( db_step(&qTags)==SQLITE_ROW ){ |
| 992 | const char *zTag = db_column_text(&qTags, 0); |
| 993 | blob_appendf(&manifest, "T +sym-%s *\n", zTag); |
| 994 | } |
| 995 | db_reset(&qTags); |
| 996 | blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); |
| 997 | if( zParentBranch ) { |
| 998 | blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch); |
| 999 | fossil_free(zParentBranch); |
| 1000 | } |
| 1001 | if( gsvn.zUser ){ |
| 1002 | blob_appendf(&manifest, "U %F\n", gsvn.zUser); |
| 1003 | }else{ |
| 1004 | const char *zUserOvrd = find_option("user-override",0,1); |
| 1005 | blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name()); |
| 1006 | } |
| 1007 | md5sum_blob(&manifest, &mcksum); |
| 1008 | blob_appendf(&manifest, "Z %b\n", &mcksum); |
| 1009 | blob_reset(&mcksum); |
| 1010 | |
| 1011 | rid = content_put(&manifest); |
| 1012 | db_bind_int(&insRev, ":rev", gsvn.rev); |
| 1013 | db_bind_text(&insRev, ":branch", gsvn.zBranch); |
| 1014 | db_bind_int(&insRev, ":rid", rid); |
| 1015 | db_step(&insRev); |
| 1016 | db_reset(&insRev); |
| 1017 | |
| 1018 | skip_revision: |
| 1019 | blob_resize(&gsvn.filter, nBaseFilter); |
| 1020 | if( gsvn.zParentBranch == gsvn.zBranch ){ |
| 1021 | gsvn.zParentBranch = 0; |
| 1022 | } |
| 1023 | if( gsvn.flatFlag ){ |
| 1024 | gsvn.zBranch = 0; |
| 1025 | } |
| 1026 | blob_reset(&manifest); |
| 1027 | } |
| 1028 | |
| 1029 | static u64 svn_get_varint(const char **pz){ |
| 1030 | unsigned int v = 0; |
| 1031 | do{ |
| @@ -1130,15 +1084,15 @@ | |
| 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 | } |
| @@ -1152,13 +1106,13 @@ | |
| 1152 | int ver; |
| 1153 | char *zTemp; |
| 1154 | const char *zUuid; |
| 1155 | Stmt addFile; |
| 1156 | Stmt delPath; |
| 1157 | Stmt addSrc; |
| 1158 | Stmt addBranch; |
| 1159 | Stmt cpyPath; |
| 1160 | |
| 1161 | /* version */ |
| 1162 | if( svn_read_rec(pIn, &rec) |
| 1163 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1164 | ver = atoi(zTemp); |
| @@ -1184,18 +1138,21 @@ | |
| 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" |
| 1196 | " WHERE chekinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'" |
| 1197 | ); |
| 1198 | gsvn.rev = -1; |
| 1199 | while( svn_read_rec(pIn, &rec) ){ |
| 1200 | if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */ |
| 1201 | /* finish previous revision */ |
| @@ -1210,13 +1167,14 @@ | |
| 1210 | gsvn.rev = atoi(zTemp); |
| 1211 | gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author")); |
| 1212 | gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log")); |
| 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"); |
| @@ -1250,37 +1208,50 @@ | |
| 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 ) |
| 1261 | { |
| 1262 | if( zKind==0 ){ |
| 1263 | fossil_fatal("Missing Node-kind"); |
| 1264 | }else if( strncmp(zKind, "dir", 3)==0 ){ |
| 1265 | if( zSrcPath ){ |
| 1266 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1267 | " WHERE trev<=%d AND tbranch=%Q", |
| 1268 | srcRev, zSrcBranch); |
| 1269 | db_bind_text(&cpyPath, ":path", zFile); |
| 1270 | db_bind_text(&cpyPath, ":branch", zBranch); |
| 1271 | db_bind_text(&cpyPath, ":srcpath", zSrcFile); |
| 1272 | db_bind_int(&cpyPath, ":rid", srcRid); |
| 1273 | db_step(&cpyPath); |
| 1274 | db_reset(&cpyPath); |
| 1275 | } |
| 1276 | }else{ |
| 1277 | int rid = 0; |
| 1278 | if( zSrcPath ){ |
| 1279 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1280 | " WHERE trev<=%d AND tbranch=%Q", |
| 1281 | srcRev, zSrcBranch); |
| 1282 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1283 | " SELECT uuid FROM xfoci" |
| 1284 | " WHERE chekinID=%d AND filename=%Q" |
| 1285 | ")", |
| 1286 | srcRid, zSrcFile); |
| @@ -1297,15 +1268,18 @@ | |
| 1297 | rid = content_put(&target); |
| 1298 | }else if( rec.contentFlag ){ |
| 1299 | rid = content_put(&rec.content); |
| 1300 | } |
| 1301 | db_bind_text(&addFile, ":path", zFile); |
| 1302 | db_bind_text(&addFile, ":branch", zBranch); |
| 1303 | db_bind_int(&addFile, ":rid", rid); |
| 1304 | db_bind_text(&addFile, ":perm", zPerm); |
| 1305 | db_step(&addFile); |
| 1306 | db_reset(&addFile); |
| 1307 | } |
| 1308 | }else |
| 1309 | if( strncmp(zAction, "change", 6)==0 ){ |
| 1310 | int rid = 0; |
| 1311 | if( zKind==0 ){ |
| @@ -1315,24 +1289,27 @@ | |
| 1315 | if( deltaFlag ){ |
| 1316 | Blob deltaSrc; |
| 1317 | Blob target; |
| 1318 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1319 | " SELECT uuid FROM xfiles" |
| 1320 | " WHERE tpath=%Q AND tbranch=%Q" |
| 1321 | ")", zFile, zBranch); |
| 1322 | content_get(rid, &deltaSrc); |
| 1323 | svn_apply_svndiff(&rec.content, &deltaSrc, &target); |
| 1324 | rid = content_put(&target); |
| 1325 | }else{ |
| 1326 | rid = content_put(&rec.content); |
| 1327 | } |
| 1328 | db_bind_text(&addFile, ":path", zFile); |
| 1329 | db_bind_text(&addFile, ":branch", zBranch); |
| 1330 | db_bind_int(&addFile, ":rid", rid); |
| 1331 | db_bind_text(&addFile, ":perm", zPerm); |
| 1332 | db_step(&addFile); |
| 1333 | db_reset(&addFile); |
| 1334 | } |
| 1335 | }else |
| 1336 | if( strncmp(zAction, "delete", 6)!=0 ){ /* already did this one above */ |
| 1337 | fossil_fatal("Unknown Node-action"); |
| 1338 | } |
| @@ -1345,13 +1322,13 @@ | |
| 1345 | fossil_free(gsvn.zUser); |
| 1346 | fossil_free(gsvn.zComment); |
| 1347 | fossil_free(gsvn.zDate); |
| 1348 | db_finalize(&addFile); |
| 1349 | db_finalize(&delPath); |
| 1350 | db_finalize(&addSrc); |
| 1351 | db_finalize(&addBranch); |
| 1352 | db_finalize(&cpyPath); |
| 1353 | fossil_print(" Done!\n"); |
| 1354 | } |
| 1355 | |
| 1356 | /* |
| 1357 | ** COMMAND: import |
| @@ -1460,16 +1437,16 @@ | |
| 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 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -900,132 +900,86 @@ | |
| 900 | return 1; |
| 901 | } |
| 902 | |
| 903 | static void svn_finish_revision(){ |
| 904 | Blob manifest; |
| 905 | static Stmt getChanges; |
| 906 | static Stmt getFiles; |
| 907 | static Stmt setRid; |
| 908 | Blob mcksum; |
| 909 | |
| 910 | blob_zero(&manifest); |
| 911 | db_static_prepare(&getChanges, "SELECT tid, tname, ttype, tparent" |
| 912 | " FROM xrevisions, xbranches ON (tbranch=tid)" |
| 913 | " WHERE trid ISNULL"); |
| 914 | db_static_prepare(&getFiles, "SELECT tpath, tuuid, tperm FROM xfiles" |
| 915 | " WHERE tbranch=:branch ORDER BY tpath"); |
| 916 | db_prepare(&setRid, "UPDATE xrevisions SET trid=:rid" |
| 917 | " WHERE trev=%d AND tbranch=:branch", gsvn.rev); |
| 918 | while( db_step(&getChanges)==SQLITE_ROW ){ |
| 919 | int branchId = db_column_int(&getChanges, 0); |
| 920 | const char *zBranch = db_column_text(&getChanges, 1); |
| 921 | int branchType = db_column_int(&getChanges, 2); |
| 922 | int parentRid = db_column_int(&getChanges, 3); |
| 923 | int onBranch = 0; |
| 924 | int rid; |
| 925 | if( branchType!=3 ){ |
| 926 | if( gsvn.zComment ){ |
| 927 | blob_appendf(&manifest, "C %F\n", gsvn.zComment); |
| 928 | }else{ |
| 929 | blob_append(&manifest, "C (no\\scomment)\n", 16); |
| 930 | } |
| 931 | blob_appendf(&manifest, "D %s\n", gsvn.zDate); |
| 932 | db_bind_int(&getFiles, ":branch", branchId); |
| 933 | while( db_step(&getFiles)==SQLITE_ROW ){ |
| 934 | const char *zFile = db_column_text(&getFiles, 0); |
| 935 | const char *zUuid = db_column_text(&getFiles, 1); |
| 936 | const char *zPerm = db_column_text(&getFiles, 2); |
| 937 | blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm); |
| 938 | } |
| 939 | db_reset(&getFiles); |
| 940 | if( parentRid==0 ){ |
| 941 | parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 942 | " WHERE trev<%d AND tbranch=%d", gsvn.rev, branchId); |
| 943 | onBranch = 1; |
| 944 | } |
| 945 | if( parentRid>0 ){ |
| 946 | const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid); |
| 947 | blob_appendf(&manifest, "P %s\n", zParentUuid); |
| 948 | if( onBranch==0 ){ |
| 949 | const char *zParentBranch = db_text(0, "SELECT tbranch FROM xbranches WHERE tid=(SELECT tbranch FROM xrevisions WHERE trid=%d)", parentRid); |
| 950 | blob_appendf(&manifest, "T *branch * %F\n", zBranch); |
| 951 | blob_appendf(&manifest, "T *sym-%F *\n", zBranch); |
| 952 | blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); |
| 953 | blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch); |
| 954 | } |
| 955 | }else{ |
| 956 | blob_appendf(&manifest, "T *branch * %F\n", zBranch); |
| 957 | blob_appendf(&manifest, "T *sym-%F *\n", zBranch); |
| 958 | blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev); |
| 959 | } |
| 960 | if( gsvn.zUser ){ |
| 961 | blob_appendf(&manifest, "U %F\n", gsvn.zUser); |
| 962 | }else{ |
| 963 | const char *zUserOvrd = find_option("user-override",0,1); |
| 964 | blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name()); |
| 965 | } |
| 966 | md5sum_blob(&manifest, &mcksum); |
| 967 | blob_appendf(&manifest, "Z %b\n", &mcksum); |
| 968 | blob_reset(&mcksum); |
| 969 | }else{ |
| 970 | // TODO tag |
| 971 | } |
| 972 | rid = content_put(&manifest); |
| 973 | db_bind_int(&setRid, ":branch", branchId); |
| 974 | db_bind_int(&setRid, ":rid", rid); |
| 975 | db_step(&setRid); |
| 976 | db_reset(&setRid); |
| 977 | blob_reset(&manifest); |
| 978 | } |
| 979 | db_reset(&getChanges); |
| 980 | db_finalize(&setRid); |
| 981 | } |
| 982 | |
| 983 | static u64 svn_get_varint(const char **pz){ |
| 984 | unsigned int v = 0; |
| 985 | do{ |
| @@ -1130,15 +1084,15 @@ | |
| 1084 | } |
| 1085 | type = 3; |
| 1086 | } |
| 1087 | if( type>0 ){ |
| 1088 | branchId = db_int(0, |
| 1089 | "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d", |
| 1090 | zBranch, type); |
| 1091 | if( branchId==0 ){ |
| 1092 | db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)", |
| 1093 | zBranch, type); |
| 1094 | branchId = db_last_insert_rowid(); |
| 1095 | } |
| 1096 | } |
| 1097 | return branchId; |
| 1098 | } |
| @@ -1152,13 +1106,13 @@ | |
| 1106 | int ver; |
| 1107 | char *zTemp; |
| 1108 | const char *zUuid; |
| 1109 | Stmt addFile; |
| 1110 | Stmt delPath; |
| 1111 | Stmt addRev; |
| 1112 | Stmt cpyPath; |
| 1113 | Stmt revSrc; |
| 1114 | |
| 1115 | /* version */ |
| 1116 | if( svn_read_rec(pIn, &rec) |
| 1117 | && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){ |
| 1118 | ver = atoi(zTemp); |
| @@ -1184,18 +1138,21 @@ | |
| 1138 | "DELETE FROM xfiles" |
| 1139 | " WHERE (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))" |
| 1140 | " AND tbranch=:branch" |
| 1141 | ); |
| 1142 | db_prepare(&addRev, |
| 1143 | "INSERT OR IGNORE INTO xrevisions (trev, tbranch)" |
| 1144 | " VALUES(:rev, :branch)" |
| 1145 | ); |
| 1146 | db_prepare(&cpyPath, |
| 1147 | "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)" |
| 1148 | " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm" |
| 1149 | " FROM xfoci" |
| 1150 | " WHERE checkinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'" |
| 1151 | ); |
| 1152 | db_prepare(&revSrc, |
| 1153 | "UPDATE xrevisions SET tparent=:parent WHERE trev=:rev AND tbranch=:branch" |
| 1154 | ); |
| 1155 | gsvn.rev = -1; |
| 1156 | while( svn_read_rec(pIn, &rec) ){ |
| 1157 | if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */ |
| 1158 | /* finish previous revision */ |
| @@ -1210,13 +1167,14 @@ | |
| 1167 | gsvn.rev = atoi(zTemp); |
| 1168 | gsvn.zUser = mprintf("%s", svn_find_prop(rec, "svn:author")); |
| 1169 | gsvn.zComment = mprintf("%s", svn_find_prop(rec, "svn:log")); |
| 1170 | zDate = svn_find_prop(rec, "svn:date"); |
| 1171 | if( zDate ){ |
| 1172 | gsvn.zDate = date_in_standard_format(zDate); |
| 1173 | }else{ |
| 1174 | gsvn.zDate = date_in_standard_format("now"); |
| 1175 | } |
| 1176 | db_bind_int(&addRev, ":rev", gsvn.rev); |
| 1177 | fossil_print("\rImporting SVN revision: %d", gsvn.rev); |
| 1178 | }else |
| 1179 | if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */ |
| 1180 | char *zAction = svn_find_header(rec, "Node-action"); |
| @@ -1250,37 +1208,50 @@ | |
| 1208 | } |
| 1209 | if( strncmp(zAction, "delete", 6)==0 |
| 1210 | || strncmp(zAction, "replace", 7)==0 ) |
| 1211 | { |
| 1212 | db_bind_text(&delPath, ":path", zFile); |
| 1213 | db_bind_int(&delPath, ":branch", branchId); |
| 1214 | db_step(&delPath); |
| 1215 | db_reset(&delPath); |
| 1216 | db_bind_int(&addRev, ":branch", branchId); |
| 1217 | db_step(&addRev); |
| 1218 | db_reset(&addRev); |
| 1219 | } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */ |
| 1220 | if( strncmp(zAction, "add", 3)==0 |
| 1221 | || strncmp(zAction, "replace", 7)==0 ) |
| 1222 | { |
| 1223 | if( zKind==0 ){ |
| 1224 | fossil_fatal("Missing Node-kind"); |
| 1225 | }else if( strncmp(zKind, "dir", 3)==0 ){ |
| 1226 | if( zSrcPath ){ |
| 1227 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1228 | " WHERE trev<=%d AND tbranch=%d", |
| 1229 | srcRev, srcBranch); |
| 1230 | db_bind_text(&cpyPath, ":path", zFile); |
| 1231 | db_bind_int(&cpyPath, ":branch", branchId); |
| 1232 | db_bind_text(&cpyPath, ":srcpath", zSrcFile); |
| 1233 | db_bind_int(&cpyPath, ":rid", srcRid); |
| 1234 | db_step(&cpyPath); |
| 1235 | db_reset(&cpyPath); |
| 1236 | db_bind_int(&addRev, ":branch", branchId); |
| 1237 | db_step(&addRev); |
| 1238 | db_reset(&addRev); |
| 1239 | if( zFile==0 ){ |
| 1240 | db_bind_int(&revSrc, ":parent", srcRid); |
| 1241 | db_bind_int(&revSrc, ":rev", srcRev); |
| 1242 | db_bind_int(&revSrc, ":branch", branchId); |
| 1243 | db_step(&revSrc); |
| 1244 | db_reset(&revSrc); |
| 1245 | } |
| 1246 | } |
| 1247 | }else{ |
| 1248 | int rid = 0; |
| 1249 | if( zSrcPath ){ |
| 1250 | int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1251 | " WHERE trev<=%d AND tbranch=%d", |
| 1252 | srcRev, srcBranch); |
| 1253 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1254 | " SELECT uuid FROM xfoci" |
| 1255 | " WHERE chekinID=%d AND filename=%Q" |
| 1256 | ")", |
| 1257 | srcRid, zSrcFile); |
| @@ -1297,15 +1268,18 @@ | |
| 1268 | rid = content_put(&target); |
| 1269 | }else if( rec.contentFlag ){ |
| 1270 | rid = content_put(&rec.content); |
| 1271 | } |
| 1272 | db_bind_text(&addFile, ":path", zFile); |
| 1273 | db_bind_int(&addFile, ":branch", branchId); |
| 1274 | db_bind_int(&addFile, ":rid", rid); |
| 1275 | db_bind_text(&addFile, ":perm", zPerm); |
| 1276 | db_step(&addFile); |
| 1277 | db_reset(&addFile); |
| 1278 | db_bind_int(&addRev, ":branch", branchId); |
| 1279 | db_step(&addRev); |
| 1280 | db_reset(&addRev); |
| 1281 | } |
| 1282 | }else |
| 1283 | if( strncmp(zAction, "change", 6)==0 ){ |
| 1284 | int rid = 0; |
| 1285 | if( zKind==0 ){ |
| @@ -1315,24 +1289,27 @@ | |
| 1289 | if( deltaFlag ){ |
| 1290 | Blob deltaSrc; |
| 1291 | Blob target; |
| 1292 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=(" |
| 1293 | " SELECT uuid FROM xfiles" |
| 1294 | " WHERE tpath=%Q AND tbranch=%d" |
| 1295 | ")", zFile, branchId); |
| 1296 | content_get(rid, &deltaSrc); |
| 1297 | svn_apply_svndiff(&rec.content, &deltaSrc, &target); |
| 1298 | rid = content_put(&target); |
| 1299 | }else{ |
| 1300 | rid = content_put(&rec.content); |
| 1301 | } |
| 1302 | db_bind_text(&addFile, ":path", zFile); |
| 1303 | db_bind_int(&addFile, ":branch", branchId); |
| 1304 | db_bind_int(&addFile, ":rid", rid); |
| 1305 | db_bind_text(&addFile, ":perm", zPerm); |
| 1306 | db_step(&addFile); |
| 1307 | db_reset(&addFile); |
| 1308 | db_bind_int(&addRev, ":branch", branchId); |
| 1309 | db_step(&addRev); |
| 1310 | db_reset(&addRev); |
| 1311 | } |
| 1312 | }else |
| 1313 | if( strncmp(zAction, "delete", 6)!=0 ){ /* already did this one above */ |
| 1314 | fossil_fatal("Unknown Node-action"); |
| 1315 | } |
| @@ -1345,13 +1322,13 @@ | |
| 1322 | fossil_free(gsvn.zUser); |
| 1323 | fossil_free(gsvn.zComment); |
| 1324 | fossil_free(gsvn.zDate); |
| 1325 | db_finalize(&addFile); |
| 1326 | db_finalize(&delPath); |
| 1327 | db_finalize(&addRev); |
| 1328 | db_finalize(&cpyPath); |
| 1329 | db_finalize(&revSrc); |
| 1330 | fossil_print(" Done!\n"); |
| 1331 | } |
| 1332 | |
| 1333 | /* |
| 1334 | ** COMMAND: import |
| @@ -1460,16 +1437,16 @@ | |
| 1437 | "CREATE TEMP TABLE xrevisions(" |
| 1438 | " trev INTEGER, tbranch INT, trid INT, tparent INT," |
| 1439 | " UNIQUE(tbranch, trev), UNIQUE(trid)" |
| 1440 | ");" |
| 1441 | "CREATE TEMP TABLE xfiles(" |
| 1442 | " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT," |
| 1443 | " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE" |
| 1444 | ");" |
| 1445 | "CREATE TEMP TABLE xbranches(" |
| 1446 | " tid INTEGER PRIMARY KEY, tname TEXT, ttype INT," |
| 1447 | " UNIQUE(tname, ttype)" |
| 1448 | ");" |
| 1449 | "CREATE VIRTUAL TABLE temp.xfoci USING files_of_checkin;" |
| 1450 | ); |
| 1451 | if( zBase==0 ){ zBase = ""; } |
| 1452 | if( strlen(zBase)>0 ){ |
| 1453 |