/* ** COMMAND: branch ** ** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE? ** ** Run various subcommands to manage branches of the open repository or ** of the repository identified by the -R or --repository option. ** ** %fossil branch new BRANCH-NAME BASIS ?-bgcolor COLOR? ** ** Create a new branch BRANCH-NAME off of check-in BASIS. ** You can optionally give the branch a default color. ** ** %fossil branch list ** ** List all branches ** */ void branch_cmd(void){ int n; db_find_and_open_repository(1); if( g.argc<3 ){ usage("new|list ..."); } n = strlen(g.argv[2]); if( n>=2 && strncmp(g.argv[2],"new",n)==0 ){ branch_new(); }else if( n>=2 && strncmp(g.argv[2],"list",n)==0 ){ Stmt q; db_prepare(&q, "%s" " AND blob.rid IN (SELECT rid FROM tagxref" " WHERE tagid=%d AND tagtype==2 AND srcid!=0)" " ORDER BY event.mtime DESC", timeline_query_for_tty(), TAG_BRANCH ); print_timeline(&q, 2000); db_finalize(&q); }else{ fossil_panic("branch subcommand should be one of: " "new list"); } }
/* ** COMMAND: branch ** ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? ** ** Run various subcommands to manage branches of the open repository or ** of the repository identified by the -R or --repository option. ** ** %fossil branch new BRANCH-NAME BASIS ?--bgcolor COLOR? ?--private? ** ** Create a new branch BRANCH-NAME off of check-in BASIS. ** You can optionally give the branch a default color. The ** --private option makes the branch private. ** ** %fossil branch list ?-all | --closed? ** %fossil branch ls ?-all | --closed? ** ** List all branches. Use --all or --closed to list all branches ** or closed branches. The default is to show only open branches. ** ** Options: ** -R|--repository FILE Run commands on repository FILE */ void branch_cmd(void){ int n; const char *zCmd = "list"; db_find_and_open_repository(0, 0); if( g.argc<2 ){ usage("new|list|ls ..."); } if( g.argc>=3 ) zCmd = g.argv[2]; n = strlen(zCmd); if( strncmp(zCmd,"new",n)==0 ){ branch_new(); }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){ Stmt q; int vid; char *zCurrent = 0; int showAll = find_option("all",0,0)!=0; int showClosed = find_option("closed",0,0)!=0; if( g.localOpen ){ vid = db_lget_int("checkout", 0); zCurrent = db_text(0, "SELECT value FROM tagxref" " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH); } branch_prepare_list_query(&q, showAll?1:(showClosed?-1:0)); while( db_step(&q)==SQLITE_ROW ){ const char *zBr = db_column_text(&q, 0); int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0; fossil_print("%s%s\n", (isCur ? "* " : " "), zBr); } db_finalize(&q); }else{ fossil_panic("branch subcommand should be one of: " "new list ls"); } }
void octree_insert(octree_t* tree, point_t* point, int index) { if (tree->root == NULL) // Empty tree { octree_node_t* node = leaf_new(point, index); tree->root = node; ++tree->num_points; } else if (tree->root->type == OCTREE_LEAF_NODE) { point_t center = {.x = 0.5 * (tree->bbox.x1 + tree->bbox.x2), .y = 0.5 * (tree->bbox.y1 + tree->bbox.y2), .z = 0.5 * (tree->bbox.z1 + tree->bbox.z2)}; // The tree consists of a single node. octree_node_t* root = tree->root; // Does the given point already exist here? if (point_distance(&root->leaf_node.point, point) == 0.0) return; // We need to create a branch node here. octree_node_t* node = root; tree->root = branch_new(); int slot = find_slot(¢er, point); tree->root->branch_node.children[slot] = node; } // Now we proceed with the normal logic, given that the root node // is a branch node. ASSERT(tree->root->type == OCTREE_BRANCH_NODE); octree_node_t* node = tree->root; point_t center = {.x = 0.5 * (tree->bbox.x1 + tree->bbox.x2), .y = 0.5 * (tree->bbox.y1 + tree->bbox.y2), .z = 0.5 * (tree->bbox.z1 + tree->bbox.z2)}; real_t lx = tree->bbox.x2 - tree->bbox.x1; real_t ly = tree->bbox.y2 - tree->bbox.y1; real_t lz = tree->bbox.z2 - tree->bbox.z1; int slot = find_slot(¢er, point); static real_t xf[] = {-0.25, -0.25, -0.25, -0.25, +0.25, +0.25, +0.25, +0.25}; static real_t yf[] = {-0.25, -0.25, +0.25, +0.25, -0.25, -0.25, +0.25, +0.25}; static real_t zf[] = {-0.25, +0.25, -0.25, +0.25, -0.25, +0.25, -0.25, +0.25}; while ((node->branch_node.children[slot] != NULL) && (node->branch_node.children[slot]->type == OCTREE_BRANCH_NODE)) { node = node->branch_node.children[slot]; center.x += xf[slot]*lx; lx *= 0.5; center.y += yf[slot]*ly; ly *= 0.5; center.z += zf[slot]*lz; lz *= 0.5; slot = find_slot(¢er, point); } octree_node_t* leaf = node->branch_node.children[slot]; if (leaf == NULL) { // No leaf here, so we create a new one! leaf = leaf_new(point, index); node->branch_node.children[slot] = leaf; ++tree->num_points; } else { // Is the point already in this node? if (point_distance(&leaf->leaf_node.point, point) == 0.0) return; else { // We have to make a new branch. int old_slot, new_slot; do { node->branch_node.children[slot] = branch_new(); node = node->branch_node.children[slot]; center.x += xf[slot]*lx; lx *= 0.5; center.y += yf[slot]*ly; ly *= 0.5; center.z += zf[slot]*lz; lz *= 0.5; new_slot = find_slot(¢er, point); old_slot = find_slot(¢er, &leaf->leaf_node.point); } while (new_slot == old_slot); node->branch_node.children[old_slot] = leaf; octree_node_t* new_leaf = leaf_new(point, index); node->branch_node.children[new_slot] = new_leaf; ++tree->num_points; } } } void octree_delete(octree_t* tree, point_t* point, int index) { // FIXME } int octree_size(octree_t* tree) { return tree->num_points; } static void node_clear(octree_node_t* node) { if (node == NULL) { return; } else if (node->type == OCTREE_LEAF_NODE) { polymec_free(node); } else { ASSERT(node->type == OCTREE_BRANCH_NODE); for (int i = 0; i < 8; ++i) node_clear(node->branch_node.children[i]); } } void octree_clear(octree_t* tree) { node_clear(tree->root); tree->root = NULL; tree->num_points = 0; }