Index: src/diffcmd.c ================================================================== --- src/diffcmd.c +++ src/diffcmd.c @@ -183,14 +183,14 @@ /* ** Do a diff against a single file named in zFileTreeName from version zFrom ** against the same file on disk. */ static void diff_one_against_disk( - const char *zFrom, /* Name of file */ + const char *zFrom, /* Version to difference from */ const char *zDiffCmd, /* Use this "diff" command */ int ignoreEolWs, /* Ignore whitespace changes at end of lines */ - const char *zFileTreeName + const char *zFileTreeName /* Name of file */ ){ Blob fname; Blob content; int isLink; file_tree_name(zFileTreeName, &fname, 1); @@ -225,11 +225,11 @@ vid = db_lget_int("checkout", 0); vfile_check_signature(vid, 1, 0); blob_zero(&sql); db_begin_transaction(); if( zFrom ){ - int rid = name_to_typed_rid(zFrom, "ci"); + int rid = extended_ci_name_to_rid(zFrom); if( !is_a_version(rid) ){ fossil_fatal("no such check-in: %s", zFrom); } load_vfile_from_rid(rid); blob_appendf(&sql, Index: src/manifest.c ================================================================== --- src/manifest.c +++ src/manifest.c @@ -938,11 +938,11 @@ */ Manifest *manifest_get_by_name(const char *zName, int *pRid){ int rid; Manifest *p; - rid = name_to_typed_rid(zName, "ci"); + rid = extended_ci_name_to_rid(zName); if( !is_a_version(rid) ){ fossil_fatal("no such checkin: %s", zName); } if( pRid ) *pRid = rid; p = manifest_get(rid, CFTYPE_MANIFEST); Index: src/name.c ================================================================== --- src/name.c +++ src/name.c @@ -387,7 +387,70 @@ return 0; }else{ rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); blob_reset(&name); } + return rid; +} + + +/* +** Similar to name_to_typed_rid(zName, "ci"), +** but it accepts more variants for the name. The additional variants are: +** +** checkout The current checkout +** parent The parent of the current checkout +** pivot:id1:id2 The pivot between id1 and id2 +** +** It should allow easier naming of checkins, both in 'diff' and 'update' +** commands for example. +*/ +int extended_ci_name_to_rid(const char *zName){ + int rid; + + rid = db_lget_int("checkout", 0); + + if( fossil_strcmp(zName, "checkout")==0 ){ + rid = db_lget_int("checkout", 0); + } + else if( fossil_strcmp(zName, "parent")==0 ){ + int cid; + cid = db_lget_int("checkout", 0); + if (cid == 0) + fossil_fatal("cannot find current checkout version"); + rid = db_int(0, "SELECT pid FROM plink WHERE cid=%d", cid); + if (rid == 0) + fossil_fatal("cannot find the parent of the current checkout version"); + } + else if( strlen(zName) > 6 && memcmp(zName, "pivot:", 6)==0 ){ + /* This conflicts with 'tag:', but I don't know a better char than : */ + const char *zPair = zName + 6; + char *zIdName; + int rid1, rid2; + char *zPair2 = strdup(zPair); /* Just for constness and strtok */ + + zIdName = strtok(zPair2,":"); + + if (!zIdName) + fossil_fatal("Cannot parse pivot#checkin1#checkin2"); + rid1 = name_to_typed_rid(zIdName, "ci"); + if (rid1 == 0) + fossil_fatal("Cannot find the check-in %s", zIdName); + + zIdName = strtok(NULL,":"); + rid2 = name_to_typed_rid(zIdName, "ci"); + + pivot_set_primary(rid1); + pivot_set_secondary(rid2); + rid = pivot_find(); + + if (rid == 0) + fossil_fatal("Cannot find the pivot of %s", zName); + + free(zPair2); + } + else{ + rid = name_to_typed_rid(zName, "ci"); + } + return rid; } Index: src/update.c ================================================================== --- src/update.c +++ src/update.c @@ -131,11 +131,11 @@ /* If VERSION is "latest", then use the same algorithm to find the ** target as if VERSION were omitted and the --latest flag is present. */ latestFlag = 1; }else{ - tid = name_to_typed_rid(g.argv[2],"ci"); + tid = extended_ci_name_to_rid(g.argv[2]); if( tid==0 ){ fossil_fatal("no such version: %s", g.argv[2]); }else if( !is_a_version(tid) ){ fossil_fatal("no such version: %s", g.argv[2]); } @@ -553,11 +553,11 @@ Manifest *pManifest; ManifestFile *pFile; int rid=0; if( revision ){ - rid = name_to_typed_rid(revision,"ci"); + rid = extended_ci_name_to_rid(revision); }else{ rid = db_lget_int("checkout", 0); } if( !is_a_version(rid) ){ if( errCode>0 ) return errCode;