Fossil

Check-in [2889cdc3]
Login

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

Overview
Comment:add support for tags
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:2889cdc36df4a4a29b7174d7980ad3bb434f3ae7
User & Date: baruch 2014-10-27 08:19:20
Context
2014-10-28
10:44
Support version 3 format (diff dumps) check-in: eb0bf087 user: baruch tags: svn-import
2014-10-27
08:19
add support for tags check-in: 2889cdc3 user: baruch tags: svn-import
08:18
revert changes committed by mistake to makefile check-in: 279f4cf9 user: baruch tags: svn-import
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/import.c.

880
881
882
883
884
885
886

887
888
889
890
891





892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935

936
937
938
939
940
941
942
...
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
...
982
983
984
985
986
987
988

989
990
991
992
993
994
995
...
996
997
998
999
1000
1001
1002

1003
1004
1005
1006
1007
1008
1009
....
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
....
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132







1133
1134
1135
1136
1137
1138
1139
....
1172
1173
1174
1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
....
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284



1285
1286
1287
1288
1289
1290
1291
}

static void svn_create_manifests(int flatFlag){
  Blob manifest;
  Stmt qRev;
  Stmt qParent;
  Stmt qFiles;

  Stmt setUuid;

  if( !flatFlag ){
    db_multi_exec("DELETE FROM xrevisions WHERE tbranch ISNULL;"
                  ""





                  " WITH xprefix AS ( "
                  "  SELECT trev, CASE tbranch WHEN 'trunk' THEN 'trunk/'"
                  "  ELSE 'branches/'||tbranch||'/' END xpref"
                  "  FROM xrevisions"
                  " ), "
                  " x AS (SELECT trev xrev, xpref, length(xpref) xlen "
                  " FROM xprefix) "
                  "UPDATE xfiles SET tpath= "
                  " CASE substr(tpath,1,(SELECT xlen FROM x WHERE xrev=trev))"
                  " WHEN (SELECT xpref FROM x WHERE xrev=trev)"
                  "  THEN substr(tpath,(SELECT xlen FROM x WHERE xrev=trev)+1)"
                  " END;"
                  "DELETE FROM xfiles WHERE tpath ISNULL;"
                  "UPDATE xrevisions SET tparent=("
                  "  SELECT ifnull(max(trev),-1) FROM xrevisions t"
                  "  WHERE t.trev<xrevisions.trev"
                  "    AND t.tbranch=xrevisions.tbranch"
                  " )"
                  " WHERE tparent ISNULL");
  }else{
    db_multi_exec("UPDATE xrevisions SET tparent=trev-1");
  }
  db_prepare(&qRev, "SELECT trev, tuser, tmsg, ttime, tparent, tbranch"
                    " FROM xrevisions "
                    " ORDER BY trev");
  db_prepare(&qParent, "SELECT tuuid, tbranch FROM xrevisions WHERE trev=:rev");
  db_prepare(&qFiles, "SELECT tpath, uuid, tperm"
                      " FROM xfiles JOIN blob ON xfiles.trid=blob.rid"
                      " WHERE trev=:rev ORDER BY tpath");

  db_prepare(&setUuid, "UPDATE xrevisions"
                       " SET tuuid=(SELECT uuid FROM blob WHERE rid=:rid)"
                       " WHERE trev=:rev");
  blob_zero(&manifest);
  while( db_step(&qRev)==SQLITE_ROW ){
    int rev = db_column_int(&qRev, 0);
    const char *zUser = db_column_text(&qRev, 1);
    const char *zMsg = db_column_text(&qRev, 2);
    const char *zTime = db_column_text(&qRev, 3);
    int parentRev = db_column_int(&qRev, 4);
    const char *zBranch = db_column_text(&qRev, 5);
    int rid;
    Blob mcksum;
    const char *zParentUuid = 0;
    const char *zParentBranch = 0;

    blob_reset(&manifest);
    if( zMsg ){
      blob_appendf(&manifest, "C %F\n", zMsg);
    }else{
      blob_append(&manifest, "C (no\\scomment)\n", 16);
    }
    blob_appendf(&manifest, "D %s\n", zTime);
................................................................................
      const char *zFile = db_column_text(&qFiles, 0);
      const char *zUuid = db_column_text(&qFiles, 1);
      const char *zPerm = db_column_text(&qFiles, 2);
      blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm);
    }
    db_reset(&qFiles);
    if( parentRev>=0 ){

      db_bind_int(&qParent, ":rev", parentRev);
      db_step(&qParent);
      zParentUuid = db_column_text(&qParent, 0);
      blob_appendf(&manifest, "P %s\n", zParentUuid);
      if( !flatFlag ){
        zParentBranch = db_column_text(&qParent, 1);
        if( strcmp(zBranch, zParentBranch)!=0 ){
          blob_appendf(&manifest, "T *branch * %s\n", zBranch);
          blob_appendf(&manifest, "T *sym-%s *\n", zBranch);



        }
      }
      db_reset(&qParent);
    }else{
      blob_appendf(&manifest, "T *branch * trunk\n");
      blob_appendf(&manifest, "T *sym-trunk *\n");
    }






    blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", rev);



    if( zUser ){
      blob_appendf(&manifest, "U %F\n", zUser);
    }else{
      const char *zUserOvrd = find_option("user-override",0,1);
      blob_appendf(&manifest, "U %F\n",
        zUserOvrd ? zUserOvrd : login_name());
    }
................................................................................
    db_bind_int(&setUuid, ":rev", rev);
    db_step(&setUuid);
    db_reset(&setUuid);
  }
  db_finalize(&qRev);
  db_finalize(&qParent);
  db_finalize(&qFiles);

  db_finalize(&setUuid);
}
/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn, int flatFlag){
................................................................................
  SvnRecord rec;
  int ver;
  const char *zTemp;
  const char *zUuid;
  char zBranch[200] = {0};
  Stmt insRev;
  Stmt insFile;

  Stmt delFile;
  Stmt setBranch;
  Stmt setParent;
  int rev = 0;

  /* version */
  if( svn_read_rec(pIn, &rec)
................................................................................
      "INSERT INTO xrevisions (trev, tuser, tmsg, ttime) "
      "VALUES(:rev, :user, :msg, :time)"
  );
  db_prepare(&insFile,
      "INSERT INTO xfiles (trev, tpath, trid, tperm) "
      "VALUES(:rev, :path, :rid, :perm)"
  );

  db_prepare(&delFile,
      "DELETE FROM xfiles "
      "WHERE trev=:rev "
      "  AND (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
  );
  db_prepare(&setBranch,
      "UPDATE xrevisions SET tbranch=:branch "
................................................................................
            db_multi_exec(
              "INSERT INTO xfiles (trev, tpath, trid, tperm) "
              " SELECT %d, %Q||substr(tpath, length(%Q)+1), trid, tperm "
              " FROM xfiles "
              " WHERE trev=%d AND tpath GLOB '%q/*'",
              rev, zPath, zSrcPath, srcRev, zSrcPath
            );

            if( !flatFlag && strncmp(zPath, "branches/", 9)==0 ){
              zTemp = zPath+9;
              while( *zTemp && *zTemp!='/' ){ zTemp++; }
              if( *zTemp==0 ){
                db_bind_int(&setParent, ":parent", srcRev);
                db_bind_int(&setParent, ":rev", rev);
                db_step(&setParent);
                db_reset(&setParent);







              }
            }
          }
        }else{
          if( blob_size(&rec.content)==0 && zSrcPath ){
            rid = db_int(0,
                         "SELECT trid FROM xfiles WHERE trev=%d AND tpath=%Q",
................................................................................
      db_bind_text(&setBranch, ":branch", zBranch);
      db_bind_int(&setBranch, ":rev", rev);
      db_step(&setBranch);
    }
  }
  db_finalize(&insRev);
  db_finalize(&insFile);

  db_finalize(&delFile);
  db_finalize(&setBranch);
  db_finalize(&setParent);
  svn_create_manifests(flatFlag);
}

/*
................................................................................
      import_reset(0);
    }
    db_finalize(&q);
  }else
  if( strncmp(g.argv[2], "svn", 3)==0 ){
    db_multi_exec(
       "CREATE TEMP TABLE xrevisions("
       " trev INT, tuser TEXT, tmsg TEXT, ttime DATETIME, tparent INT,"
       " tbranch TEXT, tuuid TEXT"
       ");"
       "CREATE TEMP TABLE xfiles("
       " trev INT, tpath TEXT, trid TEXT, tperm TEXT,"
       " UNIQUE (trev, tpath) ON CONFLICT REPLACE"



       ");"
    );
    svn_dump_import(pIn, flatFlag);
  }

  db_end_transaction(0);
  db_begin_transaction();







>




|
>
>
>
>
>
|






|




|
<
<
<
<
<
<










>












<
<

>







 







>









>
>
>







>
>
>
>
>
>

>
>
>







 







>







 







>







 







>







 







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







 







>







 







|
|




>
>
>







880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910






911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933


934
935
936
937
938
939
940
941
942
...
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
985
986
987
988
...
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
....
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
....
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
....
1134
1135
1136
1137
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
....
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
....
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
}

static void svn_create_manifests(int flatFlag){
  Blob manifest;
  Stmt qRev;
  Stmt qParent;
  Stmt qFiles;
  Stmt qTags;
  Stmt setUuid;

  if( !flatFlag ){
    db_multi_exec("DELETE FROM xrevisions WHERE tbranch ISNULL;"
                  "UPDATE xrevisions SET tparent=("
                  "  SELECT ifnull(max(trev),-1) FROM xrevisions t"
                  "  WHERE t.trev<xrevisions.trev"
                  "    AND t.tbranch=xrevisions.tbranch"
                  " )"
                  " WHERE tparent ISNULL;"
                  "WITH xprefix AS ( "
                  "  SELECT trev, CASE tbranch WHEN 'trunk' THEN 'trunk/'"
                  "  ELSE 'branches/'||tbranch||'/' END xpref"
                  "  FROM xrevisions"
                  " ), "
                  " x AS (SELECT trev xrev, xpref, length(xpref) xlen "
                  " FROM xprefix) "
                  " UPDATE xfiles SET tpath= "
                  " CASE substr(tpath,1,(SELECT xlen FROM x WHERE xrev=trev))"
                  " WHEN (SELECT xpref FROM x WHERE xrev=trev)"
                  "  THEN substr(tpath,(SELECT xlen FROM x WHERE xrev=trev)+1)"
                  " END;"
                  "DELETE FROM xfiles WHERE tpath ISNULL");






  }else{
    db_multi_exec("UPDATE xrevisions SET tparent=trev-1");
  }
  db_prepare(&qRev, "SELECT trev, tuser, tmsg, ttime, tparent, tbranch"
                    " FROM xrevisions "
                    " ORDER BY trev");
  db_prepare(&qParent, "SELECT tuuid, tbranch FROM xrevisions WHERE trev=:rev");
  db_prepare(&qFiles, "SELECT tpath, uuid, tperm"
                      " FROM xfiles JOIN blob ON xfiles.trid=blob.rid"
                      " WHERE trev=:rev ORDER BY tpath");
  db_prepare(&qTags, "SELECT ttag FROM xtags WHERE trev=:rev");
  db_prepare(&setUuid, "UPDATE xrevisions"
                       " SET tuuid=(SELECT uuid FROM blob WHERE rid=:rid)"
                       " WHERE trev=:rev");
  blob_zero(&manifest);
  while( db_step(&qRev)==SQLITE_ROW ){
    int rev = db_column_int(&qRev, 0);
    const char *zUser = db_column_text(&qRev, 1);
    const char *zMsg = db_column_text(&qRev, 2);
    const char *zTime = db_column_text(&qRev, 3);
    int parentRev = db_column_int(&qRev, 4);
    const char *zBranch = db_column_text(&qRev, 5);
    int rid;


    const char *zParentBranch = 0;
    Blob mcksum;
    blob_reset(&manifest);
    if( zMsg ){
      blob_appendf(&manifest, "C %F\n", zMsg);
    }else{
      blob_append(&manifest, "C (no\\scomment)\n", 16);
    }
    blob_appendf(&manifest, "D %s\n", zTime);
................................................................................
      const char *zFile = db_column_text(&qFiles, 0);
      const char *zUuid = db_column_text(&qFiles, 1);
      const char *zPerm = db_column_text(&qFiles, 2);
      blob_appendf(&manifest, "F %F %s %s\n", zFile, zUuid, zPerm);
    }
    db_reset(&qFiles);
    if( parentRev>=0 ){
      const char *zParentUuid;
      db_bind_int(&qParent, ":rev", parentRev);
      db_step(&qParent);
      zParentUuid = db_column_text(&qParent, 0);
      blob_appendf(&manifest, "P %s\n", zParentUuid);
      if( !flatFlag ){
        zParentBranch = db_column_text(&qParent, 1);
        if( strcmp(zBranch, zParentBranch)!=0 ){
          blob_appendf(&manifest, "T *branch * %s\n", zBranch);
          blob_appendf(&manifest, "T *sym-%s *\n", zBranch);
          zParentBranch = mprintf("%s", zParentBranch);
        }else{
          zParentBranch = 0;
        }
      }
      db_reset(&qParent);
    }else{
      blob_appendf(&manifest, "T *branch * trunk\n");
      blob_appendf(&manifest, "T *sym-trunk *\n");
    }
    db_bind_int(&qTags, ":rev", rev);
    while( db_step(&qTags)==SQLITE_ROW ){
      const char *zTag = db_column_text(&qTags, 0);
      blob_appendf(&manifest, "T +sym-%s *\n", zTag);
    }
    db_reset(&qTags);
    blob_appendf(&manifest, "T +sym-svn-rev-%d *\n", rev);
    if( zParentBranch ) {
      blob_appendf(&manifest, "T -sym-%s *\n", zParentBranch);
    }
    if( zUser ){
      blob_appendf(&manifest, "U %F\n", zUser);
    }else{
      const char *zUserOvrd = find_option("user-override",0,1);
      blob_appendf(&manifest, "U %F\n",
        zUserOvrd ? zUserOvrd : login_name());
    }
................................................................................
    db_bind_int(&setUuid, ":rev", rev);
    db_step(&setUuid);
    db_reset(&setUuid);
  }
  db_finalize(&qRev);
  db_finalize(&qParent);
  db_finalize(&qFiles);
  db_finalize(&qTags);
  db_finalize(&setUuid);
}
/*
** Read the svn-dump format from pIn and insert the corresponding
** content into the database.
*/
static void svn_dump_import(FILE *pIn, int flatFlag){
................................................................................
  SvnRecord rec;
  int ver;
  const char *zTemp;
  const char *zUuid;
  char zBranch[200] = {0};
  Stmt insRev;
  Stmt insFile;
  Stmt insTag;
  Stmt delFile;
  Stmt setBranch;
  Stmt setParent;
  int rev = 0;

  /* version */
  if( svn_read_rec(pIn, &rec)
................................................................................
      "INSERT INTO xrevisions (trev, tuser, tmsg, ttime) "
      "VALUES(:rev, :user, :msg, :time)"
  );
  db_prepare(&insFile,
      "INSERT INTO xfiles (trev, tpath, trid, tperm) "
      "VALUES(:rev, :path, :rid, :perm)"
  );
  db_prepare(&insTag, "INSERT INTO xtags (trev, ttag) VALUES(:rev, :tag)");
  db_prepare(&delFile,
      "DELETE FROM xfiles "
      "WHERE trev=:rev "
      "  AND (tpath=:path OR (tpath>:path||'/' AND tpath<:path||'0'))"
  );
  db_prepare(&setBranch,
      "UPDATE xrevisions SET tbranch=:branch "
................................................................................
            db_multi_exec(
              "INSERT INTO xfiles (trev, tpath, trid, tperm) "
              " SELECT %d, %Q||substr(tpath, length(%Q)+1), trid, tperm "
              " FROM xfiles "
              " WHERE trev=%d AND tpath GLOB '%q/*'",
              rev, zPath, zSrcPath, srcRev, zSrcPath
            );
            if( !flatFlag ){
              if( strncmp(zPath, "branches/", 9)==0 ){
                zTemp = zPath+9;
                while( *zTemp && *zTemp!='/' ){ zTemp++; }
                if( *zTemp==0 ){
                  db_bind_int(&setParent, ":parent", srcRev);
                  db_bind_int(&setParent, ":rev", rev);
                  db_step(&setParent);
                  db_reset(&setParent);
                }
              }else if( strncmp(zPath, "tags/", 5)==0 ){
                zTemp = zPath+5;
                db_bind_int(&insTag, ":rev", srcRev);
                db_bind_text(&insTag, ":tag", zTemp);
                db_step(&insTag);
                db_reset(&insTag);
              }
            }
          }
        }else{
          if( blob_size(&rec.content)==0 && zSrcPath ){
            rid = db_int(0,
                         "SELECT trid FROM xfiles WHERE trev=%d AND tpath=%Q",
................................................................................
      db_bind_text(&setBranch, ":branch", zBranch);
      db_bind_int(&setBranch, ":rev", rev);
      db_step(&setBranch);
    }
  }
  db_finalize(&insRev);
  db_finalize(&insFile);
  db_finalize(&insTag);
  db_finalize(&delFile);
  db_finalize(&setBranch);
  db_finalize(&setParent);
  svn_create_manifests(flatFlag);
}

/*
................................................................................
      import_reset(0);
    }
    db_finalize(&q);
  }else
  if( strncmp(g.argv[2], "svn", 3)==0 ){
    db_multi_exec(
       "CREATE TEMP TABLE xrevisions("
       " trev INTEGER PRIMARY KEY, tuser TEXT, tmsg TEXT, ttime DATETIME,"
       " tparent INT, tbranch TEXT, tuuid TEXT"
       ");"
       "CREATE TEMP TABLE xfiles("
       " trev INT, tpath TEXT, trid TEXT, tperm TEXT,"
       " UNIQUE (trev, tpath) ON CONFLICT REPLACE"
       ");"
       "CREATE TEMP TABLE xtags("
       " trev INT, ttag TEXT"
       ");"
    );
    svn_dump_import(pIn, flatFlag);
  }

  db_end_transaction(0);
  db_begin_transaction();