Index: src/checkout.c ================================================================== --- src/checkout.c +++ src/checkout.c @@ -43,10 +43,91 @@ if( vid==0 ) return 2; vfile_check_signature(vid); return db_exists("SELECT 1 FROM vfile WHERE chnged" " OR coalesce(origname!=pathname,0)"); } + + +/* +** zTarget is guaranteed to be a UUID. It might be the UUID of a ticket. +** If it is, store in *pClosed a true or false depending on whether or not +** the ticket is closed and return true. If zTarget +** is not the UUID of a ticket, return false. +*/ +static int is_ticket( + const char *zTarget, /* Ticket UUID */ + int *pClosed /* True if the ticket is closed */ +){ + fprintf(stderr,"I'm in is_ticket\n"); + + static Stmt q; + static int once = 1; + int n; + int rc; + char zLower[UUID_SIZE+1]; + char zUpper[UUID_SIZE+1]; + n = strlen(zTarget); + memcpy(zLower, zTarget, n+1); + canonical16(zLower, n+1); + memcpy(zUpper, zLower, n+1); + zUpper[n-1]++; + if( once ){ + const char *zClosedExpr = db_get("ticket-closed-expr", "status='Closed'"); + db_static_prepare(&q, + "SELECT %s FROM ticket " + " WHERE tkt_uuid>=:lwr AND tkt_uuid<:upr", + zClosedExpr + ); + once = 0; + } + db_bind_text(&q, ":lwr", zLower); + db_bind_text(&q, ":upr", zUpper); + if( db_step(&q)==SQLITE_ROW ){ + rc = 1; + *pClosed = db_column_int(&q, 0); + }else{ + rc = 0; + } + db_reset(&q); + return rc; +} + +/* +** Check to see if the requested co is in fact "checkout-able" +** Return values: +** 0: Not checkout-able (does not exist, or is not an on-disk artifact) +** 1: Is checkout-able. +*/ +int checkoutable(const char *zName){ + int rc; /* return code */ + int throwaway; + + rc = !is_ticket(zName, &throwaway); + fprintf(stderr,"rc is: %d\n", rc); + return(rc); + + Blob uuid; + const char *rid=(char *)NULL; + Stmt q; // db query + char *zSQL; //build-up sql + + // zSQL = mprintf(); + + // [create sql statement] + // db_prepare(&q,sqlstmt); + + blob_init(&uuid, zName, -1); + if( name_to_uuid(&uuid, 1) ){ + fossil_panic(g.zErrMsg); + } + + /* nParent=db_text(0,"select rid from blob where uuid=%s",uuid.nameofobj); */ + + /* int nParent = db_column_int(q, somenum); */ + return rc; +} + /* ** Undo the current check-out. Unlink all files from the disk. ** Clear the VFILE table. */ @@ -157,10 +238,13 @@ noWrite = find_option("dontwrite",0,0)!=0; if( g.argc!=3 ) usage("?--force? VERSION"); if( !forceFlag && unsaved_changes()==1 ){ fossil_fatal("there are unsaved changes in the current checkout"); } + if(!checkoutable(g.argv[2])){ + fossil_fatal("the VERSION you requested is not a checkout-able artifact"); + } if( forceFlag ){ db_multi_exec("DELETE FROM vfile"); prior = 0; }else{ prior = db_lget_int("checkout",0);