Fossil SCM
Minor code clean-up inside of <tt>ticket_insert()</tt> function.
Commit
3e4ba24e29843bc985c30564acc46cd7d2b0873f01b5984e166aff5d04992d41
Parent
f905bd0d8d5b70f…
1 file changed
+11
-15
+11
-15
| --- src/tkt.c | ||
| +++ src/tkt.c | ||
| @@ -23,11 +23,11 @@ | ||
| 23 | 23 | #include <assert.h> |
| 24 | 24 | |
| 25 | 25 | /* |
| 26 | 26 | ** The list of database user-defined fields in the TICKET table. |
| 27 | 27 | ** The real table also contains some addition fields for internal |
| 28 | -** used. The internal-use fields begin with "tkt_". | |
| 28 | +** use. The internal-use fields begin with "tkt_". | |
| 29 | 29 | */ |
| 30 | 30 | static int nField = 0; |
| 31 | 31 | static struct tktFieldInfo { |
| 32 | 32 | char *zName; /* Name of the database field */ |
| 33 | 33 | char *zValue; /* Value to store */ |
| @@ -190,11 +190,13 @@ | ||
| 190 | 190 | ** Parameter rid is the recordID for the ticket artifact in the BLOB table. |
| 191 | 191 | ** |
| 192 | 192 | ** Return the new rowid of the TICKET table entry. |
| 193 | 193 | */ |
| 194 | 194 | static int ticket_insert(const Manifest *p, int rid, int tktid){ |
| 195 | - Blob sql1, sql2, sql3; | |
| 195 | + Blob sql1; /* update or replace TICKET ... */ | |
| 196 | + Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */ | |
| 197 | + Blob sql3; /* list of values which correspond to the previous list */ | |
| 196 | 198 | Stmt q; |
| 197 | 199 | int i, j; |
| 198 | 200 | char *aUsed; |
| 199 | 201 | const char *zMimetype = 0; |
| 200 | 202 | |
| @@ -211,31 +213,25 @@ | ||
| 211 | 213 | blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)"); |
| 212 | 214 | } |
| 213 | 215 | aUsed = fossil_malloc( nField ); |
| 214 | 216 | memset(aUsed, 0, nField); |
| 215 | 217 | for(i=0; i<p->nField; i++){ |
| 216 | - const char *zName = p->aField[i].zName; | |
| 217 | - const char *zBaseName = zName[0]=='+' ? zName+1 : zName; | |
| 218 | + const char * const zName = p->aField[i].zName; | |
| 219 | + const char * const zBaseName = zName[0]=='+' ? zName+1 : zName; | |
| 218 | 220 | j = fieldId(zBaseName); |
| 219 | 221 | if( j<0 ) continue; |
| 220 | 222 | aUsed[j] = 1; |
| 221 | 223 | if( aField[j].mUsed & USEDBY_TICKET ){ |
| 222 | - const char *zUsedByName = zName; | |
| 223 | - if( zUsedByName[0]=='+' ){ | |
| 224 | - zUsedByName++; | |
| 224 | + if( zName[0]=='+' ){ | |
| 225 | 225 | blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q", |
| 226 | - zUsedByName, zUsedByName, p->aField[i].zValue); | |
| 226 | + zBaseName, zBaseName, p->aField[i].zValue); | |
| 227 | 227 | }else{ |
| 228 | - blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue); | |
| 228 | + blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue); | |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | if( aField[j].mUsed & USEDBY_TICKETCHNG ){ |
| 232 | - const char *zUsedByName = zName; | |
| 233 | - if( zUsedByName[0]=='+' ){ | |
| 234 | - zUsedByName++; | |
| 235 | - } | |
| 236 | - blob_append_sql(&sql2, ",\"%w\"", zUsedByName); | |
| 232 | + blob_append_sql(&sql2, ",\"%w\"", zBaseName); | |
| 237 | 233 | blob_append_sql(&sql3, ",%Q", p->aField[i].zValue); |
| 238 | 234 | } |
| 239 | 235 | if( strcmp(zBaseName,"mimetype")==0 ){ |
| 240 | 236 | zMimetype = p->aField[i].zValue; |
| 241 | 237 | } |
| @@ -257,11 +253,11 @@ | ||
| 257 | 253 | db_finalize(&q); |
| 258 | 254 | blob_reset(&sql1); |
| 259 | 255 | if( blob_size(&sql2)>0 || haveTicketChngRid ){ |
| 260 | 256 | int fromTkt = 0; |
| 261 | 257 | if( haveTicketChngRid ){ |
| 262 | - blob_append(&sql2, ",tkt_rid", -1); | |
| 258 | + blob_append_literal(&sql2, ",tkt_rid"); | |
| 263 | 259 | blob_append_sql(&sql3, ",%d", rid); |
| 264 | 260 | } |
| 265 | 261 | for(i=0; i<nField; i++){ |
| 266 | 262 | if( aUsed[i]==0 |
| 267 | 263 | && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH |
| 268 | 264 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -23,11 +23,11 @@ | |
| 23 | #include <assert.h> |
| 24 | |
| 25 | /* |
| 26 | ** The list of database user-defined fields in the TICKET table. |
| 27 | ** The real table also contains some addition fields for internal |
| 28 | ** used. The internal-use fields begin with "tkt_". |
| 29 | */ |
| 30 | static int nField = 0; |
| 31 | static struct tktFieldInfo { |
| 32 | char *zName; /* Name of the database field */ |
| 33 | char *zValue; /* Value to store */ |
| @@ -190,11 +190,13 @@ | |
| 190 | ** Parameter rid is the recordID for the ticket artifact in the BLOB table. |
| 191 | ** |
| 192 | ** Return the new rowid of the TICKET table entry. |
| 193 | */ |
| 194 | static int ticket_insert(const Manifest *p, int rid, int tktid){ |
| 195 | Blob sql1, sql2, sql3; |
| 196 | Stmt q; |
| 197 | int i, j; |
| 198 | char *aUsed; |
| 199 | const char *zMimetype = 0; |
| 200 | |
| @@ -211,31 +213,25 @@ | |
| 211 | blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)"); |
| 212 | } |
| 213 | aUsed = fossil_malloc( nField ); |
| 214 | memset(aUsed, 0, nField); |
| 215 | for(i=0; i<p->nField; i++){ |
| 216 | const char *zName = p->aField[i].zName; |
| 217 | const char *zBaseName = zName[0]=='+' ? zName+1 : zName; |
| 218 | j = fieldId(zBaseName); |
| 219 | if( j<0 ) continue; |
| 220 | aUsed[j] = 1; |
| 221 | if( aField[j].mUsed & USEDBY_TICKET ){ |
| 222 | const char *zUsedByName = zName; |
| 223 | if( zUsedByName[0]=='+' ){ |
| 224 | zUsedByName++; |
| 225 | blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q", |
| 226 | zUsedByName, zUsedByName, p->aField[i].zValue); |
| 227 | }else{ |
| 228 | blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue); |
| 229 | } |
| 230 | } |
| 231 | if( aField[j].mUsed & USEDBY_TICKETCHNG ){ |
| 232 | const char *zUsedByName = zName; |
| 233 | if( zUsedByName[0]=='+' ){ |
| 234 | zUsedByName++; |
| 235 | } |
| 236 | blob_append_sql(&sql2, ",\"%w\"", zUsedByName); |
| 237 | blob_append_sql(&sql3, ",%Q", p->aField[i].zValue); |
| 238 | } |
| 239 | if( strcmp(zBaseName,"mimetype")==0 ){ |
| 240 | zMimetype = p->aField[i].zValue; |
| 241 | } |
| @@ -257,11 +253,11 @@ | |
| 257 | db_finalize(&q); |
| 258 | blob_reset(&sql1); |
| 259 | if( blob_size(&sql2)>0 || haveTicketChngRid ){ |
| 260 | int fromTkt = 0; |
| 261 | if( haveTicketChngRid ){ |
| 262 | blob_append(&sql2, ",tkt_rid", -1); |
| 263 | blob_append_sql(&sql3, ",%d", rid); |
| 264 | } |
| 265 | for(i=0; i<nField; i++){ |
| 266 | if( aUsed[i]==0 |
| 267 | && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH |
| 268 |
| --- src/tkt.c | |
| +++ src/tkt.c | |
| @@ -23,11 +23,11 @@ | |
| 23 | #include <assert.h> |
| 24 | |
| 25 | /* |
| 26 | ** The list of database user-defined fields in the TICKET table. |
| 27 | ** The real table also contains some addition fields for internal |
| 28 | ** use. The internal-use fields begin with "tkt_". |
| 29 | */ |
| 30 | static int nField = 0; |
| 31 | static struct tktFieldInfo { |
| 32 | char *zName; /* Name of the database field */ |
| 33 | char *zValue; /* Value to store */ |
| @@ -190,11 +190,13 @@ | |
| 190 | ** Parameter rid is the recordID for the ticket artifact in the BLOB table. |
| 191 | ** |
| 192 | ** Return the new rowid of the TICKET table entry. |
| 193 | */ |
| 194 | static int ticket_insert(const Manifest *p, int rid, int tktid){ |
| 195 | Blob sql1; /* update or replace TICKET ... */ |
| 196 | Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */ |
| 197 | Blob sql3; /* list of values which correspond to the previous list */ |
| 198 | Stmt q; |
| 199 | int i, j; |
| 200 | char *aUsed; |
| 201 | const char *zMimetype = 0; |
| 202 | |
| @@ -211,31 +213,25 @@ | |
| 213 | blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)"); |
| 214 | } |
| 215 | aUsed = fossil_malloc( nField ); |
| 216 | memset(aUsed, 0, nField); |
| 217 | for(i=0; i<p->nField; i++){ |
| 218 | const char * const zName = p->aField[i].zName; |
| 219 | const char * const zBaseName = zName[0]=='+' ? zName+1 : zName; |
| 220 | j = fieldId(zBaseName); |
| 221 | if( j<0 ) continue; |
| 222 | aUsed[j] = 1; |
| 223 | if( aField[j].mUsed & USEDBY_TICKET ){ |
| 224 | if( zName[0]=='+' ){ |
| 225 | blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q", |
| 226 | zBaseName, zBaseName, p->aField[i].zValue); |
| 227 | }else{ |
| 228 | blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue); |
| 229 | } |
| 230 | } |
| 231 | if( aField[j].mUsed & USEDBY_TICKETCHNG ){ |
| 232 | blob_append_sql(&sql2, ",\"%w\"", zBaseName); |
| 233 | blob_append_sql(&sql3, ",%Q", p->aField[i].zValue); |
| 234 | } |
| 235 | if( strcmp(zBaseName,"mimetype")==0 ){ |
| 236 | zMimetype = p->aField[i].zValue; |
| 237 | } |
| @@ -257,11 +253,11 @@ | |
| 253 | db_finalize(&q); |
| 254 | blob_reset(&sql1); |
| 255 | if( blob_size(&sql2)>0 || haveTicketChngRid ){ |
| 256 | int fromTkt = 0; |
| 257 | if( haveTicketChngRid ){ |
| 258 | blob_append_literal(&sql2, ",tkt_rid"); |
| 259 | blob_append_sql(&sql3, ",%d", rid); |
| 260 | } |
| 261 | for(i=0; i<nField; i++){ |
| 262 | if( aUsed[i]==0 |
| 263 | && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH |
| 264 |