Fossil SCM

Change "magic numbers" to named constants

baruch 2015-01-11 12:44 svn-import
Commit c8e00eb1f5e04923a1ddd4faf25e9e8f7ee42c9d
1 file changed +14 -9
+14 -9
--- src/import.c
+++ src/import.c
@@ -908,10 +908,15 @@
908908
*/
909909
char * rid_to_uuid(int rid)
910910
{
911911
return db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
912912
}
913
+
914
+#define SVN_UNKNOWN 0
915
+#define SVN_TRUNK 1
916
+#define SVN_BRANCH 2
917
+#define SVN_TAG 3
913918
914919
static void svn_finish_revision(){
915920
Blob manifest;
916921
static Stmt getChanges;
917922
static Stmt getFiles;
@@ -931,11 +936,11 @@
931936
const char *zBranch = db_column_text(&getChanges, 1);
932937
int branchType = db_column_int(&getChanges, 2);
933938
int parentRid = db_column_int(&getChanges, 3);
934939
int mergeRid = parentRid;
935940
int rid;
936
- if( branchType!=3 ){
941
+ if( branchType!=SVN_TAG ){
937942
if( gsvn.zComment ){
938943
blob_appendf(&manifest, "C %F\n", gsvn.zComment);
939944
}else{
940945
blob_append(&manifest, "C (no\\scomment)\n", 16);
941946
}
@@ -1062,44 +1067,44 @@
10621067
** Extract the branch or tag that the given path is on. Return the branch ID.
10631068
*/
10641069
static int svn_parse_path(char *zPath, char **zFile, int *type){
10651070
char *zBranch = 0;
10661071
int branchId = 0;
1067
- *type = 0;
1072
+ *type = SVN_UNKNOWN;
10681073
*zFile = 0;
10691074
if( gsvn.lenTrunk==0 ){
10701075
zBranch = "trunk";
10711076
*zFile = zPath;
1072
- *type = 1;
1077
+ *type = SVN_TRUNK;
10731078
}else
10741079
if( strncmp(zPath, gsvn.zTrunk, gsvn.lenTrunk-1)==0 ){
10751080
if( zPath[gsvn.lenTrunk-1]=='/' || zPath[gsvn.lenTrunk-1]==0 ){
10761081
zBranch = "trunk";
10771082
*zFile = zPath+gsvn.lenTrunk;
1078
- *type = 1;
1083
+ *type = SVN_TRUNK;
10791084
}else{
10801085
zBranch = 0;
1081
- *type = 0;
1086
+ *type = SVN_UNKNOWN;
10821087
}
10831088
}else{
10841089
if( strncmp(zPath, gsvn.zBranches, gsvn.lenBranches)==0 ){
10851090
*zFile = zBranch = zPath+gsvn.lenBranches;
1086
- *type = 2;
1091
+ *type = SVN_BRANCH;
10871092
}else
10881093
if( strncmp(zPath, gsvn.zTags, gsvn.lenTags)==0 ){
10891094
*zFile = zBranch = zPath+gsvn.lenTags;
1090
- *type = 3;
1095
+ *type = SVN_TAG;
10911096
}else{ /* Not a branch, tag or trunk */
10921097
return 0;
10931098
}
10941099
while( **zFile && **zFile!='/' ){ (*zFile)++; }
10951100
if( **zFile ){
10961101
**zFile = '\0';
10971102
(*zFile)++;
10981103
}
10991104
}
1100
- if( *type>0 ){
1105
+ if( *type!=SVN_UNKNOWN ){
11011106
branchId = db_int(0,
11021107
"SELECT tid FROM xbranches WHERE tname=%Q AND ttype=%d",
11031108
zBranch, *type);
11041109
if( branchId==0 ){
11051110
db_multi_exec("INSERT INTO xbranches (tname, ttype) VALUES(%Q, %d)",
@@ -1248,11 +1253,11 @@
12481253
}
12491254
srcBranch = svn_parse_path(zSrcPath, &zSrcFile, &branchType);
12501255
if( srcBranch==0 ){
12511256
fossil_fatal("Copy from path outside the import paths");
12521257
}
1253
- if( branchType!=3 ){
1258
+ if( branchType!=SVN_TAG ){
12541259
srcRid = db_int(0, "SELECT trid, max(trev) FROM xrevisions"
12551260
" WHERE trev<=%d AND tbranch=%d",
12561261
srcRev, srcBranch);
12571262
}else{
12581263
srcRid = db_int(0, "SELECT tparent, max(trev) FROM xrevisions"
12591264
--- 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

Keyboard Shortcuts

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