Fossil SCM
Allow fossil_find_nearest_fork to be used on repository that is not open.
Commit
97f976785dce535ea9b8efa1caa9e189ff3ea18d
Parent
10f5fc698679b59…
6 files changed
+2
-1
+2
-1
+1
-1
+1
-1
+27
-6
+27
-6
+2
-1
| --- src/descendants.c | ||
| +++ src/descendants.c | ||
| @@ -407,11 +407,12 @@ | ||
| 407 | 407 | db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql)); |
| 408 | 408 | } |
| 409 | 409 | blob_reset(&sql); |
| 410 | 410 | n = 0; |
| 411 | 411 | 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)) ){ | |
| 413 | 414 | const char *zId = db_column_text(&q, 1); |
| 414 | 415 | const char *zDate = db_column_text(&q, 2); |
| 415 | 416 | const char *zCom = db_column_text(&q, 3); |
| 416 | 417 | const char *zBr = db_column_text(&q, 7); |
| 417 | 418 | char *z; |
| 418 | 419 |
| --- 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 |
+2
-1
| --- src/descendants.c | ||
| +++ src/descendants.c | ||
| @@ -407,11 +407,12 @@ | ||
| 407 | 407 | db_prepare(&q, "%s ORDER BY event.mtime DESC", blob_sql_text(&sql)); |
| 408 | 408 | } |
| 409 | 409 | blob_reset(&sql); |
| 410 | 410 | n = 0; |
| 411 | 411 | 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)) ){ | |
| 413 | 414 | const char *zId = db_column_text(&q, 1); |
| 414 | 415 | const char *zDate = db_column_text(&q, 2); |
| 415 | 416 | const char *zCom = db_column_text(&q, 3); |
| 416 | 417 | const char *zBr = db_column_text(&q, 7); |
| 417 | 418 | char *z; |
| 418 | 419 |
| --- 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 @@ | ||
| 121 | 121 | " WHERE tx.rid=%d" |
| 122 | 122 | " AND tx.tagid=%d" |
| 123 | 123 | " AND tx.tagtype>0", |
| 124 | 124 | rid, TAG_CLOSED)){ |
| 125 | 125 | 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)) ){ | |
| 127 | 127 | fossil_print("%s\n", "fork"); |
| 128 | 128 | isFork = 1; |
| 129 | 129 | }else{ |
| 130 | 130 | fossil_print("%s\n", "open"); |
| 131 | 131 | } |
| 132 | 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) ){ |
| 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 @@ | ||
| 121 | 121 | " WHERE tx.rid=%d" |
| 122 | 122 | " AND tx.tagid=%d" |
| 123 | 123 | " AND tx.tagtype>0", |
| 124 | 124 | rid, TAG_CLOSED)){ |
| 125 | 125 | 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)) ){ | |
| 127 | 127 | fossil_print("%s\n", "fork"); |
| 128 | 128 | isFork = 1; |
| 129 | 129 | }else{ |
| 130 | 130 | fossil_print("%s\n", "open"); |
| 131 | 131 | } |
| 132 | 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) ){ |
| 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 @@ | ||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | /* Pick the most recent leaf that is (1) not equal to vid and (2) |
| 60 | 60 | ** has not already been merged into vid and (3) the leaf is not |
| 61 | 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. | |
| 62 | 64 | */ |
| 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, | |
| 65 | 72 | "SELECT leaf.rid" |
| 66 | 73 | " FROM leaf, event" |
| 67 | 74 | " 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, | |
| 70 | 84 | " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */ |
| 71 | 85 | " WHERE rid=leaf.rid" |
| 72 | 86 | " AND tagid=%d" |
| 73 | 87 | " AND tagtype>0)" |
| 74 | 88 | " AND (SELECT value FROM tagxref" /* Constraint (4) */ |
| 75 | 89 | " WHERE tagid=%d AND rid=%d AND tagtype>0) =" |
| 76 | 90 | " (SELECT value FROM tagxref" |
| 77 | 91 | " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)" |
| 78 | 92 | " ORDER BY event.mtime DESC LIMIT 1", |
| 79 | - vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH | |
| 93 | + TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH | |
| 80 | 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; | |
| 81 | 102 | } |
| 82 | 103 | |
| 83 | 104 | /* |
| 84 | 105 | ** COMMAND: merge |
| 85 | 106 | ** |
| @@ -196,11 +217,11 @@ | ||
| 196 | 217 | */ |
| 197 | 218 | Stmt q; |
| 198 | 219 | if( pickFlag || backoutFlag || integrateFlag){ |
| 199 | 220 | fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge"); |
| 200 | 221 | } |
| 201 | - mid = fossil_find_nearest_fork(vid); | |
| 222 | + mid = fossil_find_nearest_fork(vid, db_open_local(0)); | |
| 202 | 223 | if( mid==0 ){ |
| 203 | 224 | fossil_fatal("no unmerged forks of branch \"%s\"", |
| 204 | 225 | db_text(0, "SELECT value FROM tagxref" |
| 205 | 226 | " WHERE tagid=%d AND rid=%d AND tagtype>0", |
| 206 | 227 | TAG_BRANCH, vid) |
| 207 | 228 |
| --- 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 @@ | ||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | /* Pick the most recent leaf that is (1) not equal to vid and (2) |
| 60 | 60 | ** has not already been merged into vid and (3) the leaf is not |
| 61 | 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. | |
| 62 | 64 | */ |
| 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, | |
| 65 | 72 | "SELECT leaf.rid" |
| 66 | 73 | " FROM leaf, event" |
| 67 | 74 | " 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, | |
| 70 | 84 | " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */ |
| 71 | 85 | " WHERE rid=leaf.rid" |
| 72 | 86 | " AND tagid=%d" |
| 73 | 87 | " AND tagtype>0)" |
| 74 | 88 | " AND (SELECT value FROM tagxref" /* Constraint (4) */ |
| 75 | 89 | " WHERE tagid=%d AND rid=%d AND tagtype>0) =" |
| 76 | 90 | " (SELECT value FROM tagxref" |
| 77 | 91 | " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)" |
| 78 | 92 | " ORDER BY event.mtime DESC LIMIT 1", |
| 79 | - vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH | |
| 93 | + TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH | |
| 80 | 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; | |
| 81 | 102 | } |
| 82 | 103 | |
| 83 | 104 | /* |
| 84 | 105 | ** COMMAND: merge |
| 85 | 106 | ** |
| @@ -196,11 +217,11 @@ | ||
| 196 | 217 | */ |
| 197 | 218 | Stmt q; |
| 198 | 219 | if( pickFlag || backoutFlag || integrateFlag){ |
| 199 | 220 | fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge"); |
| 200 | 221 | } |
| 201 | - mid = fossil_find_nearest_fork(vid); | |
| 222 | + mid = fossil_find_nearest_fork(vid, db_open_local(0)); | |
| 202 | 223 | if( mid==0 ){ |
| 203 | 224 | fossil_fatal("no unmerged forks of branch \"%s\"", |
| 204 | 225 | db_text(0, "SELECT value FROM tagxref" |
| 205 | 226 | " WHERE tagid=%d AND rid=%d AND tagtype>0", |
| 206 | 227 | TAG_BRANCH, vid) |
| 207 | 228 |
| --- 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 |