Fossil SCM

Allow fossil_find_nearest_fork to be used on repository that is not open.

andybradford 2015-04-16 23:46 trunk
Commit 97f976785dce535ea9b8efa1caa9e189ff3ea18d
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407407
db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408408
}
409409
blob_reset(&sql);
410410
n = 0;
411411
while( db_step(&q)==SQLITE_ROW ){
412
- if( !showForks || fossil_find_nearest_fork(db_column_int(&q, 0)) ){
412
+ if( !showForks ||
413
+ fossil_find_nearest_fork(db_column_int(&q, 0), db_open_local(0)) ){
413414
const char *zId = db_column_text(&q, 1);
414415
const char *zDate = db_column_text(&q, 2);
415416
const char *zCom = db_column_text(&q, 3);
416417
const char *zBr = db_column_text(&q, 7);
417418
char *z;
418419
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407 db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408 }
409 blob_reset(&sql);
410 n = 0;
411 while( db_step(&q)==SQLITE_ROW ){
412 if( !showForks || fossil_find_nearest_fork(db_column_int(&q, 0)) ){
 
413 const char *zId = db_column_text(&q, 1);
414 const char *zDate = db_column_text(&q, 2);
415 const char *zCom = db_column_text(&q, 3);
416 const char *zBr = db_column_text(&q, 7);
417 char *z;
418
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407 db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408 }
409 blob_reset(&sql);
410 n = 0;
411 while( db_step(&q)==SQLITE_ROW ){
412 if( !showForks ||
413 fossil_find_nearest_fork(db_column_int(&q, 0), db_open_local(0)) ){
414 const char *zId = db_column_text(&q, 1);
415 const char *zDate = db_column_text(&q, 2);
416 const char *zCom = db_column_text(&q, 3);
417 const char *zBr = db_column_text(&q, 7);
418 char *z;
419
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407407
db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408408
}
409409
blob_reset(&sql);
410410
n = 0;
411411
while( db_step(&q)==SQLITE_ROW ){
412
- if( !showForks || fossil_find_nearest_fork(db_column_int(&q, 0)) ){
412
+ if( !showForks ||
413
+ fossil_find_nearest_fork(db_column_int(&q, 0), db_open_local(0)) ){
413414
const char *zId = db_column_text(&q, 1);
414415
const char *zDate = db_column_text(&q, 2);
415416
const char *zCom = db_column_text(&q, 3);
416417
const char *zBr = db_column_text(&q, 7);
417418
char *z;
418419
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407 db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408 }
409 blob_reset(&sql);
410 n = 0;
411 while( db_step(&q)==SQLITE_ROW ){
412 if( !showForks || fossil_find_nearest_fork(db_column_int(&q, 0)) ){
 
413 const char *zId = db_column_text(&q, 1);
414 const char *zDate = db_column_text(&q, 2);
415 const char *zCom = db_column_text(&q, 3);
416 const char *zBr = db_column_text(&q, 7);
417 char *z;
418
--- src/descendants.c
+++ src/descendants.c
@@ -407,11 +407,12 @@
407 db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql));
408 }
409 blob_reset(&sql);
410 n = 0;
411 while( db_step(&q)==SQLITE_ROW ){
412 if( !showForks ||
413 fossil_find_nearest_fork(db_column_int(&q, 0), db_open_local(0)) ){
414 const char *zId = db_column_text(&q, 1);
415 const char *zDate = db_column_text(&q, 2);
416 const char *zCom = db_column_text(&q, 3);
417 const char *zBr = db_column_text(&q, 7);
418 char *z;
419
+1 -1
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121121
" WHERE tx.rid=%d"
122122
" AND tx.tagid=%d"
123123
" AND tx.tagtype>0",
124124
rid, TAG_CLOSED)){
125125
fossil_print("%s\n", "closed");
126
- }else if( fossil_find_nearest_fork(rid) ){
126
+ }else if( fossil_find_nearest_fork(rid, db_open_local(0)) ){
127127
fossil_print("%s\n", "fork");
128128
isFork = 1;
129129
}else{
130130
fossil_print("%s\n", "open");
131131
}
132132
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121 " WHERE tx.rid=%d"
122 " AND tx.tagid=%d"
123 " AND tx.tagtype>0",
124 rid, TAG_CLOSED)){
125 fossil_print("%s\n", "closed");
126 }else if( fossil_find_nearest_fork(rid) ){
127 fossil_print("%s\n", "fork");
128 isFork = 1;
129 }else{
130 fossil_print("%s\n", "open");
131 }
132
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121 " WHERE tx.rid=%d"
122 " AND tx.tagid=%d"
123 " AND tx.tagtype>0",
124 rid, TAG_CLOSED)){
125 fossil_print("%s\n", "closed");
126 }else if( fossil_find_nearest_fork(rid, db_open_local(0)) ){
127 fossil_print("%s\n", "fork");
128 isFork = 1;
129 }else{
130 fossil_print("%s\n", "open");
131 }
132
+1 -1
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121121
" WHERE tx.rid=%d"
122122
" AND tx.tagid=%d"
123123
" AND tx.tagtype>0",
124124
rid, TAG_CLOSED)){
125125
fossil_print("%s\n", "closed");
126
- }else if( fossil_find_nearest_fork(rid) ){
126
+ }else if( fossil_find_nearest_fork(rid, db_open_local(0)) ){
127127
fossil_print("%s\n", "fork");
128128
isFork = 1;
129129
}else{
130130
fossil_print("%s\n", "open");
131131
}
132132
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121 " WHERE tx.rid=%d"
122 " AND tx.tagid=%d"
123 " AND tx.tagtype>0",
124 rid, TAG_CLOSED)){
125 fossil_print("%s\n", "closed");
126 }else if( fossil_find_nearest_fork(rid) ){
127 fossil_print("%s\n", "fork");
128 isFork = 1;
129 }else{
130 fossil_print("%s\n", "open");
131 }
132
--- src/info.c
+++ src/info.c
@@ -121,11 +121,11 @@
121 " WHERE tx.rid=%d"
122 " AND tx.tagid=%d"
123 " AND tx.tagtype>0",
124 rid, TAG_CLOSED)){
125 fossil_print("%s\n", "closed");
126 }else if( fossil_find_nearest_fork(rid, db_open_local(0)) ){
127 fossil_print("%s\n", "fork");
128 isFork = 1;
129 }else{
130 fossil_print("%s\n", "open");
131 }
132
+27 -6
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
5757
5858
5959
/* Pick the most recent leaf that is (1) not equal to vid and (2)
6060
** has not already been merged into vid and (3) the leaf is not
6161
** closed and (4) the leaf is in the same branch as vid.
62
+**
63
+** Set vmergeFlag to control whether the vmerge table is checked.
6264
*/
63
-int fossil_find_nearest_fork(int vid){
64
- return db_int(0,
65
+int fossil_find_nearest_fork(int vid, int vmergeFlag){
66
+ Blob sql;
67
+ Stmt q;
68
+ int rid = 0;
69
+
70
+ blob_zero(&sql);
71
+ blob_append_sql(&sql,
6572
"SELECT leaf.rid"
6673
" FROM leaf, event"
6774
" WHERE leaf.rid=event.objid"
68
- " AND leaf.rid!=%d" /* Constraint (1) */
69
- " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
75
+ " AND leaf.rid!=%d", /* Constraint (1) */
76
+ vid
77
+ );
78
+ if( vmergeFlag ){
79
+ blob_append_sql(&sql,
80
+ " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
81
+ );
82
+ }
83
+ blob_append_sql(&sql,
7084
" AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
7185
" WHERE rid=leaf.rid"
7286
" AND tagid=%d"
7387
" AND tagtype>0)"
7488
" AND (SELECT value FROM tagxref" /* Constraint (4) */
7589
" WHERE tagid=%d AND rid=%d AND tagtype>0) ="
7690
" (SELECT value FROM tagxref"
7791
" WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
7892
" ORDER BY event.mtime DESC LIMIT 1",
79
- vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
93
+ TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
8094
);
95
+ db_prepare(&q, "%s", blob_sql_text(&sql));
96
+ blob_reset(&sql);
97
+ if( db_step(&q)==SQLITE_ROW ){
98
+ rid = db_column_int(&q, 0);
99
+ }
100
+ db_finalize(&q);
101
+ return rid;
81102
}
82103
83104
/*
84105
** COMMAND: merge
85106
**
@@ -196,11 +217,11 @@
196217
*/
197218
Stmt q;
198219
if( pickFlag || backoutFlag || integrateFlag){
199220
fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
200221
}
201
- mid = fossil_find_nearest_fork(vid);
222
+ mid = fossil_find_nearest_fork(vid, db_open_local(0));
202223
if( mid==0 ){
203224
fossil_fatal("no unmerged forks of branch \"%s\"",
204225
db_text(0, "SELECT value FROM tagxref"
205226
" WHERE tagid=%d AND rid=%d AND tagtype>0",
206227
TAG_BRANCH, vid)
207228
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
57
58
59 /* Pick the most recent leaf that is (1) not equal to vid and (2)
60 ** has not already been merged into vid and (3) the leaf is not
61 ** closed and (4) the leaf is in the same branch as vid.
 
 
62 */
63 int fossil_find_nearest_fork(int vid){
64 return db_int(0,
 
 
 
 
 
65 "SELECT leaf.rid"
66 " FROM leaf, event"
67 " WHERE leaf.rid=event.objid"
68 " AND leaf.rid!=%d" /* Constraint (1) */
69 " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
 
 
 
 
 
 
 
70 " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
71 " WHERE rid=leaf.rid"
72 " AND tagid=%d"
73 " AND tagtype>0)"
74 " AND (SELECT value FROM tagxref" /* Constraint (4) */
75 " WHERE tagid=%d AND rid=%d AND tagtype>0) ="
76 " (SELECT value FROM tagxref"
77 " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
78 " ORDER BY event.mtime DESC LIMIT 1",
79 vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
80 );
 
 
 
 
 
 
 
81 }
82
83 /*
84 ** COMMAND: merge
85 **
@@ -196,11 +217,11 @@
196 */
197 Stmt q;
198 if( pickFlag || backoutFlag || integrateFlag){
199 fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
200 }
201 mid = fossil_find_nearest_fork(vid);
202 if( mid==0 ){
203 fossil_fatal("no unmerged forks of branch \"%s\"",
204 db_text(0, "SELECT value FROM tagxref"
205 " WHERE tagid=%d AND rid=%d AND tagtype>0",
206 TAG_BRANCH, vid)
207
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
57
58
59 /* Pick the most recent leaf that is (1) not equal to vid and (2)
60 ** has not already been merged into vid and (3) the leaf is not
61 ** closed and (4) the leaf is in the same branch as vid.
62 **
63 ** Set vmergeFlag to control whether the vmerge table is checked.
64 */
65 int fossil_find_nearest_fork(int vid, int vmergeFlag){
66 Blob sql;
67 Stmt q;
68 int rid = 0;
69
70 blob_zero(&sql);
71 blob_append_sql(&sql,
72 "SELECT leaf.rid"
73 " FROM leaf, event"
74 " WHERE leaf.rid=event.objid"
75 " AND leaf.rid!=%d", /* Constraint (1) */
76 vid
77 );
78 if( vmergeFlag ){
79 blob_append_sql(&sql,
80 " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
81 );
82 }
83 blob_append_sql(&sql,
84 " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
85 " WHERE rid=leaf.rid"
86 " AND tagid=%d"
87 " AND tagtype>0)"
88 " AND (SELECT value FROM tagxref" /* Constraint (4) */
89 " WHERE tagid=%d AND rid=%d AND tagtype>0) ="
90 " (SELECT value FROM tagxref"
91 " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
92 " ORDER BY event.mtime DESC LIMIT 1",
93 TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
94 );
95 db_prepare(&q, "%s", blob_sql_text(&sql));
96 blob_reset(&sql);
97 if( db_step(&q)==SQLITE_ROW ){
98 rid = db_column_int(&q, 0);
99 }
100 db_finalize(&q);
101 return rid;
102 }
103
104 /*
105 ** COMMAND: merge
106 **
@@ -196,11 +217,11 @@
217 */
218 Stmt q;
219 if( pickFlag || backoutFlag || integrateFlag){
220 fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
221 }
222 mid = fossil_find_nearest_fork(vid, db_open_local(0));
223 if( mid==0 ){
224 fossil_fatal("no unmerged forks of branch \"%s\"",
225 db_text(0, "SELECT value FROM tagxref"
226 " WHERE tagid=%d AND rid=%d AND tagtype>0",
227 TAG_BRANCH, vid)
228
+27 -6
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
5757
5858
5959
/* Pick the most recent leaf that is (1) not equal to vid and (2)
6060
** has not already been merged into vid and (3) the leaf is not
6161
** closed and (4) the leaf is in the same branch as vid.
62
+**
63
+** Set vmergeFlag to control whether the vmerge table is checked.
6264
*/
63
-int fossil_find_nearest_fork(int vid){
64
- return db_int(0,
65
+int fossil_find_nearest_fork(int vid, int vmergeFlag){
66
+ Blob sql;
67
+ Stmt q;
68
+ int rid = 0;
69
+
70
+ blob_zero(&sql);
71
+ blob_append_sql(&sql,
6572
"SELECT leaf.rid"
6673
" FROM leaf, event"
6774
" WHERE leaf.rid=event.objid"
68
- " AND leaf.rid!=%d" /* Constraint (1) */
69
- " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
75
+ " AND leaf.rid!=%d", /* Constraint (1) */
76
+ vid
77
+ );
78
+ if( vmergeFlag ){
79
+ blob_append_sql(&sql,
80
+ " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
81
+ );
82
+ }
83
+ blob_append_sql(&sql,
7084
" AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
7185
" WHERE rid=leaf.rid"
7286
" AND tagid=%d"
7387
" AND tagtype>0)"
7488
" AND (SELECT value FROM tagxref" /* Constraint (4) */
7589
" WHERE tagid=%d AND rid=%d AND tagtype>0) ="
7690
" (SELECT value FROM tagxref"
7791
" WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
7892
" ORDER BY event.mtime DESC LIMIT 1",
79
- vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
93
+ TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
8094
);
95
+ db_prepare(&q, "%s", blob_sql_text(&sql));
96
+ blob_reset(&sql);
97
+ if( db_step(&q)==SQLITE_ROW ){
98
+ rid = db_column_int(&q, 0);
99
+ }
100
+ db_finalize(&q);
101
+ return rid;
81102
}
82103
83104
/*
84105
** COMMAND: merge
85106
**
@@ -196,11 +217,11 @@
196217
*/
197218
Stmt q;
198219
if( pickFlag || backoutFlag || integrateFlag){
199220
fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
200221
}
201
- mid = fossil_find_nearest_fork(vid);
222
+ mid = fossil_find_nearest_fork(vid, db_open_local(0));
202223
if( mid==0 ){
203224
fossil_fatal("no unmerged forks of branch \"%s\"",
204225
db_text(0, "SELECT value FROM tagxref"
205226
" WHERE tagid=%d AND rid=%d AND tagtype>0",
206227
TAG_BRANCH, vid)
207228
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
57
58
59 /* Pick the most recent leaf that is (1) not equal to vid and (2)
60 ** has not already been merged into vid and (3) the leaf is not
61 ** closed and (4) the leaf is in the same branch as vid.
 
 
62 */
63 int fossil_find_nearest_fork(int vid){
64 return db_int(0,
 
 
 
 
 
65 "SELECT leaf.rid"
66 " FROM leaf, event"
67 " WHERE leaf.rid=event.objid"
68 " AND leaf.rid!=%d" /* Constraint (1) */
69 " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
 
 
 
 
 
 
 
70 " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
71 " WHERE rid=leaf.rid"
72 " AND tagid=%d"
73 " AND tagtype>0)"
74 " AND (SELECT value FROM tagxref" /* Constraint (4) */
75 " WHERE tagid=%d AND rid=%d AND tagtype>0) ="
76 " (SELECT value FROM tagxref"
77 " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
78 " ORDER BY event.mtime DESC LIMIT 1",
79 vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
80 );
 
 
 
 
 
 
 
81 }
82
83 /*
84 ** COMMAND: merge
85 **
@@ -196,11 +217,11 @@
196 */
197 Stmt q;
198 if( pickFlag || backoutFlag || integrateFlag){
199 fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
200 }
201 mid = fossil_find_nearest_fork(vid);
202 if( mid==0 ){
203 fossil_fatal("no unmerged forks of branch \"%s\"",
204 db_text(0, "SELECT value FROM tagxref"
205 " WHERE tagid=%d AND rid=%d AND tagtype>0",
206 TAG_BRANCH, vid)
207
--- src/merge.c
+++ src/merge.c
@@ -57,29 +57,50 @@
57
58
59 /* Pick the most recent leaf that is (1) not equal to vid and (2)
60 ** has not already been merged into vid and (3) the leaf is not
61 ** closed and (4) the leaf is in the same branch as vid.
62 **
63 ** Set vmergeFlag to control whether the vmerge table is checked.
64 */
65 int fossil_find_nearest_fork(int vid, int vmergeFlag){
66 Blob sql;
67 Stmt q;
68 int rid = 0;
69
70 blob_zero(&sql);
71 blob_append_sql(&sql,
72 "SELECT leaf.rid"
73 " FROM leaf, event"
74 " WHERE leaf.rid=event.objid"
75 " AND leaf.rid!=%d", /* Constraint (1) */
76 vid
77 );
78 if( vmergeFlag ){
79 blob_append_sql(&sql,
80 " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */
81 );
82 }
83 blob_append_sql(&sql,
84 " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */
85 " WHERE rid=leaf.rid"
86 " AND tagid=%d"
87 " AND tagtype>0)"
88 " AND (SELECT value FROM tagxref" /* Constraint (4) */
89 " WHERE tagid=%d AND rid=%d AND tagtype>0) ="
90 " (SELECT value FROM tagxref"
91 " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)"
92 " ORDER BY event.mtime DESC LIMIT 1",
93 TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH
94 );
95 db_prepare(&q, "%s", blob_sql_text(&sql));
96 blob_reset(&sql);
97 if( db_step(&q)==SQLITE_ROW ){
98 rid = db_column_int(&q, 0);
99 }
100 db_finalize(&q);
101 return rid;
102 }
103
104 /*
105 ** COMMAND: merge
106 **
@@ -196,11 +217,11 @@
217 */
218 Stmt q;
219 if( pickFlag || backoutFlag || integrateFlag){
220 fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge");
221 }
222 mid = fossil_find_nearest_fork(vid, db_open_local(0));
223 if( mid==0 ){
224 fossil_fatal("no unmerged forks of branch \"%s\"",
225 db_text(0, "SELECT value FROM tagxref"
226 " WHERE tagid=%d AND rid=%d AND tagtype>0",
227 TAG_BRANCH, vid)
228

Keyboard Shortcuts

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