Fossil

Check-in [855f233b]
Login

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

Overview
Comment:Fixes for detecting branch creation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:855f233b69884126f4580c159f82f7ccec926f82
User & Date: baruch 2015-01-07 14:07:33
Original Comment: Fixes for detecting branch cration
Context
2015-01-07
19:46
Merge latest trunk check-in: aea273f7 user: baruch tags: svn-import
14:07
Fixes for detecting branch creation check-in: 855f233b user: baruch tags: svn-import
2015-01-06
20:17
Fix a typo and tagging issue check-in: 2b6fc1dd user: baruch tags: svn-import
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/import.c.

726
727
728
729
730
731
732

733
734
735
736
737
738
739
...
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
...
933
934
935
936
937
938
939
940
941
942
943
944
945
946


947
948
949
950
951
952
953
954


955
956
957
958
959
960
961





962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
....
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157

1158
1159
1160
1161
1162
1163
1164
1165
1166

1167
1168
1169
1170
1171
1172
1173
....
1204
1205
1206
1207
1208
1209
1210



1211
1212
1213
1214
1215
1216
1217
....
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
....
1253
1254
1255
1256
1257
1258
1259





1260
1261
1262
1263
1264
1265
1266
....
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
  char *zComment;             /* Comment of a commit */
  const char *zTrunk;         /* Name of trunk folder in repo root */
  int lenTrunk;               /* String length of zTrunk */
  const char *zBranches;      /* Name of branches folder in repo root */
  int lenBranches;            /* String length of zBranches */
  const char *zTags;          /* Name of tags folder in repo root */
  int lenTags;                /* String length of zTags */

} gsvn;
typedef struct {
  char *zKey;
  char *zVal;
} KeyVal;
typedef struct {
  KeyVal *aHeaders;
................................................................................
  db_prepare(&setRid, "UPDATE xrevisions SET trid=:rid"
                             " WHERE trev=%d AND tbranch=:branch", gsvn.rev);
  while( db_step(&getChanges)==SQLITE_ROW ){
    int branchId = db_column_int(&getChanges, 0);
    const char *zBranch = db_column_text(&getChanges, 1);
    int branchType = db_column_int(&getChanges, 2);
    int parentRid = db_column_int(&getChanges, 3);
    int onBranch = 0;
    int rid;
    if( branchType!=3 ){
      if( gsvn.zComment ){
        blob_appendf(&manifest, "C %F\n", gsvn.zComment);
      }else{
        blob_append(&manifest, "C (no\\scomment)\n", 16);
      }
................................................................................
      while( db_step(&getFiles)==SQLITE_ROW ){
        const char *zFile = db_column_text(&getFiles, 0);
        const char *zUuid = db_column_text(&getFiles, 1);
        const char *zPerm = db_column_text(&getFiles, 2);
        blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm);
      }
      db_reset(&getFiles);
      if( parentRid==0 ){
        parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                              " WHERE trev<%d AND tbranch=%d", gsvn.rev, branchId);
        onBranch = 1;
      }
      if( parentRid>0 ){
        const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid);


        blob_appendf(&manifest, "P %s\n", zParentUuid);
        if( onBranch==0 ){
          blob_appendf(&manifest, "T *branch * %F\n", zBranch);
          blob_appendf(&manifest, "T *sym-%F *\n", zBranch);
        }
        blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
        if( onBranch==0 ){
          const char *zParentBranch = db_text(0, "SELECT tbranch FROM xbranches WHERE tid=(SELECT tbranch FROM xrevisions WHERE trid=%d)", parentRid);


          blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);
        }
      }else{
        blob_appendf(&manifest, "T *branch * %F\n", zBranch);
        blob_appendf(&manifest, "T *sym-%F *\n", zBranch);
        blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
      }





      if( gsvn.zUser ){
        blob_appendf(&manifest, "U %F\n", gsvn.zUser);
      }else{
        const char *zUserOvrd = find_option("user-override",0,1);
        blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
      }
      md5sum_blob(&manifest, &mcksum);
      blob_appendf(&manifest, "Z %b\n", &mcksum);
      blob_reset(&mcksum);
    }else{
//      TODO tag
    }
    rid = content_put(&manifest);
    db_bind_int(&setRid, ":branch", branchId);
    db_bind_int(&setRid, ":rid", rid);
    db_step(&setRid);
    db_reset(&setRid);
    blob_reset(&manifest);
  }
................................................................................
      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;
  }
................................................................................
  );
  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)"
    " VALUES(:rev, :branch)"
  );
  db_prepare(&cpyPath,
    "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
    " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
    " FROM xfoci"
    " WHERE checkinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'"
  );
  db_prepare(&revSrc,
    "UPDATE xrevisions SET tparent=:parent WHERE trev=:rev AND tbranch=:branch"
  );
  gsvn.rev = -1;

  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      char *zDate = NULL;
      if( gsvn.rev>=0 ){
        svn_finish_revision();
        fossil_free(gsvn.zUser);
        fossil_free(gsvn.zComment);
        fossil_free(gsvn.zDate);

      }
      /* start new revision */
      gsvn.rev = atoi(zTemp);
      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 ){
................................................................................
          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_int(&delPath, ":branch", branchId);
        db_step(&delPath);
        db_reset(&delPath);
................................................................................
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                                   " WHERE trev<=%d AND tbranch=%d",
                                srcRev, srcBranch);

            db_bind_text(&cpyPath, ":path", zFile);
            db_bind_int(&cpyPath, ":branch", branchId);
            db_bind_text(&cpyPath, ":srcpath", zSrcFile);
            db_bind_int(&cpyPath, ":rid", srcRid);
            db_step(&cpyPath);
            db_reset(&cpyPath);
            db_bind_int(&addRev, ":branch", branchId);
            db_step(&addRev);
            db_reset(&addRev);
            if( zFile==0 ){
              db_bind_int(&revSrc, ":parent", srcRid);
              db_bind_int(&revSrc, ":rev", srcRev);
              db_bind_int(&revSrc, ":branch", branchId);
              db_step(&revSrc);
              db_reset(&revSrc);
            }
          }
        }else{
          int rid = 0;
................................................................................
                            " WHERE trev<=%d AND tbranch=%d",
                         srcRev, srcBranch);
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfoci"
                            "  WHERE checkinID=%d AND filename=%Q"
                            ")",
                         srcRid, zSrcFile);





          }
          if( deltaFlag ){
            Blob deltaSrc;
            Blob target;
            if( rid!=0 ){
              content_get(rid, &deltaSrc);
            }else{
................................................................................
      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,"
       " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xbranches("







>







 







|







 







|


<



>
>
|
<


<
|
|
|
>
>
|






>
>
>
>
>
|
|
|
|
|
|
|
|
|
<
<
<







 







|










|







 







|
<








|


>









>







 







>
>
>







 







>
|
|
|
|
|
|
|
|
|
<

|







 







>
>
>
>
>







 







|







726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
...
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
...
934
935
936
937
938
939
940
941
942
943

944
945
946
947
948
949

950
951

952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977



978
979
980
981
982
983
984
....
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
....
1142
1143
1144
1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
....
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
....
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
....
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
....
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
  char *zComment;             /* Comment of a commit */
  const char *zTrunk;         /* Name of trunk folder in repo root */
  int lenTrunk;               /* String length of zTrunk */
  const char *zBranches;      /* Name of branches folder in repo root */
  int lenBranches;            /* String length of zBranches */
  const char *zTags;          /* Name of tags folder in repo root */
  int lenTags;                /* String length of zTags */
  Bag newBranches;            /* Branches that were created in this revision */
} gsvn;
typedef struct {
  char *zKey;
  char *zVal;
} KeyVal;
typedef struct {
  KeyVal *aHeaders;
................................................................................
  db_prepare(&setRid, "UPDATE xrevisions SET trid=:rid"
                             " WHERE trev=%d AND tbranch=:branch", gsvn.rev);
  while( db_step(&getChanges)==SQLITE_ROW ){
    int branchId = db_column_int(&getChanges, 0);
    const char *zBranch = db_column_text(&getChanges, 1);
    int branchType = db_column_int(&getChanges, 2);
    int parentRid = db_column_int(&getChanges, 3);
    int mergeRid = parentRid;
    int rid;
    if( branchType!=3 ){
      if( gsvn.zComment ){
        blob_appendf(&manifest, "C %F\n", gsvn.zComment);
      }else{
        blob_append(&manifest, "C (no\\scomment)\n", 16);
      }
................................................................................
      while( db_step(&getFiles)==SQLITE_ROW ){
        const char *zFile = db_column_text(&getFiles, 0);
        const char *zUuid = db_column_text(&getFiles, 1);
        const char *zPerm = db_column_text(&getFiles, 2);
        blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm);
      }
      db_reset(&getFiles);
      if( !bag_find(&gsvn.newBranches, branchId) ){
        parentRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                              " WHERE trev<%d AND tbranch=%d", gsvn.rev, branchId);

      }
      if( parentRid>0 ){
        const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid);
        if( parentRid==mergeRid || mergeRid==0){
          const char *zParentBranch = db_text(0, "SELECT tname FROM xbranches WHERE tid=(SELECT tbranch FROM xrevisions WHERE trid=%d)", parentRid);
          blob_appendf(&manifest, "P %s\n", zParentUuid);

          blob_appendf(&manifest, "T *branch * %F\n", zBranch);
          blob_appendf(&manifest, "T *sym-%F *\n", zBranch);

          blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
          blob_appendf(&manifest, "T -sym-%F *\n", zParentBranch);
        }else{
          const char *zMergeUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mergeRid);
          blob_appendf(&manifest, "P %s %s\n", zParentUuid, zMergeUuid);
          blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
        }
      }else{
        blob_appendf(&manifest, "T *branch * %F\n", zBranch);
        blob_appendf(&manifest, "T *sym-%F *\n", zBranch);
        blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", gsvn.rev);
      }
    }else{
      const char *zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", parentRid);
      blob_appendf(&manifest, "D %s\n", gsvn.zDate);
      blob_appendf(&manifest, "T +sym-%F %s\n", zBranch, zParentUuid);
    }
    if( gsvn.zUser ){
      blob_appendf(&manifest, "U %F\n", gsvn.zUser);
    }else{
      const char *zUserOvrd = find_option("user-override",0,1);
      blob_appendf(&manifest, "U %F\n", zUserOvrd ? zUserOvrd : login_name());
    }
    md5sum_blob(&manifest, &mcksum);
    blob_appendf(&manifest, "Z %b\n", &mcksum);
    blob_reset(&mcksum);



    rid = content_put(&manifest);
    db_bind_int(&setRid, ":branch", branchId);
    db_bind_int(&setRid, ":rid", rid);
    db_step(&setRid);
    db_reset(&setRid);
    blob_reset(&manifest);
  }
................................................................................
      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;
  }
................................................................................
  );
  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) VALUES(:rev, :branch)"

  );
  db_prepare(&cpyPath,
    "INSERT INTO xfiles (tpath, tbranch, tuuid, tperm)"
    " SELECT :path||substr(filename, length(:srcpath)+1), :branch, uuid, perm"
    " FROM xfoci"
    " WHERE checkinID=:rid AND filename>:srcpath||'/' AND filename<:srcpath||'0'"
  );
  db_prepare(&revSrc,
    "UPDATE xrevisions SET tparent=:parent WHERE trev=:rev AND tbranch=:branch AND tparent<:parent"
  );
  gsvn.rev = -1;
  bag_init(&gsvn.newBranches);
  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      char *zDate = NULL;
      if( gsvn.rev>=0 ){
        svn_finish_revision();
        fossil_free(gsvn.zUser);
        fossil_free(gsvn.zComment);
        fossil_free(gsvn.zDate);
        bag_clear(&gsvn.newBranches);
      }
      /* start new revision */
      gsvn.rev = atoi(zTemp);
      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 ){
................................................................................
          fossil_fatal("Missing copyfrom-rev");
        }
        srcBranch = svn_parse_path(zSrcPath, &zSrcFile);
        if( srcBranch==0 ){
          fossil_fatal("Copy from path outside the import paths");
        }
      }
      if( zFile==0 ){
        bag_insert(&gsvn.newBranches, branchId);
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        db_bind_text(&delPath, ":path", zFile);
        db_bind_int(&delPath, ":branch", branchId);
        db_step(&delPath);
        db_reset(&delPath);
................................................................................
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
          if( zSrcPath ){
            int srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
                                   " WHERE trev<=%d AND tbranch=%d",
                                srcRev, srcBranch);
            if( srcRid>0 ){
              db_bind_text(&cpyPath, ":path", zFile);
              db_bind_int(&cpyPath, ":branch", branchId);
              db_bind_text(&cpyPath, ":srcpath", zSrcFile);
              db_bind_int(&cpyPath, ":rid", srcRid);
              db_step(&cpyPath);
              db_reset(&cpyPath);
              db_bind_int(&addRev, ":branch", branchId);
              db_step(&addRev);
              db_reset(&addRev);

              db_bind_int(&revSrc, ":parent", srcRid);
              db_bind_int(&revSrc, ":rev", gsvn.rev);
              db_bind_int(&revSrc, ":branch", branchId);
              db_step(&revSrc);
              db_reset(&revSrc);
            }
          }
        }else{
          int rid = 0;
................................................................................
                            " WHERE trev<=%d AND tbranch=%d",
                         srcRev, srcBranch);
            rid = db_int(0, "SELECT rid FROM blob WHERE uuid=("
                            " SELECT uuid FROM xfoci"
                            "  WHERE checkinID=%d AND filename=%Q"
                            ")",
                         srcRid, zSrcFile);
            db_bind_int(&revSrc, ":parent", srcRid);
            db_bind_int(&revSrc, ":rev", gsvn.rev);
            db_bind_int(&revSrc, ":branch", branchId);
            db_step(&revSrc);
            db_reset(&revSrc);
          }
          if( deltaFlag ){
            Blob deltaSrc;
            Blob target;
            if( rid!=0 ){
              content_get(rid, &deltaSrc);
            }else{
................................................................................
      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 DEFAULT 0,"
       " UNIQUE(tbranch, trev), UNIQUE(trid)"
       ");"
       "CREATE TEMP TABLE xfiles("
       " tpath TEXT, tbranch INT, tuuid TEXT, tperm TEXT,"
       " UNIQUE (tbranch, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xbranches("