Fossil with Commonmark

Check-in [997da4f0e4]
Login

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

Overview
Comment:Allow using tags as copy-source Move variables to smaller scope, as per coding style guidelines
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:997da4f0e45fb25098d35aab1868c8643d8a49a1
User & Date: baruch 2015-01-11 11:30:46
Context
2015-01-11
12:44
Change "magic numbers" to named constants check-in: c8e00eb1f5 user: baruch tags: svn-import
11:30
Allow using tags as copy-source Move variables to smaller scope, as per coding style guidelines check-in: 997da4f0e4 user: baruch tags: svn-import
08:02
Fix issue with branching from a branch check-in: 93134dda26 user: baruch tags: svn-import
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/import.c.

   950    950         db_reset(&getFiles);
   951    951         if( !bag_find(&gsvn.newBranches, branchId) ){
   952    952           parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
   953    953                                 " WHERE trev<%d AND tbranch=%d",
   954    954                              gsvn.rev, branchId);
   955    955         }
   956    956         if( parentRid>0 ){
   957         -        const char *zParentUuid = rid_to_uuid(parentRid);
          957  +        char *zParentUuid = rid_to_uuid(parentRid);
   958    958           if( parentRid==mergeRid || mergeRid==0){
   959         -          const char *zParentBranch =
          959  +          char *zParentBranch =
   960    960               db_text(0, "SELECT tname FROM xbranches WHERE tid="
   961    961                          " (SELECT tbranch FROM xrevisions WHERE trid=%d)",
   962    962                       parentRid
   963    963               );
   964    964             blob_appendf(&manifest, "P %s\n", zParentUuid);
   965    965             blob_appendf(&manifest, "T *branch * %F\n", zBranch);
   966    966             blob_appendf(&manifest, "T *sym-%F *\n", zBranch);
   967    967             blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
   968    968             blob_appendf(&manifest, "T -sym-%F *\n", zParentBranch);
   969    969             fossil_free(zParentBranch);
   970    970           }else{
   971         -          const char *zMergeUuid = rid_to_uuid(mergeRid);
          971  +          char *zMergeUuid = rid_to_uuid(mergeRid);
   972    972             blob_appendf(&manifest, "P %s %s\n", zParentUuid, zMergeUuid);
   973    973             blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
          974  +          fossil_free(zMergeUuid);
   974    975           }
   975    976           fossil_free(zParentUuid);
   976    977         }else{
   977    978           blob_appendf(&manifest, "T *branch * %F\n", zBranch);
   978    979           blob_appendf(&manifest, "T *sym-%F *\n", zBranch);
   979    980           blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
   980    981         }
   981    982       }else{
   982         -      const char *zParentUuid = rid_to_uuid(parentRid);
          983  +      char *zParentUuid = rid_to_uuid(parentRid);
   983    984         blob_appendf(&manifest, "D %s\n", gsvn.zDate);
   984    985         blob_appendf(&manifest, "T +sym-%F %s\n", zBranch, zParentUuid);
   985    986         fossil_free(zParentUuid);
   986    987       }
   987    988       if( gsvn.zUser ){
   988    989         blob_appendf(&manifest, "U %F\n", gsvn.zUser);
   989    990       }else{
................................................................................
  1054   1055         }
  1055   1056       }
  1056   1057       zDiff += lenData;
  1057   1058     }
  1058   1059   }
  1059   1060   
  1060   1061   /*
  1061         -** Extract the name of the branch or tag that the given path is on.
  1062         -** Returns: 1 - It is on the trunk
  1063         -**          2 - It is on a branch
  1064         -**          3 - It is a tag
  1065         -**          0 - It is none of the above
         1062  +** Extract the branch or tag that the given path is on. Return the branch ID.
  1066   1063    */
  1067         -static int svn_parse_path(char *zPath, char **zFile){
  1068         -  int type = 0;
         1064  +static int svn_parse_path(char *zPath, char **zFile, int *type){
  1069   1065     char *zBranch = 0;
  1070   1066     int branchId = 0;
         1067  +  *type = 0;
  1071   1068     *zFile = 0;
  1072   1069     if( gsvn.lenTrunk==0 ){
  1073   1070       zBranch = "trunk";
  1074   1071       *zFile = zPath;
  1075         -    type = 1;
         1072  +    *type = 1;
  1076   1073     }else
  1077   1074     if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
  1078   1075       if( zPath[gsvn.lenTrunk-1]=='/' || zPath[gsvn.lenTrunk-1]==0 ){
  1079   1076         zBranch = "trunk";
  1080   1077         *zFile = zPath+gsvn.lenTrunk;
  1081         -      type = 1;
         1078  +      *type = 1;
  1082   1079       }else{
  1083   1080         zBranch = 0;
  1084         -      type = 0;
         1081  +      *type = 0;
  1085   1082       }
  1086         -  }else
  1087         -  if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
  1088         -    *zFile = zBranch = zPath+gsvn.lenBranches;
         1083  +  }else{
         1084  +    if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
         1085  +      *zFile = zBranch = zPath+gsvn.lenBranches;
         1086  +      *type = 2;
         1087  +    }else
         1088  +    if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
         1089  +      *zFile = zBranch = zPath+gsvn.lenTags;
         1090  +      *type = 3;
         1091  +    }else{ /* Not a branch, tag or trunk */
         1092  +      return 0;
         1093  +    }
  1089   1094       while( **zFile && **zFile!='/' ){ (*zFile)++; }
  1090   1095       if( **zFile ){
  1091   1096         **zFile = '\0';
  1092   1097         (*zFile)++;
  1093   1098       }
  1094         -    type = 2;
  1095         -  }else
  1096         -  if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
  1097         -    *zFile = zBranch = zPath+gsvn.lenTags;
  1098         -    while( **zFile && **zFile!='/' ){ (*zFile)++; }
  1099         -    if( **zFile ){
  1100         -      **zFile = '\0';
  1101         -      (*zFile)++;
  1102         -    }
  1103         -    type = 3;
  1104   1099     }
  1105         -  if( type>0 ){
         1100  +  if( *type>0 ){
  1106   1101       branchId = db_int(0,
  1107   1102                         "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d",
  1108         -                      zBranch, type);
         1103  +                      zBranch, *type);
  1109   1104       if( branchId==0 ){
  1110   1105         db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)",
  1111         -                    zBranch, type);
         1106  +                    zBranch, *type);
  1112   1107         branchId = db_last_insert_rowid();
  1113   1108       }
  1114   1109     }
  1115   1110     return branchId;
  1116   1111   }
  1117   1112   
  1118   1113   /*
................................................................................
  1140   1135       }
  1141   1136     }else{
  1142   1137       fossil_fatal("Input is not an svn-dump!");
  1143   1138     }
  1144   1139     svn_free_rec(&rec);
  1145   1140     /* UUID */
  1146   1141     if( !svn_read_rec(pIn, &rec) || !(zUuid = svn_find_header(rec, "UUID")) ){
  1147         -    fossil_fatal("Missing UUID!");
         1142  +    /* Removed the following line since UUID is not actually used
         1143  +     fossil_fatal("Missing UUID!"); */
  1148   1144     }
  1149   1145     svn_free_rec(&rec);
  1150   1146   
  1151   1147     /* content */
  1152   1148     db_prepare(&addFile,
  1153   1149       "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
  1154   1150       " VALUES(:path, :branch, (SELECT uuid FROM blob WHERE rid=:rid), :perm)"
................................................................................
  1202   1198         }else{
  1203   1199           gsvn.zDate = date_in_standard_format("now");
  1204   1200         }
  1205   1201         db_bind_int(&addRev, ":rev", gsvn.rev);
  1206   1202         fossil_print("\rImporting SVN revision: %d", gsvn.rev);
  1207   1203       }else
  1208   1204       if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
         1205  +      char *zFile;
         1206  +      int branchType;
         1207  +      int branchId = svn_parse_path(zTemp, &zFile, &branchType);
  1209   1208         char *zAction = svn_find_header(rec, "Node-action");
  1210   1209         char *zKind = svn_find_header(rec, "Node-kind");
  1211         -      char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
  1212   1210         char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
  1213         -      char *zFile;
  1214         -      int srcBranch;
  1215         -      char *zSrcFile;
  1216   1211         int deltaFlag = 0;
  1217   1212         int srcRev = 0;
  1218         -      int branchId = svn_parse_path(zTemp, &zFile);
  1219   1213         if( branchId==0 ){
  1220   1214           svn_free_rec(&rec);
  1221   1215           continue;
  1222   1216         }
  1223   1217         if( (zTemp = svn_find_header(rec, "Text-delta")) ){
  1224   1218           deltaFlag = strncmp(zTemp, "true", 4)==0;
  1225   1219         }
  1226         -      if( zSrcPath ){
  1227         -        zTemp = svn_find_header(rec, "Node-copyfrom-rev");
  1228         -        if( zTemp ){
  1229         -          srcRev = atoi(zTemp);
  1230         -        }else{
  1231         -          fossil_fatal("Missing copyfrom-rev");
  1232         -        }
  1233         -        srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
  1234         -        if( srcBranch==0 ){
  1235         -          fossil_fatal("Copy from path outside the import paths");
  1236         -        }
  1237         -      }
  1238   1220         if( zFile[0]==0 ){
  1239   1221           bag_insert(&gsvn.newBranches, branchId);
  1240   1222         }
  1241   1223         if( strncmp(zAction, "delete", 6)==0
  1242   1224          || strncmp(zAction, "replace", 7)==0 )
  1243   1225         {
  1244   1226           //TODO delete root
................................................................................
  1249   1231           db_bind_int(&addRev, ":branch", branchId);
  1250   1232           db_step(&addRev);
  1251   1233           db_reset(&addRev);
  1252   1234         } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
  1253   1235         if( strncmp(zAction, "add", 3)==0
  1254   1236          || strncmp(zAction, "replace", 7)==0 )
  1255   1237         {
         1238  +        char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
         1239  +        char *zSrcFile;
  1256   1240           int srcRid = 0;
         1241  +        if( zSrcPath ){
         1242  +          int srcBranch;
         1243  +          zTemp = svn_find_header(rec, "Node-copyfrom-rev");
         1244  +          if( zTemp ){
         1245  +            srcRev = atoi(zTemp);
         1246  +          }else{
         1247  +            fossil_fatal("Missing copyfrom-rev");
         1248  +          }
         1249  +          srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType);
         1250  +          if( srcBranch==0 ){
         1251  +            fossil_fatal("Copy from path outside the import paths");
         1252  +          }
         1253  +          if( branchType!=3 ){
         1254  +            srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
         1255  +                               " WHERE trev<=%d AND tbranch=%d",
         1256  +                            srcRev, srcBranch);
         1257  +          }else{
         1258  +            srcRid = db_int(0, "SELECT tparent, max(trev) FROM xrevisions"
         1259  +                               " WHERE trev<=%d AND tbranch=%d",
         1260  +                            srcRev, srcBranch);
         1261  +          }
         1262  +          if( srcRid>0 && srcBranch!=branchId ){
         1263  +            db_bind_int(&addRev, ":branch", branchId);
         1264  +            db_step(&addRev);
         1265  +            db_reset(&addRev);
         1266  +            db_bind_int(&revSrc, ":parent", srcRid);
         1267  +            db_bind_int(&revSrc, ":rev", gsvn.rev);
         1268  +            db_bind_int(&revSrc, ":branch", branchId);
         1269  +            db_step(&revSrc);
         1270  +            db_reset(&revSrc);
         1271  +          }
         1272  +        }
  1257   1273           if( zKind==0 ){
  1258   1274             fossil_fatal("Missing Node-kind");
  1259   1275           }else if( strncmp(zKind, "dir", 3)==0 ){
  1260   1276             if( zSrcPath ){
  1261         -            srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
  1262         -                                   " WHERE trev<=%d AND tbranch=%d",
  1263         -                                srcRev, srcBranch);
  1264   1277               if( srcRid>0 ){
  1265   1278                 if( zFile[0]==0 ){
  1266   1279                   db_bind_text(&cpyRoot, ":path", zFile);
  1267   1280                   db_bind_int(&cpyRoot, ":branch", branchId);
  1268   1281                   db_bind_int(&cpyRoot, ":rid", srcRid);
  1269   1282                   db_step(&cpyRoot);
  1270   1283                   db_reset(&cpyRoot);
................................................................................
  1280   1293                 db_step(&addRev);
  1281   1294                 db_reset(&addRev);
  1282   1295               }
  1283   1296             }
  1284   1297           }else{
  1285   1298             int rid = 0;
  1286   1299             if( zSrcPath ){
  1287         -            srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
  1288         -                            " WHERE trev<=%d AND tbranch=%d",
  1289         -                         srcRev, srcBranch);
  1290   1300               rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
  1291   1301                               " SELECT uuid FROM xfoci"
  1292   1302                               "  WHERE checkinID=%d AND filename=%Q"
  1293   1303                               ")",
  1294   1304                            srcRid, zSrcFile);
  1295   1305             }
  1296   1306             if( deltaFlag ){
................................................................................
  1312   1322             db_bind_text(&addFile, ":perm", zPerm);
  1313   1323             db_step(&addFile);
  1314   1324             db_reset(&addFile);
  1315   1325             db_bind_int(&addRev, ":branch", branchId);
  1316   1326             db_step(&addRev);
  1317   1327             db_reset(&addRev);
  1318   1328           }
  1319         -        if( zSrcPath && srcRid>0 && srcBranch!=branchId ){
  1320         -          db_bind_int(&revSrc, ":parent", srcRid);
  1321         -          db_bind_int(&revSrc, ":rev", gsvn.rev);
  1322         -          db_bind_int(&revSrc, ":branch", branchId);
  1323         -          db_step(&revSrc);
  1324         -          db_reset(&revSrc);
  1325         -        }
  1326   1329         }else
  1327   1330         if( strncmp(zAction, "change", 6)==0 ){
  1328   1331           int rid = 0;
  1329   1332           if( zKind==0 ){
  1330   1333             fossil_fatal("Missing Node-kind");
  1331   1334           }
  1332   1335           if( strncmp(zKind, "dir", 3)!=0 ){