Fossil SCM
test recycling "is_ticket()" from wikiformat.c as a way to avoid trying to checkout a ticket
Commit
695b1c756336a28bfb45f16e6efc49cee613a09c
Parent
ab6a293182e1962…
1 file changed
+49
-1
+49
-1
| --- src/checkout.c | ||
| +++ src/checkout.c | ||
| @@ -44,18 +44,66 @@ | ||
| 44 | 44 | vfile_check_signature(vid); |
| 45 | 45 | return db_exists("SELECT 1 FROM vfile WHERE chnged" |
| 46 | 46 | " OR coalesce(origname!=pathname,0)"); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + | |
| 50 | +/* | |
| 51 | +** zTarget is guaranteed to be a UUID. It might be the UUID of a ticket. | |
| 52 | +** If it is, store in *pClosed a true or false depending on whether or not | |
| 53 | +** the ticket is closed and return true. If zTarget | |
| 54 | +** is not the UUID of a ticket, return false. | |
| 55 | +*/ | |
| 56 | +static int is_ticket( | |
| 57 | + const char *zTarget, /* Ticket UUID */ | |
| 58 | + int *pClosed /* True if the ticket is closed */ | |
| 59 | +){ | |
| 60 | + static Stmt q; | |
| 61 | + static int once = 1; | |
| 62 | + int n; | |
| 63 | + int rc; | |
| 64 | + char zLower[UUID_SIZE+1]; | |
| 65 | + char zUpper[UUID_SIZE+1]; | |
| 66 | + n = strlen(zTarget); | |
| 67 | + memcpy(zLower, zTarget, n+1); | |
| 68 | + canonical16(zLower, n+1); | |
| 69 | + memcpy(zUpper, zLower, n+1); | |
| 70 | + zUpper[n-1]++; | |
| 71 | + if( once ){ | |
| 72 | + const char *zClosedExpr = db_get("ticket-closed-expr", "status='Closed'"); | |
| 73 | + db_static_prepare(&q, | |
| 74 | + "SELECT %s FROM ticket " | |
| 75 | + " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr", | |
| 76 | + zClosedExpr | |
| 77 | + ); | |
| 78 | + once = 0; | |
| 79 | + } | |
| 80 | + db_bind_text(&q, ":lwr", zLower); | |
| 81 | + db_bind_text(&q, ":upr", zUpper); | |
| 82 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 83 | + rc = 1; | |
| 84 | + *pClosed = db_column_int(&q, 0); | |
| 85 | + }else{ | |
| 86 | + rc = 0; | |
| 87 | + } | |
| 88 | + db_reset(&q); | |
| 89 | + return rc; | |
| 90 | +} | |
| 91 | + | |
| 49 | 92 | /* |
| 50 | 93 | ** Check to see if the requested co is in fact "checkout-able" |
| 51 | 94 | ** Return values: |
| 52 | 95 | ** 0: Not checkout-able (does not exist, or is not an on-disk artifact) |
| 53 | 96 | ** 1: Is checkout-able. |
| 54 | 97 | */ |
| 55 | 98 | int checkoutable(const char *zName){ |
| 56 | - int rc=1; /* assuming is checkout-able */ | |
| 99 | + int rc; /* return code */ | |
| 100 | + int throwaway; | |
| 101 | + | |
| 102 | + rc = !is_ticket(zName, &throwaway); | |
| 103 | + return(rc); | |
| 104 | + | |
| 57 | 105 | Blob uuid; |
| 58 | 106 | const char *rid=(char *)NULL; |
| 59 | 107 | Stmt q; // db query |
| 60 | 108 | char *zSQL; //build-up sql |
| 61 | 109 | |
| 62 | 110 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -44,18 +44,66 @@ | |
| 44 | vfile_check_signature(vid); |
| 45 | return db_exists("SELECT 1 FROM vfile WHERE chnged" |
| 46 | " OR coalesce(origname!=pathname,0)"); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | ** Check to see if the requested co is in fact "checkout-able" |
| 51 | ** Return values: |
| 52 | ** 0: Not checkout-able (does not exist, or is not an on-disk artifact) |
| 53 | ** 1: Is checkout-able. |
| 54 | */ |
| 55 | int checkoutable(const char *zName){ |
| 56 | int rc=1; /* assuming is checkout-able */ |
| 57 | Blob uuid; |
| 58 | const char *rid=(char *)NULL; |
| 59 | Stmt q; // db query |
| 60 | char *zSQL; //build-up sql |
| 61 | |
| 62 |
| --- src/checkout.c | |
| +++ src/checkout.c | |
| @@ -44,18 +44,66 @@ | |
| 44 | vfile_check_signature(vid); |
| 45 | return db_exists("SELECT 1 FROM vfile WHERE chnged" |
| 46 | " OR coalesce(origname!=pathname,0)"); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /* |
| 51 | ** zTarget is guaranteed to be a UUID. It might be the UUID of a ticket. |
| 52 | ** If it is, store in *pClosed a true or false depending on whether or not |
| 53 | ** the ticket is closed and return true. If zTarget |
| 54 | ** is not the UUID of a ticket, return false. |
| 55 | */ |
| 56 | static int is_ticket( |
| 57 | const char *zTarget, /* Ticket UUID */ |
| 58 | int *pClosed /* True if the ticket is closed */ |
| 59 | ){ |
| 60 | static Stmt q; |
| 61 | static int once = 1; |
| 62 | int n; |
| 63 | int rc; |
| 64 | char zLower[UUID_SIZE+1]; |
| 65 | char zUpper[UUID_SIZE+1]; |
| 66 | n = strlen(zTarget); |
| 67 | memcpy(zLower, zTarget, n+1); |
| 68 | canonical16(zLower, n+1); |
| 69 | memcpy(zUpper, zLower, n+1); |
| 70 | zUpper[n-1]++; |
| 71 | if( once ){ |
| 72 | const char *zClosedExpr = db_get("ticket-closed-expr", "status='Closed'"); |
| 73 | db_static_prepare(&q, |
| 74 | "SELECT %s FROM ticket " |
| 75 | " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr", |
| 76 | zClosedExpr |
| 77 | ); |
| 78 | once = 0; |
| 79 | } |
| 80 | db_bind_text(&q, ":lwr", zLower); |
| 81 | db_bind_text(&q, ":upr", zUpper); |
| 82 | if( db_step(&q)==SQLITE_ROW ){ |
| 83 | rc = 1; |
| 84 | *pClosed = db_column_int(&q, 0); |
| 85 | }else{ |
| 86 | rc = 0; |
| 87 | } |
| 88 | db_reset(&q); |
| 89 | return rc; |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | ** Check to see if the requested co is in fact "checkout-able" |
| 94 | ** Return values: |
| 95 | ** 0: Not checkout-able (does not exist, or is not an on-disk artifact) |
| 96 | ** 1: Is checkout-able. |
| 97 | */ |
| 98 | int checkoutable(const char *zName){ |
| 99 | int rc; /* return code */ |
| 100 | int throwaway; |
| 101 | |
| 102 | rc = !is_ticket(zName, &throwaway); |
| 103 | return(rc); |
| 104 | |
| 105 | Blob uuid; |
| 106 | const char *rid=(char *)NULL; |
| 107 | Stmt q; // db query |
| 108 | char *zSQL; //build-up sql |
| 109 | |
| 110 |