Fossil SCM

Add a link in the checkin page to show the changes in the branch in respect to the parent branch. It finds the last merge from parent to the current branch for the comparison.

viriketo 2015-02-09 10:56 trunk
Commit f309130a8bb347ee490ea83ef02ad90d413ccd3b
2 files changed +2 +107
+2
--- src/info.c
+++ src/info.c
@@ -674,10 +674,12 @@
674674
@ <td>
675675
@ %z(href("%R/tree?ci=%S",zUuid))files</a>
676676
@ | %z(href("%R/fileage?name=%S",zUuid))file ages</a>
677677
@ | %z(href("%R/tree?nofiles&type=tree&ci=%S",zUuid))folders</a>
678678
@ | %z(href("%R/artifact/%S",zUuid))manifest</a>
679
+ @ | <a href="%s(g.zTop)/vdiff?from=pbranch:%S(zUuid)&to=%S(zUuid)">
680
+ @ changes over parent branch</a>
679681
if( g.perm.Write ){
680682
@ | %z(href("%R/ci_edit?r=%S",zUuid))edit</a>
681683
}
682684
@ </td>
683685
@ </tr>
684686
--- src/info.c
+++ src/info.c
@@ -674,10 +674,12 @@
674 @ <td>
675 @ %z(href("%R/tree?ci=%S",zUuid))files</a>
676 @ | %z(href("%R/fileage?name=%S",zUuid))file ages</a>
677 @ | %z(href("%R/tree?nofiles&type=tree&ci=%S",zUuid))folders</a>
678 @ | %z(href("%R/artifact/%S",zUuid))manifest</a>
 
 
679 if( g.perm.Write ){
680 @ | %z(href("%R/ci_edit?r=%S",zUuid))edit</a>
681 }
682 @ </td>
683 @ </tr>
684
--- src/info.c
+++ src/info.c
@@ -674,10 +674,12 @@
674 @ <td>
675 @ %z(href("%R/tree?ci=%S",zUuid))files</a>
676 @ | %z(href("%R/fileage?name=%S",zUuid))file ages</a>
677 @ | %z(href("%R/tree?nofiles&type=tree&ci=%S",zUuid))folders</a>
678 @ | %z(href("%R/artifact/%S",zUuid))manifest</a>
679 @ | <a href="%s(g.zTop)/vdiff?from=pbranch:%S(zUuid)&to=%S(zUuid)">
680 @ changes over parent branch</a>
681 if( g.perm.Write ){
682 @ | %z(href("%R/ci_edit?r=%S",zUuid))edit</a>
683 }
684 @ </td>
685 @ </tr>
686
+107
--- src/name.c
+++ src/name.c
@@ -181,10 +181,19 @@
181181
" WHERE mtime<=julianday('%qz') AND type GLOB '%q'"
182182
" ORDER BY mtime DESC LIMIT 1",
183183
&zTag[4], zType);
184184
return rid;
185185
}
186
+
187
+ /* "parent:", as for parent branch. It returns the checkin of
188
+ the last checkin of the parent branch that has been merged in. */
189
+ if( memcmp(zTag, "pbranch:", 8)==0 ){
190
+ int branchRid = symbolic_name_to_rid(&zTag[8], zType);
191
+ if (branchRid == 0) return 0;
192
+ rid = get_parent_branch_rid(branchRid);
193
+ return rid;
194
+ }
186195
187196
/* "tag:" + symbolic-name */
188197
if( memcmp(zTag, "tag:", 4)==0 ){
189198
rid = db_int(0,
190199
"SELECT event.objid, max(event.mtime)"
@@ -1058,5 +1067,103 @@
10581067
*/
10591068
void test_phatoms_cmd(void){
10601069
db_find_and_open_repository(0,0);
10611070
describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
10621071
}
1072
+
1073
+
1074
+
1075
+/*
1076
+** It returns the checkin of the last checkin of the parent branch that has
1077
+** been merged in.
1078
+*/
1079
+int get_parent_branch_rid(int ridRequested){
1080
+ Stmt s;
1081
+ const char *branchName; /* Name of the branch requested at rid */
1082
+ const char *parentBranchName; /* Name of the parent branch */
1083
+ int rid;
1084
+
1085
+ /* Get the name of the current branch */
1086
+ branchName = db_text(0,
1087
+ "SELECT value FROM tagxref"
1088
+ " WHERE tagid=%d"
1089
+ " AND tagxref.tagtype>0"
1090
+ " AND rid=%d",
1091
+ TAG_BRANCH, ridRequested);
1092
+
1093
+ if ( !branchName )
1094
+ return 0;
1095
+
1096
+ /* Find the name of the branch this was forked from */
1097
+ db_prepare(&s,
1098
+ "SELECT pid, tagxref.value FROM plink JOIN tagxref"
1099
+ " WHERE cid=:rid"
1100
+ " AND isprim=1"
1101
+ " AND tagxref.tagid=%d"
1102
+ " AND tagxref.tagtype>0"
1103
+ " AND tagxref.rid=pid",
1104
+ TAG_BRANCH);
1105
+
1106
+ rid = ridRequested;
1107
+ while( rid > 0 ) {
1108
+ db_bind_int(&s, ":rid", rid);
1109
+ if ( db_step(&s) == SQLITE_ROW ) {
1110
+ rid = db_column_int(&s, 0);
1111
+ parentBranchName = db_column_text(&s, 1);
1112
+ if ( !parentBranchName ) {
1113
+ rid = 0;
1114
+ break;
1115
+ }
1116
+
1117
+ if ( fossil_strcmp(parentBranchName, branchName) ) {
1118
+ parentBranchName = fossil_strdup(parentBranchName);
1119
+ break;
1120
+ }
1121
+ }else{
1122
+ rid = 0;
1123
+ break;
1124
+ }
1125
+ db_reset(&s);
1126
+ }
1127
+ db_finalize(&s);
1128
+
1129
+ if (rid == 0)
1130
+ return 0;
1131
+
1132
+ /* Find the last checkin coming from the parent branch */
1133
+ db_prepare(&s,
1134
+ "SELECT pid, tagxref.value FROM plink JOIN tagxref"
1135
+ " WHERE cid=:rid"
1136
+ " AND tagxref.tagid=%d"
1137
+ " AND tagxref.tagtype>0"
1138
+ " AND tagxref.rid=pid ORDER BY isprim ASC",
1139
+ TAG_BRANCH);
1140
+
1141
+ rid = ridRequested;
1142
+ while( rid > 0 ) {
1143
+ db_bind_int(&s, ":rid", rid);
1144
+ int found = 0;
1145
+ while ( db_step(&s) == SQLITE_ROW ) {
1146
+ const char *branchNamePid; /* Branch name of the pid */
1147
+
1148
+ ++found;
1149
+ rid = db_column_int(&s, 0);
1150
+ branchNamePid = db_column_text(&s, 1);
1151
+ if ( !branchNamePid ) {
1152
+ break;
1153
+ }
1154
+ if ( fossil_strcmp(parentBranchName, branchNamePid)==0 ) {
1155
+ /* Found the last merge from the parent branch */
1156
+ db_finalize(&s);
1157
+ return rid;
1158
+ }
1159
+ }
1160
+
1161
+ if (found == 0) {
1162
+ break;
1163
+ }
1164
+ db_reset(&s);
1165
+ }
1166
+ db_finalize(&s);
1167
+
1168
+ return 0;
1169
+}
10631170
--- src/name.c
+++ src/name.c
@@ -181,10 +181,19 @@
181 " WHERE mtime<=julianday('%qz') AND type GLOB '%q'"
182 " ORDER BY mtime DESC LIMIT 1",
183 &zTag[4], zType);
184 return rid;
185 }
 
 
 
 
 
 
 
 
 
186
187 /* "tag:" + symbolic-name */
188 if( memcmp(zTag, "tag:", 4)==0 ){
189 rid = db_int(0,
190 "SELECT event.objid, max(event.mtime)"
@@ -1058,5 +1067,103 @@
1058 */
1059 void test_phatoms_cmd(void){
1060 db_find_and_open_repository(0,0);
1061 describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1062 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1063
--- src/name.c
+++ src/name.c
@@ -181,10 +181,19 @@
181 " WHERE mtime<=julianday('%qz') AND type GLOB '%q'"
182 " ORDER BY mtime DESC LIMIT 1",
183 &zTag[4], zType);
184 return rid;
185 }
186
187 /* "parent:", as for parent branch. It returns the checkin of
188 the last checkin of the parent branch that has been merged in. */
189 if( memcmp(zTag, "pbranch:", 8)==0 ){
190 int branchRid = symbolic_name_to_rid(&zTag[8], zType);
191 if (branchRid == 0) return 0;
192 rid = get_parent_branch_rid(branchRid);
193 return rid;
194 }
195
196 /* "tag:" + symbolic-name */
197 if( memcmp(zTag, "tag:", 4)==0 ){
198 rid = db_int(0,
199 "SELECT event.objid, max(event.mtime)"
@@ -1058,5 +1067,103 @@
1067 */
1068 void test_phatoms_cmd(void){
1069 db_find_and_open_repository(0,0);
1070 describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1071 }
1072
1073
1074
1075 /*
1076 ** It returns the checkin of the last checkin of the parent branch that has
1077 ** been merged in.
1078 */
1079 int get_parent_branch_rid(int ridRequested){
1080 Stmt s;
1081 const char *branchName; /* Name of the branch requested at rid */
1082 const char *parentBranchName; /* Name of the parent branch */
1083 int rid;
1084
1085 /* Get the name of the current branch */
1086 branchName = db_text(0,
1087 "SELECT value FROM tagxref"
1088 " WHERE tagid=%d"
1089 " AND tagxref.tagtype>0"
1090 " AND rid=%d",
1091 TAG_BRANCH, ridRequested);
1092
1093 if ( !branchName )
1094 return 0;
1095
1096 /* Find the name of the branch this was forked from */
1097 db_prepare(&s,
1098 "SELECT pid, tagxref.value FROM plink JOIN tagxref"
1099 " WHERE cid=:rid"
1100 " AND isprim=1"
1101 " AND tagxref.tagid=%d"
1102 " AND tagxref.tagtype>0"
1103 " AND tagxref.rid=pid",
1104 TAG_BRANCH);
1105
1106 rid = ridRequested;
1107 while( rid > 0 ) {
1108 db_bind_int(&s, ":rid", rid);
1109 if ( db_step(&s) == SQLITE_ROW ) {
1110 rid = db_column_int(&s, 0);
1111 parentBranchName = db_column_text(&s, 1);
1112 if ( !parentBranchName ) {
1113 rid = 0;
1114 break;
1115 }
1116
1117 if ( fossil_strcmp(parentBranchName, branchName) ) {
1118 parentBranchName = fossil_strdup(parentBranchName);
1119 break;
1120 }
1121 }else{
1122 rid = 0;
1123 break;
1124 }
1125 db_reset(&s);
1126 }
1127 db_finalize(&s);
1128
1129 if (rid == 0)
1130 return 0;
1131
1132 /* Find the last checkin coming from the parent branch */
1133 db_prepare(&s,
1134 "SELECT pid, tagxref.value FROM plink JOIN tagxref"
1135 " WHERE cid=:rid"
1136 " AND tagxref.tagid=%d"
1137 " AND tagxref.tagtype>0"
1138 " AND tagxref.rid=pid ORDER BY isprim ASC",
1139 TAG_BRANCH);
1140
1141 rid = ridRequested;
1142 while( rid > 0 ) {
1143 db_bind_int(&s, ":rid", rid);
1144 int found = 0;
1145 while ( db_step(&s) == SQLITE_ROW ) {
1146 const char *branchNamePid; /* Branch name of the pid */
1147
1148 ++found;
1149 rid = db_column_int(&s, 0);
1150 branchNamePid = db_column_text(&s, 1);
1151 if ( !branchNamePid ) {
1152 break;
1153 }
1154 if ( fossil_strcmp(parentBranchName, branchNamePid)==0 ) {
1155 /* Found the last merge from the parent branch */
1156 db_finalize(&s);
1157 return rid;
1158 }
1159 }
1160
1161 if (found == 0) {
1162 break;
1163 }
1164 db_reset(&s);
1165 }
1166 db_finalize(&s);
1167
1168 return 0;
1169 }
1170

Keyboard Shortcuts

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