| | @@ -387,7 +387,70 @@ |
| 387 | 387 | return 0; |
| 388 | 388 | }else{ |
| 389 | 389 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); |
| 390 | 390 | blob_reset(&name); |
| 391 | 391 | } |
| 392 | + return rid; |
| 393 | +} |
| 394 | + |
| 395 | + |
| 396 | +/* |
| 397 | +** Similar to name_to_typed_rid(zName, "ci"), |
| 398 | +** but it accepts more variants for the name. The additional variants are: |
| 399 | +** |
| 400 | +** checkout The current checkout |
| 401 | +** parent The parent of the current checkout |
| 402 | +** pivot:id1:id2 The pivot between id1 and id2 |
| 403 | +** |
| 404 | +** It should allow easier naming of checkins, both in 'diff' and 'update' |
| 405 | +** commands for example. |
| 406 | +*/ |
| 407 | +int extended_ci_name_to_rid(const char *zName){ |
| 408 | + int rid; |
| 409 | + |
| 410 | + rid = db_lget_int("checkout", 0); |
| 411 | + |
| 412 | + if( fossil_strcmp(zName, "checkout")==0 ){ |
| 413 | + rid = db_lget_int("checkout", 0); |
| 414 | + } |
| 415 | + else if( fossil_strcmp(zName, "parent")==0 ){ |
| 416 | + int cid; |
| 417 | + cid = db_lget_int("checkout", 0); |
| 418 | + if (cid == 0) |
| 419 | + fossil_fatal("cannot find current checkout version"); |
| 420 | + rid = db_int(0, "SELECT pid FROM plink WHERE cid=%d", cid); |
| 421 | + if (rid == 0) |
| 422 | + fossil_fatal("cannot find the parent of the current checkout version"); |
| 423 | + } |
| 424 | + else if( strlen(zName) > 6 && memcmp(zName, "pivot:", 6)==0 ){ |
| 425 | + /* This conflicts with 'tag:', but I don't know a better char than : */ |
| 426 | + const char *zPair = zName + 6; |
| 427 | + char *zIdName; |
| 428 | + int rid1, rid2; |
| 429 | + char *zPair2 = strdup(zPair); /* Just for constness and strtok */ |
| 430 | + |
| 431 | + zIdName = strtok(zPair2,":"); |
| 432 | + |
| 433 | + if (!zIdName) |
| 434 | + fossil_fatal("Cannot parse pivot#checkin1#checkin2"); |
| 435 | + rid1 = name_to_typed_rid(zIdName, "ci"); |
| 436 | + if (rid1 == 0) |
| 437 | + fossil_fatal("Cannot find the check-in %s", zIdName); |
| 438 | + |
| 439 | + zIdName = strtok(NULL,":"); |
| 440 | + rid2 = name_to_typed_rid(zIdName, "ci"); |
| 441 | + |
| 442 | + pivot_set_primary(rid1); |
| 443 | + pivot_set_secondary(rid2); |
| 444 | + rid = pivot_find(); |
| 445 | + |
| 446 | + if (rid == 0) |
| 447 | + fossil_fatal("Cannot find the pivot of %s", zName); |
| 448 | + |
| 449 | + free(zPair2); |
| 450 | + } |
| 451 | + else{ |
| 452 | + rid = name_to_typed_rid(zName, "ci"); |
| 453 | + } |
| 454 | + |
| 392 | 455 | return rid; |
| 393 | 456 | } |
| 394 | 457 | |