Fossil SCM
Change "magic numbers" to named constants
Commit
c8e00eb1f5e04923a1ddd4faf25e9e8f7ee42c9d
Parent
997da4f0e45fb25…
1 file changed
+14
-9
+14
-9
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -908,10 +908,15 @@ | ||
| 908 | 908 | */ |
| 909 | 909 | char * rid_to_uuid(int rid) |
| 910 | 910 | { |
| 911 | 911 | return db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 912 | 912 | } |
| 913 | + | |
| 914 | +#define SVN_UNKNOWN 0 | |
| 915 | +#define SVN_TRUNK 1 | |
| 916 | +#define SVN_BRANCH 2 | |
| 917 | +#define SVN_TAG 3 | |
| 913 | 918 | |
| 914 | 919 | static void svn_finish_revision(){ |
| 915 | 920 | Blob manifest; |
| 916 | 921 | static Stmt getChanges; |
| 917 | 922 | static Stmt getFiles; |
| @@ -931,11 +936,11 @@ | ||
| 931 | 936 | const char *zBranch = db_column_text(&getChanges, 1); |
| 932 | 937 | int branchType = db_column_int(&getChanges, 2); |
| 933 | 938 | int parentRid = db_column_int(&getChanges, 3); |
| 934 | 939 | int mergeRid = parentRid; |
| 935 | 940 | int rid; |
| 936 | - if( branchType!=3 ){ | |
| 941 | + if( branchType!=SVN_TAG ){ | |
| 937 | 942 | if( gsvn.zComment ){ |
| 938 | 943 | blob_appendf(&manifest, "C %F\n", gsvn.zComment); |
| 939 | 944 | }else{ |
| 940 | 945 | blob_append(&manifest, "C (no\\scomment)\n", 16); |
| 941 | 946 | } |
| @@ -1062,44 +1067,44 @@ | ||
| 1062 | 1067 | ** Extract the branch or tag that the given path is on. Return the branch ID. |
| 1063 | 1068 | */ |
| 1064 | 1069 | static int svn_parse_path(char *zPath, char **zFile, int *type){ |
| 1065 | 1070 | char *zBranch = 0; |
| 1066 | 1071 | int branchId = 0; |
| 1067 | - *type = 0; | |
| 1072 | + *type = SVN_UNKNOWN; | |
| 1068 | 1073 | *zFile = 0; |
| 1069 | 1074 | if( gsvn.lenTrunk==0 ){ |
| 1070 | 1075 | zBranch = "trunk"; |
| 1071 | 1076 | *zFile = zPath; |
| 1072 | - *type = 1; | |
| 1077 | + *type = SVN_TRUNK; | |
| 1073 | 1078 | }else |
| 1074 | 1079 | if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){ |
| 1075 | 1080 | if( zPath[gsvn.lenTrunk-1]=='/' || zPath[gsvn.lenTrunk-1]==0 ){ |
| 1076 | 1081 | zBranch = "trunk"; |
| 1077 | 1082 | *zFile = zPath+gsvn.lenTrunk; |
| 1078 | - *type = 1; | |
| 1083 | + *type = SVN_TRUNK; | |
| 1079 | 1084 | }else{ |
| 1080 | 1085 | zBranch = 0; |
| 1081 | - *type = 0; | |
| 1086 | + *type = SVN_UNKNOWN; | |
| 1082 | 1087 | } |
| 1083 | 1088 | }else{ |
| 1084 | 1089 | if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){ |
| 1085 | 1090 | *zFile = zBranch = zPath+gsvn.lenBranches; |
| 1086 | - *type = 2; | |
| 1091 | + *type = SVN_BRANCH; | |
| 1087 | 1092 | }else |
| 1088 | 1093 | if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){ |
| 1089 | 1094 | *zFile = zBranch = zPath+gsvn.lenTags; |
| 1090 | - *type = 3; | |
| 1095 | + *type = SVN_TAG; | |
| 1091 | 1096 | }else{ /* Not a branch, tag or trunk */ |
| 1092 | 1097 | return 0; |
| 1093 | 1098 | } |
| 1094 | 1099 | while( **zFile && **zFile!='/' ){ (*zFile)++; } |
| 1095 | 1100 | if( **zFile ){ |
| 1096 | 1101 | **zFile = '\0'; |
| 1097 | 1102 | (*zFile)++; |
| 1098 | 1103 | } |
| 1099 | 1104 | } |
| 1100 | - if( *type>0 ){ | |
| 1105 | + if( *type!=SVN_UNKNOWN ){ | |
| 1101 | 1106 | branchId = db_int(0, |
| 1102 | 1107 | "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d", |
| 1103 | 1108 | zBranch, *type); |
| 1104 | 1109 | if( branchId==0 ){ |
| 1105 | 1110 | db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)", |
| @@ -1248,11 +1253,11 @@ | ||
| 1248 | 1253 | } |
| 1249 | 1254 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1250 | 1255 | if( srcBranch==0 ){ |
| 1251 | 1256 | fossil_fatal("Copy from path outside the import paths"); |
| 1252 | 1257 | } |
| 1253 | - if( branchType!=3 ){ | |
| 1258 | + if( branchType!=SVN_TAG ){ | |
| 1254 | 1259 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1255 | 1260 | " WHERE trev<=%d AND tbranch=%d", |
| 1256 | 1261 | srcRev, srcBranch); |
| 1257 | 1262 | }else{ |
| 1258 | 1263 | srcRid = db_int(0, "SELECT tparent, max(trev) FROM xrevisions" |
| 1259 | 1264 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -908,10 +908,15 @@ | |
| 908 | */ |
| 909 | char * rid_to_uuid(int rid) |
| 910 | { |
| 911 | return db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 912 | } |
| 913 | |
| 914 | static void svn_finish_revision(){ |
| 915 | Blob manifest; |
| 916 | static Stmt getChanges; |
| 917 | static Stmt getFiles; |
| @@ -931,11 +936,11 @@ | |
| 931 | const char *zBranch = db_column_text(&getChanges, 1); |
| 932 | int branchType = db_column_int(&getChanges, 2); |
| 933 | int parentRid = db_column_int(&getChanges, 3); |
| 934 | int mergeRid = parentRid; |
| 935 | int rid; |
| 936 | if( branchType!=3 ){ |
| 937 | if( gsvn.zComment ){ |
| 938 | blob_appendf(&manifest, "C %F\n", gsvn.zComment); |
| 939 | }else{ |
| 940 | blob_append(&manifest, "C (no\\scomment)\n", 16); |
| 941 | } |
| @@ -1062,44 +1067,44 @@ | |
| 1062 | ** Extract the branch or tag that the given path is on. Return the branch ID. |
| 1063 | */ |
| 1064 | static int svn_parse_path(char *zPath, char **zFile, int *type){ |
| 1065 | char *zBranch = 0; |
| 1066 | int branchId = 0; |
| 1067 | *type = 0; |
| 1068 | *zFile = 0; |
| 1069 | if( gsvn.lenTrunk==0 ){ |
| 1070 | zBranch = "trunk"; |
| 1071 | *zFile = zPath; |
| 1072 | *type = 1; |
| 1073 | }else |
| 1074 | if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){ |
| 1075 | if( zPath[gsvn.lenTrunk-1]=='/' || zPath[gsvn.lenTrunk-1]==0 ){ |
| 1076 | zBranch = "trunk"; |
| 1077 | *zFile = zPath+gsvn.lenTrunk; |
| 1078 | *type = 1; |
| 1079 | }else{ |
| 1080 | zBranch = 0; |
| 1081 | *type = 0; |
| 1082 | } |
| 1083 | }else{ |
| 1084 | if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){ |
| 1085 | *zFile = zBranch = zPath+gsvn.lenBranches; |
| 1086 | *type = 2; |
| 1087 | }else |
| 1088 | if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){ |
| 1089 | *zFile = zBranch = zPath+gsvn.lenTags; |
| 1090 | *type = 3; |
| 1091 | }else{ /* Not a branch, tag or trunk */ |
| 1092 | return 0; |
| 1093 | } |
| 1094 | while( **zFile && **zFile!='/' ){ (*zFile)++; } |
| 1095 | if( **zFile ){ |
| 1096 | **zFile = '\0'; |
| 1097 | (*zFile)++; |
| 1098 | } |
| 1099 | } |
| 1100 | if( *type>0 ){ |
| 1101 | branchId = db_int(0, |
| 1102 | "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d", |
| 1103 | zBranch, *type); |
| 1104 | if( branchId==0 ){ |
| 1105 | db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)", |
| @@ -1248,11 +1253,11 @@ | |
| 1248 | } |
| 1249 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1250 | if( srcBranch==0 ){ |
| 1251 | fossil_fatal("Copy from path outside the import paths"); |
| 1252 | } |
| 1253 | if( branchType!=3 ){ |
| 1254 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1255 | " WHERE trev<=%d AND tbranch=%d", |
| 1256 | srcRev, srcBranch); |
| 1257 | }else{ |
| 1258 | srcRid = db_int(0, "SELECT tparent, max(trev) FROM xrevisions" |
| 1259 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -908,10 +908,15 @@ | |
| 908 | */ |
| 909 | char * rid_to_uuid(int rid) |
| 910 | { |
| 911 | return db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 912 | } |
| 913 | |
| 914 | #define SVN_UNKNOWN 0 |
| 915 | #define SVN_TRUNK 1 |
| 916 | #define SVN_BRANCH 2 |
| 917 | #define SVN_TAG 3 |
| 918 | |
| 919 | static void svn_finish_revision(){ |
| 920 | Blob manifest; |
| 921 | static Stmt getChanges; |
| 922 | static Stmt getFiles; |
| @@ -931,11 +936,11 @@ | |
| 936 | const char *zBranch = db_column_text(&getChanges, 1); |
| 937 | int branchType = db_column_int(&getChanges, 2); |
| 938 | int parentRid = db_column_int(&getChanges, 3); |
| 939 | int mergeRid = parentRid; |
| 940 | int rid; |
| 941 | if( branchType!=SVN_TAG ){ |
| 942 | if( gsvn.zComment ){ |
| 943 | blob_appendf(&manifest, "C %F\n", gsvn.zComment); |
| 944 | }else{ |
| 945 | blob_append(&manifest, "C (no\\scomment)\n", 16); |
| 946 | } |
| @@ -1062,44 +1067,44 @@ | |
| 1067 | ** Extract the branch or tag that the given path is on. Return the branch ID. |
| 1068 | */ |
| 1069 | static int svn_parse_path(char *zPath, char **zFile, int *type){ |
| 1070 | char *zBranch = 0; |
| 1071 | int branchId = 0; |
| 1072 | *type = SVN_UNKNOWN; |
| 1073 | *zFile = 0; |
| 1074 | if( gsvn.lenTrunk==0 ){ |
| 1075 | zBranch = "trunk"; |
| 1076 | *zFile = zPath; |
| 1077 | *type = SVN_TRUNK; |
| 1078 | }else |
| 1079 | if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){ |
| 1080 | if( zPath[gsvn.lenTrunk-1]=='/' || zPath[gsvn.lenTrunk-1]==0 ){ |
| 1081 | zBranch = "trunk"; |
| 1082 | *zFile = zPath+gsvn.lenTrunk; |
| 1083 | *type = SVN_TRUNK; |
| 1084 | }else{ |
| 1085 | zBranch = 0; |
| 1086 | *type = SVN_UNKNOWN; |
| 1087 | } |
| 1088 | }else{ |
| 1089 | if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){ |
| 1090 | *zFile = zBranch = zPath+gsvn.lenBranches; |
| 1091 | *type = SVN_BRANCH; |
| 1092 | }else |
| 1093 | if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){ |
| 1094 | *zFile = zBranch = zPath+gsvn.lenTags; |
| 1095 | *type = SVN_TAG; |
| 1096 | }else{ /* Not a branch, tag or trunk */ |
| 1097 | return 0; |
| 1098 | } |
| 1099 | while( **zFile && **zFile!='/' ){ (*zFile)++; } |
| 1100 | if( **zFile ){ |
| 1101 | **zFile = '\0'; |
| 1102 | (*zFile)++; |
| 1103 | } |
| 1104 | } |
| 1105 | if( *type!=SVN_UNKNOWN ){ |
| 1106 | branchId = db_int(0, |
| 1107 | "SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d", |
| 1108 | zBranch, *type); |
| 1109 | if( branchId==0 ){ |
| 1110 | db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)", |
| @@ -1248,11 +1253,11 @@ | |
| 1253 | } |
| 1254 | srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType); |
| 1255 | if( srcBranch==0 ){ |
| 1256 | fossil_fatal("Copy from path outside the import paths"); |
| 1257 | } |
| 1258 | if( branchType!=SVN_TAG ){ |
| 1259 | srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions" |
| 1260 | " WHERE trev<=%d AND tbranch=%d", |
| 1261 | srcRev, srcBranch); |
| 1262 | }else{ |
| 1263 | srcRid = db_int(0, "SELECT tparent, max(trev) FROM xrevisions" |
| 1264 |