Fossil

Check-in [11bcc4eb]
Login

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

Overview
Comment:Sanitize branch names to conform to Git restrictions.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | mirror-cmd
Files: files | file ages | folders
SHA3-256: 11bcc4eb108cf98f6b20bfa07ef68974c5b998d20670e37c3ed145bdb1d86c76
User & Date: drh 2019-03-14 18:55:24.661
Context
2019-03-14
19:43
Fix the export so that it is able to handle phantom check-ins. ... (check-in: 4a480954 user: drh tags: mirror-cmd)
18:55
Sanitize branch names to conform to Git restrictions. ... (check-in: 11bcc4eb user: drh tags: mirror-cmd)
18:20
Progress on the "fossil mirror" command. ... (check-in: 5063eb52 user: drh tags: mirror-cmd)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/export.c.
829
830
831
832
833
834
835




































836
837
838
839
840
841
842
*/
void test_topological_sort(void){
  int n;
  db_find_and_open_repository(0, 0);
  n = topological_sort_checkins(1);
  fossil_print("%d reorderings required\n", n);
}





































/*
** Transfer a tag over to the mirror.  "rid" is the BLOB.RID value for
** the record that describes the tag.
**
** The Git tag mechanism is very limited compared to Fossil.  Many Fossil
** tags cannot be exported to Git.  If this tag cannot be exported, then







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
*/
void test_topological_sort(void){
  int n;
  db_find_and_open_repository(0, 0);
  n = topological_sort_checkins(1);
  fossil_print("%d reorderings required\n", n);
}

/***************************************************************************
** Implementation of the "fossil mirror" command follows.  We hope that the
** new code that follows will largely replace the legacy "fossil export" code
** above.
*/

/*
** Convert characters of z[] that are not allowed to be in branch or
** tag names into "_".
*/
static void mirror_sanitize_git_name(char *z){
  static unsigned char aSafe[] = {
     /* x0 x1 x2 x3 x4 x5 x6 x7 x8  x9 xA xB xC xD xE xF */
         0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,  /* 0x */
         0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0,  /* 1x */
         0, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 2x */
         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 0, 1, 1, 1, 1, 0,  /* 3x */
         0, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 4x */
         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 0, 0, 1, 0, 1,  /* 5x */
         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1,  /* 6x */
         1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 0, 0,  /* 7x */
  };
  unsigned char *zu = (unsigned char*)z;
  int i;
  for(i=0; zu[i]; i++){
    if( zu[i]>0x7f || !aSafe[zu[i]] ){
      zu[i] = '_';
    }else if( zu[i]=='/' && (i==0 || zu[i+1]==0 || zu[i+1]=='/') ){
      zu[i] = '_';
    }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
                             || (i>0 && zu[i-1]=='.')) ){
      zu[i] = '_';
    }
  }
}

/*
** Transfer a tag over to the mirror.  "rid" is the BLOB.RID value for
** the record that describes the tag.
**
** The Git tag mechanism is very limited compared to Fossil.  Many Fossil
** tags cannot be exported to Git.  If this tag cannot be exported, then
960
961
962
963
964
965
966


967
968
969
970
971
972
973
  zBranch = db_text(0,
    "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d",
    TAG_BRANCH, rid
  );
  if( fossil_strcmp(zBranch,"trunk")==0 ){
    fossil_free(zBranch);
    zBranch = mprintf("master");


  }

  /* Export the check-in */
  fprintf(xCmd, "commit refs/head/%s\n", zBranch);
  fossil_free(zBranch);
  iMark = mirror_find_mark(zUuid, 1);
  fprintf(xCmd, "mark :%d\n", iMark);







>
>







996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
  zBranch = db_text(0,
    "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=%d",
    TAG_BRANCH, rid
  );
  if( fossil_strcmp(zBranch,"trunk")==0 ){
    fossil_free(zBranch);
    zBranch = mprintf("master");
  }else{
    mirror_sanitize_git_name(zBranch);
  }

  /* Export the check-in */
  fprintf(xCmd, "commit refs/head/%s\n", zBranch);
  fossil_free(zBranch);
  iMark = mirror_find_mark(zUuid, 1);
  fprintf(xCmd, "mark :%d\n", iMark);
1181
1182
1183
1184
1185
1186
1187
1188




1189
1190
1191
1192
1193
1194
1195
    "SELECT objid, type, mtime, blob.uuid FROM event, blob\n"
    " WHERE type IN ('ci','t')"
    "   AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
    "   AND blob.rid=event.objid"
    "   AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
  );
  nTotal = db_int(0, "SELECT count(*) FROM tomirror");
  if( nLimit<nTotal ) nTotal = nLimit;




  db_prepare(&q,
    "SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime"
  );
  while( nLimit && db_step(&q)==SQLITE_ROW ){
    double rMTime = db_column_double(&q, 2);
    const char *zType = db_column_text(&q, 1);
    int rid = db_column_int(&q, 0);







|
>
>
>
>







1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
    "SELECT objid, type, mtime, blob.uuid FROM event, blob\n"
    " WHERE type IN ('ci','t')"
    "   AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
    "   AND blob.rid=event.objid"
    "   AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
  );
  nTotal = db_int(0, "SELECT count(*) FROM tomirror");
  if( nLimit<nTotal ){
    nTotal = nLimit;
  }else if( nLimit>nTotal ){
    nLimit = nTotal;
  }
  db_prepare(&q,
    "SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime"
  );
  while( nLimit && db_step(&q)==SQLITE_ROW ){
    double rMTime = db_column_double(&q, 2);
    const char *zType = db_column_text(&q, 1);
    int rid = db_column_int(&q, 0);