Fossil

Check-in [05537c6f]
Login

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

Overview
Comment:Fix bug when deleting whole folder
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | svn-import
Files: files | file ages | folders
SHA1:05537c6fc04045f423ceba6e15c8dd4929efe574
User & Date: baruch 2014-11-03 14:50:13
Context
2014-11-03
16:05
Fix bugs with filter and with add+change in same commit check-in: 65dc40a1 user: baruch tags: svn-import
14:50
Fix bug when deleting whole folder check-in: 05537c6f user: baruch tags: svn-import
2014-11-02
13:59
Options to set trunk/branches/tags folder names and project repository root (filter). Various fixes check-in: f67cb93f user: baruch tags: svn-import
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/import.c.

919
920
921
922
923
924
925



926
927
928
929
930
931
932
...
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
...
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
....
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
....
1098
1099
1100
1101
1102
1103
1104
1105





1106
1107
1108
1109
1110
1111
1112
....
1122
1123
1124
1125
1126
1127
1128

1129
1130
1131
1132
1133
1134
1135
....
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
....
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
  db_static_prepare(&qFiles, "SELECT tpath, trid, tperm FROM xfiles "
                             "WHERE tpath GLOB :filter ORDER BY tpath");
  db_static_prepare(&qTags, "SELECT ttag FROM xtags WHERE trev=:rev");
  if( !gsvn.flatFlag ){
    if( gsvn.parent<0 ){
      gsvn.parent = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions "
                               "WHERE tbranch=%Q", gsvn.zBranch);



    }
    db_bind_int(&insRev, ":rev", gsvn.rev);
    db_bind_text(&insRev, ":branch", gsvn.zBranch);
    db_bind_int(&insRev, ":rid", 0);
    db_step(&insRev);
    db_reset(&insRev);
  }else{
................................................................................
  if( gsvn.zComment ){
    blob_appendf(&manifest, "C %F\n", gsvn.zComment);
  }else{
    blob_append(&manifest, "C (no\\scomment)\n", 16);
  }
  blob_appendf(&manifest, "D %s\n", gsvn.zDate);
  nBaseFilter = blob_size(&gsvn.filter);
  if( strcmp(gsvn.zBranch, gsvn.zTrunk)==0 ){
    blob_appendf(&gsvn.filter, "%s*", gsvn.zTrunk);
  }else{
    blob_appendf(&gsvn.filter, "%s%s/*", gsvn.zBranches, gsvn.zBranch);
  }
  db_bind_text(&qFiles, ":filter", blob_str(&gsvn.filter));
  nFilter = blob_size(&gsvn.filter);
  while( db_step(&qFiles)==SQLITE_ROW ){
    const char *zFile = db_column_text(&qFiles, 0);
    int rid = db_column_int(&qFiles, 1);
    const char *zPerm = db_column_text(&qFiles, 2);
    const char *zUuid;
    zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
    blob_appendf(&manifest, "F %F %s %s\n", zFile+nFilter, zUuid, zPerm);
................................................................................
    db_bind_int(&qParent, ":rev", gsvn.parent);
    db_step(&qParent);
    zParentUuid = db_column_text(&qParent, 0);
    blob_appendf(&manifest, "P %s\n", zParentUuid);
    if( !gsvn.flatFlag ){
      zParentBranch = db_column_text(&qParent, 1);
      if( strcmp(gsvn.zBranch, zParentBranch)!=0 ){
        blob_appendf(&manifest, "T *branch * %s\n", gsvn.zBranch);
        blob_appendf(&manifest, "T *sym-%s *\n", gsvn.zBranch);
        zParentBranch = mprintf("%s", zParentBranch);
      }else{
        zParentBranch = 0;
      }
    }
  }else{
    blob_appendf(&manifest, "T *branch * trunk\n");
    blob_appendf(&manifest, "T *sym-trunk *\n");
................................................................................
  SvnRecord rec;
  int ver;
  const char *zTemp;
  const char *zUuid;
  Stmt addHist;
  Stmt insTag;
  Stmt cpyPath;

  int bHasFiles;

  /* version */
  if( svn_read_rec(pIn, &rec)
   && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){
    ver = atoi(zTemp);
    if( ver!=2 && ver!=3 ){
................................................................................
  db_prepare(&cpyPath,
    "WITH xsrc AS (SELECT * FROM ("
    "  SELECT tpath, trid, tperm, max(trev) trev FROM xhist"
    "  WHERE trev<=:srcrev GROUP BY tpath"
    " ) WHERE trid NOTNULL)"
    "INSERT INTO xhist (trev, tpath, trid, tperm)"
    " SELECT :rev, :path||substr(tpath, length(:srcpath)+1), trid, tperm"
    " FROM xsrc WHERE tpath>:srcpath||'/' AND tpath<:srcpath||0"





  );
  gsvn.rev = -1;
  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      if( bHasFiles ){
        svn_create_manifest();
................................................................................
      gsvn.zDate = date_in_standard_format(svn_find_prop(rec, "svn:date"));
      gsvn.parent = -1;
      gsvn.zBranch = 0;
      bHasFiles = 0;
      fossil_print("\rImporting SVN revision: %d", gsvn.rev);
      db_bind_int(&addHist, ":rev", gsvn.rev);
      db_bind_int(&cpyPath, ":rev", gsvn.rev);

    }else
    if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
      const char *zPath = zTemp;
      const char *zAction = svn_find_header(rec, "Node-action");
      const char *zKind = svn_find_header(rec, "Node-kind");
      const char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
      const char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
................................................................................
            bHasFiles = 1;
          }
        }
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        db_bind_null(&addHist, ":rid");
        db_bind_text(&addHist, ":path", zPath);
        db_bind_null(&addHist, ":perm");
        db_step(&addHist);
        db_reset(&addHist);
      } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
      if( strncmp(zAction, "add", 3)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
................................................................................
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
    }
    svn_free_rec(&rec);
  }
  if( gsvn.rev>0 ){
    svn_create_manifest();
  }
  fossil_free(gsvn.zUser);
  fossil_free(gsvn.zComment);
  fossil_free(gsvn.zDate);
  db_finalize(&addHist);
  db_finalize(&insTag);
  db_finalize(&cpyPath);

  fossil_print(" Done!\n");
}

/*
** COMMAND: import
**
** Usage: %fossil import FORMAT ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?







>
>
>







 







|





|







 







|
|
|







 







>







 







|
>
>
>
>
>







 







>







 







<
|
<
|
|







 







|








>







919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
...
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
...
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
....
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
....
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
....
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
....
1186
1187
1188
1189
1190
1191
1192

1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
....
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
  db_static_prepare(&qFiles, "SELECT tpath, trid, tperm FROM xfiles "
                             "WHERE tpath GLOB :filter ORDER BY tpath");
  db_static_prepare(&qTags, "SELECT ttag FROM xtags WHERE trev=:rev");
  if( !gsvn.flatFlag ){
    if( gsvn.parent<0 ){
      gsvn.parent = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions "
                               "WHERE tbranch=%Q", gsvn.zBranch);
      if( gsvn.parent<0 ){
        gsvn.parent = db_int(-1, "SELECT ifnull(max(trev),-1) FROM xrevisions");
      }
    }
    db_bind_int(&insRev, ":rev", gsvn.rev);
    db_bind_text(&insRev, ":branch", gsvn.zBranch);
    db_bind_int(&insRev, ":rid", 0);
    db_step(&insRev);
    db_reset(&insRev);
  }else{
................................................................................
  if( gsvn.zComment ){
    blob_appendf(&manifest, "C %F\n", gsvn.zComment);
  }else{
    blob_append(&manifest, "C (no\\scomment)\n", 16);
  }
  blob_appendf(&manifest, "D %s\n", gsvn.zDate);
  nBaseFilter = blob_size(&gsvn.filter);
  if( strncmp(gsvn.zBranch, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
    blob_appendf(&gsvn.filter, "%s*", gsvn.zTrunk);
  }else{
    blob_appendf(&gsvn.filter, "%s%s/*", gsvn.zBranches, gsvn.zBranch);
  }
  db_bind_text(&qFiles, ":filter", blob_str(&gsvn.filter));
  nFilter = blob_size(&gsvn.filter)-1;
  while( db_step(&qFiles)==SQLITE_ROW ){
    const char *zFile = db_column_text(&qFiles, 0);
    int rid = db_column_int(&qFiles, 1);
    const char *zPerm = db_column_text(&qFiles, 2);
    const char *zUuid;
    zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
    blob_appendf(&manifest, "F %F %s %s\n", zFile+nFilter, zUuid, zPerm);
................................................................................
    db_bind_int(&qParent, ":rev", gsvn.parent);
    db_step(&qParent);
    zParentUuid = db_column_text(&qParent, 0);
    blob_appendf(&manifest, "P %s\n", zParentUuid);
    if( !gsvn.flatFlag ){
      zParentBranch = db_column_text(&qParent, 1);
      if( strcmp(gsvn.zBranch, zParentBranch)!=0 ){
        blob_appendf(&manifest, "T *branch * %F\n", gsvn.zBranch);
        blob_appendf(&manifest, "T *sym-%F *\n", gsvn.zBranch);
        zParentBranch = mprintf("%F", zParentBranch);
      }else{
        zParentBranch = 0;
      }
    }
  }else{
    blob_appendf(&manifest, "T *branch * trunk\n");
    blob_appendf(&manifest, "T *sym-trunk *\n");
................................................................................
  SvnRecord rec;
  int ver;
  const char *zTemp;
  const char *zUuid;
  Stmt addHist;
  Stmt insTag;
  Stmt cpyPath;
  Stmt delPath;
  int bHasFiles;

  /* version */
  if( svn_read_rec(pIn, &rec)
   && (zTemp = svn_find_header(rec, "SVN-fs-dump-format-version")) ){
    ver = atoi(zTemp);
    if( ver!=2 && ver!=3 ){
................................................................................
  db_prepare(&cpyPath,
    "WITH xsrc AS (SELECT * FROM ("
    "  SELECT tpath, trid, tperm, max(trev) trev FROM xhist"
    "  WHERE trev<=:srcrev GROUP BY tpath"
    " ) WHERE trid NOTNULL)"
    "INSERT INTO xhist (trev, tpath, trid, tperm)"
    " SELECT :rev, :path||substr(tpath, length(:srcpath)+1), trid, tperm"
    " FROM xsrc WHERE tpath>:srcpath||'/' AND tpath<:srcpath||'0'"
  );
  db_prepare(&delPath,
    "INSERT INTO xhist (trev, tpath, trid, tperm)"
    " SELECT :rev, tpath, NULL, NULL"
    " FROM xfiles WHERE (tpath>:path||'/' AND tpath<:path||'0') OR tpath=:path"
  );
  gsvn.rev = -1;
  while( svn_read_rec(pIn, &rec) ){
    if( (zTemp = svn_find_header(rec, "Revision-number")) ){ /* revision node */
      /* finish previous revision */
      if( bHasFiles ){
        svn_create_manifest();
................................................................................
      gsvn.zDate = date_in_standard_format(svn_find_prop(rec, "svn:date"));
      gsvn.parent = -1;
      gsvn.zBranch = 0;
      bHasFiles = 0;
      fossil_print("\rImporting SVN revision: %d", gsvn.rev);
      db_bind_int(&addHist, ":rev", gsvn.rev);
      db_bind_int(&cpyPath, ":rev", gsvn.rev);
      db_bind_int(&delPath, ":rev", gsvn.rev);
    }else
    if( (zTemp = svn_find_header(rec, "Node-path")) ){ /* file/dir node */
      const char *zPath = zTemp;
      const char *zAction = svn_find_header(rec, "Node-action");
      const char *zKind = svn_find_header(rec, "Node-kind");
      const char *zSrcPath = svn_find_header(rec, "Node-copyfrom-path");
      const char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
................................................................................
            bHasFiles = 1;
          }
        }
      }
      if( strncmp(zAction, "delete", 6)==0
       || strncmp(zAction, "replace", 7)==0 )
      {

        db_bind_text(&delPath, ":path", zPath);

        db_step(&delPath);
        db_reset(&delPath);
      } /* no 'else' here since 'replace' does both a 'delete' and an 'add' */
      if( strncmp(zAction, "add", 3)==0
       || strncmp(zAction, "replace", 7)==0 )
      {
        if( zKind==0 ){
          fossil_fatal("Missing Node-kind");
        }else if( strncmp(zKind, "dir", 3)==0 ){
................................................................................
        fossil_fatal("Unknown Node-action");
      }
    }else{
      fossil_fatal("Unknown record type");
    }
    svn_free_rec(&rec);
  }
  if( bHasFiles ){
    svn_create_manifest();
  }
  fossil_free(gsvn.zUser);
  fossil_free(gsvn.zComment);
  fossil_free(gsvn.zDate);
  db_finalize(&addHist);
  db_finalize(&insTag);
  db_finalize(&cpyPath);
  db_finalize(&delPath);
  fossil_print(" Done!\n");
}

/*
** COMMAND: import
**
** Usage: %fossil import FORMAT ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?