| | @@ -27,10 +27,12 @@ |
| 27 | 27 | struct PathNode { |
| 28 | 28 | int rid; /* ID for this node */ |
| 29 | 29 | u8 fromIsParent; /* True if pFrom is the parent of rid */ |
| 30 | 30 | u8 isPrim; /* True if primary side of common ancestor */ |
| 31 | 31 | u8 isHidden; /* Abbreviate output in "fossil bisect ls" */ |
| 32 | + u8 nDelay; /* Delay this many steps before walking */ |
| 33 | + char *zBranch; /* Branch name for this node. Might be NULL */ |
| 32 | 34 | PathNode *pFrom; /* Node we came from */ |
| 33 | 35 | union { |
| 34 | 36 | PathNode *pPeer; /* List of nodes of the same generation */ |
| 35 | 37 | PathNode *pTo; /* Next on path from beginning to end */ |
| 36 | 38 | } u; |
| | @@ -45,10 +47,11 @@ |
| 45 | 47 | PathNode *pCurrent; /* Current generation of nodes */ |
| 46 | 48 | PathNode *pAll; /* All nodes */ |
| 47 | 49 | Bag seen; /* Nodes seen before */ |
| 48 | 50 | int nStep; /* Number of steps from first to last */ |
| 49 | 51 | int nNotHidden; /* Number of steps not counting hidden nodes */ |
| 52 | + u8 brCost; /* Extra cost for moving to a different branch */ |
| 50 | 53 | PathNode *pStart; /* Earliest node */ |
| 51 | 54 | PathNode *pEnd; /* Most recent */ |
| 52 | 55 | } path; |
| 53 | 56 | |
| 54 | 57 | /* |
| | @@ -76,10 +79,16 @@ |
| 76 | 79 | p = fossil_malloc( sizeof(*p) ); |
| 77 | 80 | memset(p, 0, sizeof(*p)); |
| 78 | 81 | p->rid = rid; |
| 79 | 82 | p->fromIsParent = isParent; |
| 80 | 83 | p->pFrom = pFrom; |
| 84 | + if( path.brCost ){ |
| 85 | + p->zBranch = branch_of_rid(rid); |
| 86 | + if( pFrom && fossil_strcmp(p->zBranch, pFrom->zBranch)!=0 ){ |
| 87 | + p->nDelay = path.brCost; |
| 88 | + } |
| 89 | + } |
| 81 | 90 | p->u.pPeer = path.pCurrent; |
| 82 | 91 | path.pCurrent = p; |
| 83 | 92 | p->pAll = path.pAll; |
| 84 | 93 | path.pAll = p; |
| 85 | 94 | bag_insert(&path.seen, rid); |
| | @@ -92,10 +101,11 @@ |
| 92 | 101 | void path_reset(void){ |
| 93 | 102 | PathNode *p; |
| 94 | 103 | while( path.pAll ){ |
| 95 | 104 | p = path.pAll; |
| 96 | 105 | path.pAll = p->pAll; |
| 106 | + fossil_free(p->zBranch); |
| 97 | 107 | fossil_free(p); |
| 98 | 108 | } |
| 99 | 109 | bag_clear(&path.seen); |
| 100 | 110 | memset(&path, 0, sizeof(path)); |
| 101 | 111 | } |
| | @@ -128,17 +138,20 @@ |
| 128 | 138 | PathNode *path_shortest( |
| 129 | 139 | int iFrom, /* Path starts here */ |
| 130 | 140 | int iTo, /* Path ends here */ |
| 131 | 141 | int directOnly, /* No merge links if true */ |
| 132 | 142 | int oneWayOnly, /* Parent->child only if true */ |
| 133 | | - Bag *pHidden /* Hidden nodes */ |
| 143 | + Bag *pHidden, /* Hidden nodes */ |
| 144 | + int branchCost /* Add extra codes to changing branches */ |
| 134 | 145 | ){ |
| 135 | 146 | Stmt s; |
| 136 | 147 | PathNode *pPrev; |
| 137 | 148 | PathNode *p; |
| 149 | + int nPriorPeer = 1; |
| 138 | 150 | |
| 139 | 151 | path_reset(); |
| 152 | + path.brCost = branchCost; |
| 140 | 153 | path.pStart = path_new_node(iFrom, 0, 0); |
| 141 | 154 | if( iTo==iFrom ){ |
| 142 | 155 | path.pEnd = path.pStart; |
| 143 | 156 | return path.pStart; |
| 144 | 157 | } |
| | @@ -162,14 +175,24 @@ |
| 162 | 175 | "UNION ALL " |
| 163 | 176 | "SELECT pid, 0 FROM plink WHERE cid=:pid" |
| 164 | 177 | ); |
| 165 | 178 | } |
| 166 | 179 | while( path.pCurrent ){ |
| 167 | | - path.nStep++; |
| 180 | + if( nPriorPeer ) path.nStep++; |
| 181 | + nPriorPeer = 0; |
| 168 | 182 | pPrev = path.pCurrent; |
| 169 | 183 | path.pCurrent = 0; |
| 170 | 184 | while( pPrev ){ |
| 185 | + if( pPrev->nDelay>0 && (nPriorPeer>0 || pPrev->u.pPeer!=0) ){ |
| 186 | + PathNode *pThis = pPrev; |
| 187 | + pPrev = pThis->u.pPeer; |
| 188 | + pThis->u.pPeer = path.pCurrent; |
| 189 | + path.pCurrent = pThis; |
| 190 | + pThis->nDelay--; |
| 191 | + continue; |
| 192 | + } |
| 193 | + nPriorPeer++; |
| 171 | 194 | db_bind_int(&s, ":pid", pPrev->rid); |
| 172 | 195 | while( db_step(&s)==SQLITE_ROW ){ |
| 173 | 196 | int cid = db_column_int(&s, 0); |
| 174 | 197 | int isParent = db_column_int(&s, 1); |
| 175 | 198 | if( bag_find(&path.seen, cid) ) continue; |
| | @@ -238,11 +261,11 @@ |
| 238 | 261 | int cid /* RID for check-in at the end of the path */ |
| 239 | 262 | ){ |
| 240 | 263 | PathNode *pPath; |
| 241 | 264 | int gen = 0; |
| 242 | 265 | Stmt ins; |
| 243 | | - pPath = path_shortest(cid, origid, 1, 0, 0); |
| 266 | + pPath = path_shortest(cid, origid, 1, 0, 0, 0); |
| 244 | 267 | db_multi_exec( |
| 245 | 268 | "CREATE TEMP TABLE IF NOT EXISTS ancestor(" |
| 246 | 269 | " rid INT UNIQUE," |
| 247 | 270 | " generation INTEGER PRIMARY KEY" |
| 248 | 271 | ");" |
| | @@ -273,18 +296,20 @@ |
| 273 | 296 | int iTo; |
| 274 | 297 | PathNode *p; |
| 275 | 298 | int n; |
| 276 | 299 | int directOnly; |
| 277 | 300 | int oneWay; |
| 301 | + const char *zBrCost; |
| 278 | 302 | |
| 279 | 303 | db_find_and_open_repository(0,0); |
| 280 | 304 | directOnly = find_option("no-merge",0,0)!=0; |
| 281 | 305 | oneWay = find_option("one-way",0,0)!=0; |
| 306 | + zBrCost = find_option("branch-cost",0,1); |
| 282 | 307 | if( g.argc!=4 ) usage("VERSION1 VERSION2"); |
| 283 | 308 | iFrom = name_to_rid(g.argv[2]); |
| 284 | 309 | iTo = name_to_rid(g.argv[3]); |
| 285 | | - p = path_shortest(iFrom, iTo, directOnly, oneWay, 0); |
| 310 | + p = path_shortest(iFrom, iTo, directOnly, oneWay, 0, atoi(zBrCost)); |
| 286 | 311 | if( p==0 ){ |
| 287 | 312 | fossil_fatal("no path from %s to %s", g.argv[1], g.argv[2]); |
| 288 | 313 | } |
| 289 | 314 | for(n=1, p=path.pStart; p; p=p->u.pTo, n++){ |
| 290 | 315 | char *z; |
| | @@ -453,11 +478,11 @@ |
| 453 | 478 | }else if(0==iTo){ |
| 454 | 479 | fossil_fatal("Invalid 'to' RID: 0"); |
| 455 | 480 | } |
| 456 | 481 | if( iFrom==iTo ) return; |
| 457 | 482 | path_reset(); |
| 458 | | - p = path_shortest(iFrom, iTo, 1, revOK==0, 0); |
| 483 | + p = path_shortest(iFrom, iTo, 1, revOK==0, 0, 0); |
| 459 | 484 | if( p==0 ) return; |
| 460 | 485 | path_reverse_path(); |
| 461 | 486 | db_prepare(&q1, |
| 462 | 487 | "SELECT pfnid, fnid FROM mlink" |
| 463 | 488 | " WHERE mid=:mid AND (pfnid>0 OR fid==0)" |
| 464 | 489 | |