Fossil SCM
Sanitize branch names to conform to Git restrictions.
Commit
11bcc4eb108cf98f6b20bfa07ef68974c5b998d20670e37c3ed145bdb1d86c76
Parent
5063eb521ed1092…
1 file changed
+43
-1
+43
-1
| --- src/export.c | ||
| +++ src/export.c | ||
| @@ -831,10 +831,46 @@ | ||
| 831 | 831 | int n; |
| 832 | 832 | db_find_and_open_repository(0, 0); |
| 833 | 833 | n = topological_sort_checkins(1); |
| 834 | 834 | fossil_print("%d reorderings required\n", n); |
| 835 | 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 | +} | |
| 836 | 872 | |
| 837 | 873 | /* |
| 838 | 874 | ** Transfer a tag over to the mirror. "rid" is the BLOB.RID value for |
| 839 | 875 | ** the record that describes the tag. |
| 840 | 876 | ** |
| @@ -962,10 +998,12 @@ | ||
| 962 | 998 | TAG_BRANCH, rid |
| 963 | 999 | ); |
| 964 | 1000 | if( fossil_strcmp(zBranch,"trunk")==0 ){ |
| 965 | 1001 | fossil_free(zBranch); |
| 966 | 1002 | zBranch = mprintf("master"); |
| 1003 | + }else{ | |
| 1004 | + mirror_sanitize_git_name(zBranch); | |
| 967 | 1005 | } |
| 968 | 1006 | |
| 969 | 1007 | /* Export the check-in */ |
| 970 | 1008 | fprintf(xCmd, "commit refs/head/%s\n", zBranch); |
| 971 | 1009 | fossil_free(zBranch); |
| @@ -1183,11 +1221,15 @@ | ||
| 1183 | 1221 | " AND mtime>coalesce((SELECT value FROM mconfig WHERE key='start'),0.0)" |
| 1184 | 1222 | " AND blob.rid=event.objid" |
| 1185 | 1223 | " AND blob.uuid NOT IN (SELECT uuid FROM mirror.mmark);" |
| 1186 | 1224 | ); |
| 1187 | 1225 | 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 | + } | |
| 1189 | 1231 | db_prepare(&q, |
| 1190 | 1232 | "SELECT objid, type, mtime, uuid FROM tomirror ORDER BY mtime" |
| 1191 | 1233 | ); |
| 1192 | 1234 | while( nLimit && db_step(&q)==SQLITE_ROW ){ |
| 1193 | 1235 | double rMTime = db_column_double(&q, 2); |
| 1194 | 1236 |
| --- 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 |