| | @@ -53,10 +53,34 @@ |
| 53 | 53 | fossil_free(zCom); |
| 54 | 54 | } |
| 55 | 55 | db_finalize(&q); |
| 56 | 56 | } |
| 57 | 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 | +} |
| 58 | 82 | |
| 59 | 83 | /* |
| 60 | 84 | ** COMMAND: merge |
| 61 | 85 | ** |
| 62 | 86 | ** Usage: %fossil merge ?OPTIONS? ?VERSION? |
| | @@ -172,27 +196,11 @@ |
| 172 | 196 | */ |
| 173 | 197 | Stmt q; |
| 174 | 198 | if( pickFlag || backoutFlag || integrateFlag){ |
| 175 | 199 | fossil_fatal("cannot use --backout, --cherrypick or --integrate with a fork merge"); |
| 176 | 200 | } |
| 177 | | - mid = db_int(0, |
| 178 | | - "SELECT leaf.rid" |
| 179 | | - " FROM leaf, event" |
| 180 | | - " WHERE leaf.rid=event.objid" |
| 181 | | - " AND leaf.rid!=%d" /* Constraint (1) */ |
| 182 | | - " AND leaf.rid NOT IN (SELECT merge FROM vmerge)" /* Constraint (2) */ |
| 183 | | - " AND NOT EXISTS(SELECT 1 FROM tagxref" /* Constraint (3) */ |
| 184 | | - " WHERE rid=leaf.rid" |
| 185 | | - " AND tagid=%d" |
| 186 | | - " AND tagtype>0)" |
| 187 | | - " AND (SELECT value FROM tagxref" /* Constraint (4) */ |
| 188 | | - " WHERE tagid=%d AND rid=%d AND tagtype>0) =" |
| 189 | | - " (SELECT value FROM tagxref" |
| 190 | | - " WHERE tagid=%d AND rid=leaf.rid AND tagtype>0)" |
| 191 | | - " ORDER BY event.mtime DESC LIMIT 1", |
| 192 | | - vid, TAG_CLOSED, TAG_BRANCH, vid, TAG_BRANCH |
| 193 | | - ); |
| 201 | + mid = fossil_find_nearest_fork(vid); |
| 194 | 202 | if( mid==0 ){ |
| 195 | 203 | fossil_fatal("no unmerged forks of branch \"%s\"", |
| 196 | 204 | db_text(0, "SELECT value FROM tagxref" |
| 197 | 205 | " WHERE tagid=%d AND rid=%d AND tagtype>0", |
| 198 | 206 | TAG_BRANCH, vid) |
| 199 | 207 | |