Fossil SCM

Add comments, format code and remove magic size numbers.

danield 2022-03-30 14:01 describe-cmd
Commit 40de2cd9c3273f119d9a614d91f6519ae61570f6307df3803f10afd2afcbb9cb
1 file changed +28 -17
+28 -17
--- src/info.c
+++ src/info.c
@@ -3680,38 +3680,49 @@
36803680
}
36813681
db_finalize(&q);
36823682
}
36833683
36843684
#if INTERFACE
3685
+/*
3686
+** Description of a checkin relative to an earlier, tagged checkin.
3687
+*/
36853688
typedef struct CommitDescr {
3686
- char zLastTag[100];
3687
- int nCommitsSince;
3688
- char zArtifactHash[65];
3689
- int isDirty;
3689
+ char *zRelTagname; /* Tag name on the relative checkin */
3690
+ int nCommitsSince; /* Number of commits since then */
3691
+ char *zCommitHash; /* Hash of the described checkin */
3692
+ int isDirty; /* Working directory has uncommitted changes */
36903693
} CommitDescr;
36913694
#endif
36923695
3696
+/*
3697
+** Describe the checkin given by 'zName', and possibly matching 'matchGlob',
3698
+** relative to an earlier, tagged checkin. Use 'descr' for the output.
3699
+**
3700
+** Finds the closest ancestor (ignoring merge-ins) that has a non-propagating
3701
+** label tag and the number of steps backwards that we had to search in
3702
+** order to find that tag.
3703
+*/
36933704
int describe_commit(const char *zName, const char *matchGlob,
36943705
CommitDescr *descr){
3695
- int rid;
3696
- const char *zUuid;
3697
- int nRet = 0;
3698
- Stmt q;
3706
+ int rid; /* rid for zName */
3707
+ const char *zUuid; /* Hash of rid */
3708
+ int nRet = 0; /* Value to be returned */
3709
+ Stmt q; /* Query for tagged ancestors */
36993710
37003711
rid = symbolic_name_to_rid(zName, "ci"); /* only commits */
37013712
37023713
if( rid<=0 ){
37033714
/* Commit does not exist */
3704
- *(descr->zLastTag) = 0;
3715
+ *(descr->zRelTagname) = 0;
37053716
descr->nCommitsSince = -1;
3706
- *(descr->zArtifactHash) = 0;
3717
+ *(descr->zCommitHash) = 0;
37073718
descr->isDirty = -1;
37083719
return -1;
37093720
}
37103721
37113722
zUuid = rid_to_uuid(rid);
3712
- memcpy(descr->zArtifactHash, zUuid, strlen(zUuid)+1);
3723
+ descr->zCommitHash = mprintf("%s", zUuid);
37133724
descr->isDirty = unsaved_changes(0);
37143725
37153726
db_multi_exec(
37163727
"DROP TABLE IF EXISTS singletonTaggedAncestors;"
37173728
"CREATE TEMP TABLE singletonTaggedAncestors AS"
@@ -3762,16 +3773,16 @@
37623773
(matchGlob ? matchGlob : "*")
37633774
);
37643775
37653776
if( db_step(&q)==SQLITE_ROW ){
37663777
const char *lastTag = db_column_text(&q, 4);
3767
- memcpy(descr->zLastTag, lastTag, strlen(lastTag)+1);
3778
+ descr->zRelTagname = mprintf("%s", lastTag);
37683779
descr->nCommitsSince = db_column_int(&q, 2)-1;
37693780
nRet = 0;
37703781
}else{
37713782
/* no ancestor commit with a fitting singleton tag found */
3772
- *(descr->zLastTag) = 0;
3783
+ *(descr->zRelTagname) = 0;
37733784
descr->nCommitsSince = -1;
37743785
nRet = -2;
37753786
}
37763787
37773788
db_finalize(&q);
@@ -3833,23 +3844,23 @@
38333844
switch( describe_commit(zName, zMatchGlob, &descr) ){
38343845
case -1:
38353846
fossil_fatal("commit %s does not exist", zName);
38363847
break;
38373848
case -2:
3838
- fossil_print("%.*s%s\n", nDigits, descr.zArtifactHash,
3849
+ fossil_print("%.*s%s\n", nDigits, descr.zCommitHash,
38393850
bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
38403851
break;
38413852
case 0:
38423853
if( descr.nCommitsSince==0 && !bLongFlag ){
3843
- fossil_print("%s%s\n", descr.zLastTag,
3854
+ fossil_print("%s%s\n", descr.zRelTagname,
38443855
bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
38453856
}else{
3846
- fossil_print("%s-%d-%.*s%s\n", descr.zLastTag,
3847
- descr.nCommitsSince, nDigits, descr.zArtifactHash,
3857
+ fossil_print("%s-%d-%.*s%s\n", descr.zRelTagname,
3858
+ descr.nCommitsSince, nDigits, descr.zCommitHash,
38483859
bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
38493860
}
38503861
break;
38513862
default:
38523863
fossil_fatal("cannot describe commit");
38533864
break;
38543865
}
38553866
}
38563867
--- src/info.c
+++ src/info.c
@@ -3680,38 +3680,49 @@
3680 }
3681 db_finalize(&q);
3682 }
3683
3684 #if INTERFACE
 
 
 
3685 typedef struct CommitDescr {
3686 char zLastTag[100];
3687 int nCommitsSince;
3688 char zArtifactHash[65];
3689 int isDirty;
3690 } CommitDescr;
3691 #endif
3692
 
 
 
 
 
 
 
 
3693 int describe_commit(const char *zName, const char *matchGlob,
3694 CommitDescr *descr){
3695 int rid;
3696 const char *zUuid;
3697 int nRet = 0;
3698 Stmt q;
3699
3700 rid = symbolic_name_to_rid(zName, "ci"); /* only commits */
3701
3702 if( rid<=0 ){
3703 /* Commit does not exist */
3704 *(descr->zLastTag) = 0;
3705 descr->nCommitsSince = -1;
3706 *(descr->zArtifactHash) = 0;
3707 descr->isDirty = -1;
3708 return -1;
3709 }
3710
3711 zUuid = rid_to_uuid(rid);
3712 memcpy(descr->zArtifactHash, zUuid, strlen(zUuid)+1);
3713 descr->isDirty = unsaved_changes(0);
3714
3715 db_multi_exec(
3716 "DROP TABLE IF EXISTS singletonTaggedAncestors;"
3717 "CREATE TEMP TABLE singletonTaggedAncestors AS"
@@ -3762,16 +3773,16 @@
3762 (matchGlob ? matchGlob : "*")
3763 );
3764
3765 if( db_step(&q)==SQLITE_ROW ){
3766 const char *lastTag = db_column_text(&q, 4);
3767 memcpy(descr->zLastTag, lastTag, strlen(lastTag)+1);
3768 descr->nCommitsSince = db_column_int(&q, 2)-1;
3769 nRet = 0;
3770 }else{
3771 /* no ancestor commit with a fitting singleton tag found */
3772 *(descr->zLastTag) = 0;
3773 descr->nCommitsSince = -1;
3774 nRet = -2;
3775 }
3776
3777 db_finalize(&q);
@@ -3833,23 +3844,23 @@
3833 switch( describe_commit(zName, zMatchGlob, &descr) ){
3834 case -1:
3835 fossil_fatal("commit %s does not exist", zName);
3836 break;
3837 case -2:
3838 fossil_print("%.*s%s\n", nDigits, descr.zArtifactHash,
3839 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3840 break;
3841 case 0:
3842 if( descr.nCommitsSince==0 && !bLongFlag ){
3843 fossil_print("%s%s\n", descr.zLastTag,
3844 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3845 }else{
3846 fossil_print("%s-%d-%.*s%s\n", descr.zLastTag,
3847 descr.nCommitsSince, nDigits, descr.zArtifactHash,
3848 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3849 }
3850 break;
3851 default:
3852 fossil_fatal("cannot describe commit");
3853 break;
3854 }
3855 }
3856
--- src/info.c
+++ src/info.c
@@ -3680,38 +3680,49 @@
3680 }
3681 db_finalize(&q);
3682 }
3683
3684 #if INTERFACE
3685 /*
3686 ** Description of a checkin relative to an earlier, tagged checkin.
3687 */
3688 typedef struct CommitDescr {
3689 char *zRelTagname; /* Tag name on the relative checkin */
3690 int nCommitsSince; /* Number of commits since then */
3691 char *zCommitHash; /* Hash of the described checkin */
3692 int isDirty; /* Working directory has uncommitted changes */
3693 } CommitDescr;
3694 #endif
3695
3696 /*
3697 ** Describe the checkin given by 'zName', and possibly matching 'matchGlob',
3698 ** relative to an earlier, tagged checkin. Use 'descr' for the output.
3699 **
3700 ** Finds the closest ancestor (ignoring merge-ins) that has a non-propagating
3701 ** label tag and the number of steps backwards that we had to search in
3702 ** order to find that tag.
3703 */
3704 int describe_commit(const char *zName, const char *matchGlob,
3705 CommitDescr *descr){
3706 int rid; /* rid for zName */
3707 const char *zUuid; /* Hash of rid */
3708 int nRet = 0; /* Value to be returned */
3709 Stmt q; /* Query for tagged ancestors */
3710
3711 rid = symbolic_name_to_rid(zName, "ci"); /* only commits */
3712
3713 if( rid<=0 ){
3714 /* Commit does not exist */
3715 *(descr->zRelTagname) = 0;
3716 descr->nCommitsSince = -1;
3717 *(descr->zCommitHash) = 0;
3718 descr->isDirty = -1;
3719 return -1;
3720 }
3721
3722 zUuid = rid_to_uuid(rid);
3723 descr->zCommitHash = mprintf("%s", zUuid);
3724 descr->isDirty = unsaved_changes(0);
3725
3726 db_multi_exec(
3727 "DROP TABLE IF EXISTS singletonTaggedAncestors;"
3728 "CREATE TEMP TABLE singletonTaggedAncestors AS"
@@ -3762,16 +3773,16 @@
3773 (matchGlob ? matchGlob : "*")
3774 );
3775
3776 if( db_step(&q)==SQLITE_ROW ){
3777 const char *lastTag = db_column_text(&q, 4);
3778 descr->zRelTagname = mprintf("%s", lastTag);
3779 descr->nCommitsSince = db_column_int(&q, 2)-1;
3780 nRet = 0;
3781 }else{
3782 /* no ancestor commit with a fitting singleton tag found */
3783 *(descr->zRelTagname) = 0;
3784 descr->nCommitsSince = -1;
3785 nRet = -2;
3786 }
3787
3788 db_finalize(&q);
@@ -3833,23 +3844,23 @@
3844 switch( describe_commit(zName, zMatchGlob, &descr) ){
3845 case -1:
3846 fossil_fatal("commit %s does not exist", zName);
3847 break;
3848 case -2:
3849 fossil_print("%.*s%s\n", nDigits, descr.zCommitHash,
3850 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3851 break;
3852 case 0:
3853 if( descr.nCommitsSince==0 && !bLongFlag ){
3854 fossil_print("%s%s\n", descr.zRelTagname,
3855 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3856 }else{
3857 fossil_print("%s-%d-%.*s%s\n", descr.zRelTagname,
3858 descr.nCommitsSince, nDigits, descr.zCommitHash,
3859 bDirtyFlag ? (descr.isDirty ? "-dirty" : "") : "");
3860 }
3861 break;
3862 default:
3863 fossil_fatal("cannot describe commit");
3864 break;
3865 }
3866 }
3867

Keyboard Shortcuts

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