Fossil SCM

Sanitize branch names to conform to Git restrictions.

drh 2019-03-14 18:55 UTC mirror-cmd
Commit 11bcc4eb108cf98f6b20bfa07ef68974c5b998d20670e37c3ed145bdb1d86c76
1 file changed +43 -1
+43 -1
--- src/export.c
+++ src/export.c
@@ -831,10 +831,46 @@
831831
int n;
832832
db_find_and_open_repository(0, 0);
833833
n = topological_sort_checkins(1);
834834
fossil_print("%d reorderings required\n", n);
835835
}
836
+
837
+/***************************************************************************
838
+** Implementation of the "fossil mirror" command follows. We hope that the
839
+** new code that follows will largely replace the legacy "fossil export" code
840
+** above.
841
+*/
842
+
843
+/*
844
+** Convert characters of z[] that are not allowed to be in branch or
845
+** tag names into "_".
846
+*/
847
+static void mirror_sanitize_git_name(char *z){
848
+ static unsigned char aSafe[] = {
849
+ /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
850
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
851
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
852
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 2x */
853
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* 3x */
854
+ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
855
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /* 5x */
856
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
857
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */
858
+ };
859
+ unsigned char *zu = (unsigned char*)z;
860
+ int i;
861
+ for(i=0; zu[i]; i++){
862
+ if( zu[i]>0x7f || !aSafe[zu[i]] ){
863
+ zu[i] = '_';
864
+ }else if( zu[i]=='/' && (i==0 || zu[i+1]==0 || zu[i+1]=='/') ){
865
+ zu[i] = '_';
866
+ }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
867
+ || (i>0 && zu[i-1]=='.')) ){
868
+ zu[i] = '_';
869
+ }
870
+ }
871
+}
836872
837873
/*
838874
** Transfer a tag over to the mirror. "rid" is the BLOB.RID value for
839875
** the record that describes the tag.
840876
**
@@ -962,10 +998,12 @@
962998
TAG_BRANCH, rid
963999
);
9641000
if( fossil_strcmp(zBranch,"trunk")==0 ){
9651001
fossil_free(zBranch);
9661002
zBranch = mprintf("master");
1003
+ }else{
1004
+ mirror_sanitize_git_name(zBranch);
9671005
}
9681006
9691007
/* Export the check-in */
9701008
fprintf(xCmd, "commit refs/head/%s\n", zBranch);
9711009
fossil_free(zBranch);
@@ -1183,11 +1221,15 @@
11831221
" AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
11841222
" AND blob.rid=event.objid"
11851223
" AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
11861224
);
11871225
nTotal = db_int(0, "SELECT count(*) FROM tomirror");
1188
- if( nLimit<nTotal ) nTotal = nLimit;
1226
+ if( nLimit<nTotal ){
1227
+ nTotal = nLimit;
1228
+ }else if( nLimit>nTotal ){
1229
+ nLimit = nTotal;
1230
+ }
11891231
db_prepare(&q,
11901232
"SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime"
11911233
);
11921234
while( nLimit && db_step(&q)==SQLITE_ROW ){
11931235
double rMTime = db_column_double(&q, 2);
11941236
--- src/export.c
+++ src/export.c
@@ -831,10 +831,46 @@
831 int n;
832 db_find_and_open_repository(0, 0);
833 n = topological_sort_checkins(1);
834 fossil_print("%d reorderings required\n", n);
835 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
836
837 /*
838 ** Transfer a tag over to the mirror. "rid" is the BLOB.RID value for
839 ** the record that describes the tag.
840 **
@@ -962,10 +998,12 @@
962 TAG_BRANCH, rid
963 );
964 if( fossil_strcmp(zBranch,"trunk")==0 ){
965 fossil_free(zBranch);
966 zBranch = mprintf("master");
 
 
967 }
968
969 /* Export the check-in */
970 fprintf(xCmd, "commit refs/head/%s\n", zBranch);
971 fossil_free(zBranch);
@@ -1183,11 +1221,15 @@
1183 " AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
1184 " AND blob.rid=event.objid"
1185 " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
1186 );
1187 nTotal = db_int(0, "SELECT count(*) FROM tomirror");
1188 if( nLimit<nTotal ) nTotal = nLimit;
 
 
 
 
1189 db_prepare(&q,
1190 "SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime"
1191 );
1192 while( nLimit && db_step(&q)==SQLITE_ROW ){
1193 double rMTime = db_column_double(&q, 2);
1194
--- src/export.c
+++ src/export.c
@@ -831,10 +831,46 @@
831 int n;
832 db_find_and_open_repository(0, 0);
833 n = topological_sort_checkins(1);
834 fossil_print("%d reorderings required\n", n);
835 }
836
837 /***************************************************************************
838 ** Implementation of the "fossil mirror" command follows. We hope that the
839 ** new code that follows will largely replace the legacy "fossil export" code
840 ** above.
841 */
842
843 /*
844 ** Convert characters of z[] that are not allowed to be in branch or
845 ** tag names into "_".
846 */
847 static void mirror_sanitize_git_name(char *z){
848 static unsigned char aSafe[] = {
849 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
850 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
851 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
852 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 2x */
853 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* 3x */
854 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
855 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, /* 5x */
856 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
857 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, /* 7x */
858 };
859 unsigned char *zu = (unsigned char*)z;
860 int i;
861 for(i=0; zu[i]; i++){
862 if( zu[i]>0x7f || !aSafe[zu[i]] ){
863 zu[i] = '_';
864 }else if( zu[i]=='/' && (i==0 || zu[i+1]==0 || zu[i+1]=='/') ){
865 zu[i] = '_';
866 }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
867 || (i>0 && zu[i-1]=='.')) ){
868 zu[i] = '_';
869 }
870 }
871 }
872
873 /*
874 ** Transfer a tag over to the mirror. "rid" is the BLOB.RID value for
875 ** the record that describes the tag.
876 **
@@ -962,10 +998,12 @@
998 TAG_BRANCH, rid
999 );
1000 if( fossil_strcmp(zBranch,"trunk")==0 ){
1001 fossil_free(zBranch);
1002 zBranch = mprintf("master");
1003 }else{
1004 mirror_sanitize_git_name(zBranch);
1005 }
1006
1007 /* Export the check-in */
1008 fprintf(xCmd, "commit refs/head/%s\n", zBranch);
1009 fossil_free(zBranch);
@@ -1183,11 +1221,15 @@
1221 " AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)"
1222 " AND blob.rid=event.objid"
1223 " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);"
1224 );
1225 nTotal = db_int(0, "SELECT count(*) FROM tomirror");
1226 if( nLimit<nTotal ){
1227 nTotal = nLimit;
1228 }else if( nLimit>nTotal ){
1229 nLimit = nTotal;
1230 }
1231 db_prepare(&q,
1232 "SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime"
1233 );
1234 while( nLimit && db_step(&q)==SQLITE_ROW ){
1235 double rMTime = db_column_double(&q, 2);
1236

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button