Fossil SCM

Adding a more options at naming commits for diff and update commands. I wrote a new function that allows more kind of specifications for a checkin uuid: checkout, parent and pivot:id1:id2. If there was a way to discover the 'parent branch' of the current checkout, there could be a 'parentbranch' naming too. I think this makes the life easier, specially for the pivot:id1:id2 case, about seeing the difference between a branch and its parent branch. I find myself using often the test-find-pivot command just to get that diff or update to the pivot, to check changes between the current branch and the parent branch.

viriketo 2011-10-12 17:41 UTC trunk
Commit 9fe787ec03bd0101be77032f6b1a89bb42a9d922
+3 -3
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -183,14 +183,14 @@
183183
/*
184184
** Do a diff against a single file named in zFileTreeName from version zFrom
185185
** against the same file on disk.
186186
*/
187187
static void diff_one_against_disk(
188
- const char *zFrom, /* Name of file */
188
+ const char *zFrom, /* Version to difference from */
189189
const char *zDiffCmd, /* Use this "diff" command */
190190
int ignoreEolWs, /* Ignore whitespace changes at end of lines */
191
- const char *zFileTreeName
191
+ const char *zFileTreeName /* Name of file */
192192
){
193193
Blob fname;
194194
Blob content;
195195
int isLink;
196196
file_tree_name(zFileTreeName, &fname, 1);
@@ -225,11 +225,11 @@
225225
vid = db_lget_int("checkout", 0);
226226
vfile_check_signature(vid, 1, 0);
227227
blob_zero(&sql);
228228
db_begin_transaction();
229229
if( zFrom ){
230
- int rid = name_to_typed_rid(zFrom, "ci");
230
+ int rid = extended_ci_name_to_rid(zFrom);
231231
if( !is_a_version(rid) ){
232232
fossil_fatal("no such check-in: %s", zFrom);
233233
}
234234
load_vfile_from_rid(rid);
235235
blob_appendf(&sql,
236236
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -183,14 +183,14 @@
183 /*
184 ** Do a diff against a single file named in zFileTreeName from version zFrom
185 ** against the same file on disk.
186 */
187 static void diff_one_against_disk(
188 const char *zFrom, /* Name of file */
189 const char *zDiffCmd, /* Use this "diff" command */
190 int ignoreEolWs, /* Ignore whitespace changes at end of lines */
191 const char *zFileTreeName
192 ){
193 Blob fname;
194 Blob content;
195 int isLink;
196 file_tree_name(zFileTreeName, &fname, 1);
@@ -225,11 +225,11 @@
225 vid = db_lget_int("checkout", 0);
226 vfile_check_signature(vid, 1, 0);
227 blob_zero(&sql);
228 db_begin_transaction();
229 if( zFrom ){
230 int rid = name_to_typed_rid(zFrom, "ci");
231 if( !is_a_version(rid) ){
232 fossil_fatal("no such check-in: %s", zFrom);
233 }
234 load_vfile_from_rid(rid);
235 blob_appendf(&sql,
236
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -183,14 +183,14 @@
183 /*
184 ** Do a diff against a single file named in zFileTreeName from version zFrom
185 ** against the same file on disk.
186 */
187 static void diff_one_against_disk(
188 const char *zFrom, /* Version to difference from */
189 const char *zDiffCmd, /* Use this "diff" command */
190 int ignoreEolWs, /* Ignore whitespace changes at end of lines */
191 const char *zFileTreeName /* Name of file */
192 ){
193 Blob fname;
194 Blob content;
195 int isLink;
196 file_tree_name(zFileTreeName, &fname, 1);
@@ -225,11 +225,11 @@
225 vid = db_lget_int("checkout", 0);
226 vfile_check_signature(vid, 1, 0);
227 blob_zero(&sql);
228 db_begin_transaction();
229 if( zFrom ){
230 int rid = extended_ci_name_to_rid(zFrom);
231 if( !is_a_version(rid) ){
232 fossil_fatal("no such check-in: %s", zFrom);
233 }
234 load_vfile_from_rid(rid);
235 blob_appendf(&sql,
236
+1 -1
--- src/manifest.c
+++ src/manifest.c
@@ -938,11 +938,11 @@
938938
*/
939939
Manifest *manifest_get_by_name(const char *zName, int *pRid){
940940
int rid;
941941
Manifest *p;
942942
943
- rid = name_to_typed_rid(zName, "ci");
943
+ rid = extended_ci_name_to_rid(zName);
944944
if( !is_a_version(rid) ){
945945
fossil_fatal("no such checkin: %s", zName);
946946
}
947947
if( pRid ) *pRid = rid;
948948
p = manifest_get(rid, CFTYPE_MANIFEST);
949949
--- src/manifest.c
+++ src/manifest.c
@@ -938,11 +938,11 @@
938 */
939 Manifest *manifest_get_by_name(const char *zName, int *pRid){
940 int rid;
941 Manifest *p;
942
943 rid = name_to_typed_rid(zName, "ci");
944 if( !is_a_version(rid) ){
945 fossil_fatal("no such checkin: %s", zName);
946 }
947 if( pRid ) *pRid = rid;
948 p = manifest_get(rid, CFTYPE_MANIFEST);
949
--- src/manifest.c
+++ src/manifest.c
@@ -938,11 +938,11 @@
938 */
939 Manifest *manifest_get_by_name(const char *zName, int *pRid){
940 int rid;
941 Manifest *p;
942
943 rid = extended_ci_name_to_rid(zName);
944 if( !is_a_version(rid) ){
945 fossil_fatal("no such checkin: %s", zName);
946 }
947 if( pRid ) *pRid = rid;
948 p = manifest_get(rid, CFTYPE_MANIFEST);
949
+63
--- src/name.c
+++ src/name.c
@@ -387,7 +387,70 @@
387387
return 0;
388388
}else{
389389
rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
390390
blob_reset(&name);
391391
}
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
+
392455
return rid;
393456
}
394457
--- src/name.c
+++ src/name.c
@@ -387,7 +387,70 @@
387 return 0;
388 }else{
389 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
390 blob_reset(&name);
391 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392 return rid;
393 }
394
--- src/name.c
+++ src/name.c
@@ -387,7 +387,70 @@
387 return 0;
388 }else{
389 rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name);
390 blob_reset(&name);
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
455 return rid;
456 }
457
+2 -2
--- src/update.c
+++ src/update.c
@@ -131,11 +131,11 @@
131131
/* If VERSION is "latest", then use the same algorithm to find the
132132
** target as if VERSION were omitted and the --latest flag is present.
133133
*/
134134
latestFlag = 1;
135135
}else{
136
- tid = name_to_typed_rid(g.argv[2],"ci");
136
+ tid = extended_ci_name_to_rid(g.argv[2]);
137137
if( tid==0 ){
138138
fossil_fatal("no such version: %s", g.argv[2]);
139139
}else if( !is_a_version(tid) ){
140140
fossil_fatal("no such version: %s", g.argv[2]);
141141
}
@@ -553,11 +553,11 @@
553553
Manifest *pManifest;
554554
ManifestFile *pFile;
555555
int rid=0;
556556
557557
if( revision ){
558
- rid = name_to_typed_rid(revision,"ci");
558
+ rid = extended_ci_name_to_rid(revision);
559559
}else{
560560
rid = db_lget_int("checkout", 0);
561561
}
562562
if( !is_a_version(rid) ){
563563
if( errCode>0 ) return errCode;
564564
--- src/update.c
+++ src/update.c
@@ -131,11 +131,11 @@
131 /* If VERSION is "latest", then use the same algorithm to find the
132 ** target as if VERSION were omitted and the --latest flag is present.
133 */
134 latestFlag = 1;
135 }else{
136 tid = name_to_typed_rid(g.argv[2],"ci");
137 if( tid==0 ){
138 fossil_fatal("no such version: %s", g.argv[2]);
139 }else if( !is_a_version(tid) ){
140 fossil_fatal("no such version: %s", g.argv[2]);
141 }
@@ -553,11 +553,11 @@
553 Manifest *pManifest;
554 ManifestFile *pFile;
555 int rid=0;
556
557 if( revision ){
558 rid = name_to_typed_rid(revision,"ci");
559 }else{
560 rid = db_lget_int("checkout", 0);
561 }
562 if( !is_a_version(rid) ){
563 if( errCode>0 ) return errCode;
564
--- src/update.c
+++ src/update.c
@@ -131,11 +131,11 @@
131 /* If VERSION is "latest", then use the same algorithm to find the
132 ** target as if VERSION were omitted and the --latest flag is present.
133 */
134 latestFlag = 1;
135 }else{
136 tid = extended_ci_name_to_rid(g.argv[2]);
137 if( tid==0 ){
138 fossil_fatal("no such version: %s", g.argv[2]);
139 }else if( !is_a_version(tid) ){
140 fossil_fatal("no such version: %s", g.argv[2]);
141 }
@@ -553,11 +553,11 @@
553 Manifest *pManifest;
554 ManifestFile *pFile;
555 int rid=0;
556
557 if( revision ){
558 rid = extended_ci_name_to_rid(revision);
559 }else{
560 rid = db_lget_int("checkout", 0);
561 }
562 if( !is_a_version(rid) ){
563 if( errCode>0 ) return errCode;
564

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button