Fossil SCM
Attempt to simplify/unify the logic for looking up the start of a branch.
Commit
485eb736034f3f73671d2c49e9780d0e832f016d
Parent
488dcfada1ff1d8…
1 file changed
+15
-43
+15
-43
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -42,10 +42,20 @@ | ||
| 42 | 42 | if( z[7]!='-') return 0; |
| 43 | 43 | if( !fossil_isdigit(z[8]) ) return 0; |
| 44 | 44 | if( !fossil_isdigit(z[9]) ) return 0; |
| 45 | 45 | return 1; |
| 46 | 46 | } |
| 47 | + | |
| 48 | +/* | |
| 49 | +** Return the name of the branch containing RID -OR- zero if not found. | |
| 50 | +*/ | |
| 51 | +char *name_of_branch(int rid){ | |
| 52 | + return db_text(0,"SELECT value FROM tagxref" | |
| 53 | + " WHERE rid=%d AND tagid=%d" | |
| 54 | + " AND tagtype>0", | |
| 55 | + rid, TAG_BRANCH); | |
| 56 | +} | |
| 47 | 57 | |
| 48 | 58 | /* |
| 49 | 59 | ** Return the RID that is the "root" of the branch that contains |
| 50 | 60 | ** check-in "rid" if inBranch==0 or the first check-in in the branch |
| 51 | 61 | ** if inBranch==1. |
| @@ -1080,57 +1090,19 @@ | ||
| 1080 | 1090 | char *branchName = 0; /* Name of the branch at rid */ |
| 1081 | 1091 | char *parentBranchName = 0; /* Name of the parent branch */ |
| 1082 | 1092 | int rid; |
| 1083 | 1093 | |
| 1084 | 1094 | /* Get the name of the current branch */ |
| 1085 | - branchName = db_text(0, | |
| 1086 | - "SELECT value FROM tagxref" | |
| 1087 | - " WHERE tagid=%d" | |
| 1088 | - " AND tagxref.tagtype>0" | |
| 1089 | - " AND rid=%d", | |
| 1090 | - TAG_BRANCH, branchRid | |
| 1091 | - ); | |
| 1095 | + branchName = name_of_branch(branchRid); | |
| 1092 | 1096 | |
| 1093 | 1097 | if( !branchName ) |
| 1094 | 1098 | return 0; |
| 1095 | 1099 | |
| 1096 | - /* Find the name of the branch this was forked from */ | |
| 1097 | - db_prepare(&s, | |
| 1098 | - "SELECT pid, tagxref.value FROM plink JOIN tagxref" | |
| 1099 | - " WHERE cid=:rid" | |
| 1100 | - " AND isprim=1" | |
| 1101 | - " AND tagxref.tagid=%d" | |
| 1102 | - " AND tagxref.tagtype>0" | |
| 1103 | - " AND tagxref.rid=pid", | |
| 1104 | - TAG_BRANCH | |
| 1105 | - ); | |
| 1106 | - rid = branchRid; | |
| 1107 | - while( rid>0 ){ | |
| 1108 | - db_bind_int(&s, ":rid", rid); | |
| 1109 | - if( db_step(&s)==SQLITE_ROW ){ | |
| 1110 | - const char *zValue; /* Branch name of the pid */ | |
| 1111 | - rid = db_column_int(&s, 0); | |
| 1112 | - zValue = db_column_text(&s, 1); | |
| 1113 | - if( !zValue ){ | |
| 1114 | - rid = 0; | |
| 1115 | - break; | |
| 1116 | - } | |
| 1117 | - if( fossil_strcmp(zValue,branchName) ){ | |
| 1118 | - parentBranchName = fossil_strdup(zValue); | |
| 1119 | - break; | |
| 1120 | - } | |
| 1121 | - }else{ | |
| 1122 | - rid = 0; | |
| 1123 | - break; | |
| 1124 | - } | |
| 1125 | - db_reset(&s); | |
| 1126 | - } | |
| 1127 | - db_finalize(&s); | |
| 1128 | - | |
| 1129 | - if( rid==0 ){ | |
| 1130 | - fossil_free(branchName); | |
| 1131 | - fossil_free(parentBranchName); | |
| 1100 | + parentBranchName = name_of_branch(start_of_branch(branchRid, 0)); | |
| 1101 | + | |
| 1102 | + if( !parentBranchName ){ | |
| 1103 | + fossil_free(branchName); | |
| 1132 | 1104 | return 0; |
| 1133 | 1105 | } |
| 1134 | 1106 | |
| 1135 | 1107 | /* Find the last checkin coming from the parent branch */ |
| 1136 | 1108 | db_prepare(&s, |
| 1137 | 1109 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -42,10 +42,20 @@ | |
| 42 | if( z[7]!='-') return 0; |
| 43 | if( !fossil_isdigit(z[8]) ) return 0; |
| 44 | if( !fossil_isdigit(z[9]) ) return 0; |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | ** Return the RID that is the "root" of the branch that contains |
| 50 | ** check-in "rid" if inBranch==0 or the first check-in in the branch |
| 51 | ** if inBranch==1. |
| @@ -1080,57 +1090,19 @@ | |
| 1080 | char *branchName = 0; /* Name of the branch at rid */ |
| 1081 | char *parentBranchName = 0; /* Name of the parent branch */ |
| 1082 | int rid; |
| 1083 | |
| 1084 | /* Get the name of the current branch */ |
| 1085 | branchName = db_text(0, |
| 1086 | "SELECT value FROM tagxref" |
| 1087 | " WHERE tagid=%d" |
| 1088 | " AND tagxref.tagtype>0" |
| 1089 | " AND rid=%d", |
| 1090 | TAG_BRANCH, branchRid |
| 1091 | ); |
| 1092 | |
| 1093 | if( !branchName ) |
| 1094 | return 0; |
| 1095 | |
| 1096 | /* Find the name of the branch this was forked from */ |
| 1097 | db_prepare(&s, |
| 1098 | "SELECT pid, tagxref.value FROM plink JOIN tagxref" |
| 1099 | " WHERE cid=:rid" |
| 1100 | " AND isprim=1" |
| 1101 | " AND tagxref.tagid=%d" |
| 1102 | " AND tagxref.tagtype>0" |
| 1103 | " AND tagxref.rid=pid", |
| 1104 | TAG_BRANCH |
| 1105 | ); |
| 1106 | rid = branchRid; |
| 1107 | while( rid>0 ){ |
| 1108 | db_bind_int(&s, ":rid", rid); |
| 1109 | if( db_step(&s)==SQLITE_ROW ){ |
| 1110 | const char *zValue; /* Branch name of the pid */ |
| 1111 | rid = db_column_int(&s, 0); |
| 1112 | zValue = db_column_text(&s, 1); |
| 1113 | if( !zValue ){ |
| 1114 | rid = 0; |
| 1115 | break; |
| 1116 | } |
| 1117 | if( fossil_strcmp(zValue,branchName) ){ |
| 1118 | parentBranchName = fossil_strdup(zValue); |
| 1119 | break; |
| 1120 | } |
| 1121 | }else{ |
| 1122 | rid = 0; |
| 1123 | break; |
| 1124 | } |
| 1125 | db_reset(&s); |
| 1126 | } |
| 1127 | db_finalize(&s); |
| 1128 | |
| 1129 | if( rid==0 ){ |
| 1130 | fossil_free(branchName); |
| 1131 | fossil_free(parentBranchName); |
| 1132 | return 0; |
| 1133 | } |
| 1134 | |
| 1135 | /* Find the last checkin coming from the parent branch */ |
| 1136 | db_prepare(&s, |
| 1137 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -42,10 +42,20 @@ | |
| 42 | if( z[7]!='-') return 0; |
| 43 | if( !fossil_isdigit(z[8]) ) return 0; |
| 44 | if( !fossil_isdigit(z[9]) ) return 0; |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | ** Return the name of the branch containing RID -OR- zero if not found. |
| 50 | */ |
| 51 | char *name_of_branch(int rid){ |
| 52 | return db_text(0,"SELECT value FROM tagxref" |
| 53 | " WHERE rid=%d AND tagid=%d" |
| 54 | " AND tagtype>0", |
| 55 | rid, TAG_BRANCH); |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | ** Return the RID that is the "root" of the branch that contains |
| 60 | ** check-in "rid" if inBranch==0 or the first check-in in the branch |
| 61 | ** if inBranch==1. |
| @@ -1080,57 +1090,19 @@ | |
| 1090 | char *branchName = 0; /* Name of the branch at rid */ |
| 1091 | char *parentBranchName = 0; /* Name of the parent branch */ |
| 1092 | int rid; |
| 1093 | |
| 1094 | /* Get the name of the current branch */ |
| 1095 | branchName = name_of_branch(branchRid); |
| 1096 | |
| 1097 | if( !branchName ) |
| 1098 | return 0; |
| 1099 | |
| 1100 | parentBranchName = name_of_branch(start_of_branch(branchRid, 0)); |
| 1101 | |
| 1102 | if( !parentBranchName ){ |
| 1103 | fossil_free(branchName); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | /* Find the last checkin coming from the parent branch */ |
| 1108 | db_prepare(&s, |
| 1109 |