static void handle_node(void) { if (node_ctx.propLength != LENGTH_UNKNOWN && node_ctx.propLength) read_props(); if (node_ctx.srcRev) node_ctx.srcMode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst); if (node_ctx.textLength != LENGTH_UNKNOWN && node_ctx.type != REPO_MODE_DIR) node_ctx.mark = next_blob_mark(); if (node_ctx.action == NODEACT_DELETE) { repo_delete(node_ctx.dst); } else if (node_ctx.action == NODEACT_CHANGE || node_ctx.action == NODEACT_REPLACE) { if (node_ctx.action == NODEACT_REPLACE && node_ctx.type == REPO_MODE_DIR) repo_replace(node_ctx.dst, node_ctx.mark); else if (node_ctx.propLength != LENGTH_UNKNOWN) repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark); else if (node_ctx.textLength != LENGTH_UNKNOWN) node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark); } else if (node_ctx.action == NODEACT_ADD) { if (node_ctx.srcRev && node_ctx.propLength != LENGTH_UNKNOWN) repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark); else if (node_ctx.srcRev && node_ctx.textLength != LENGTH_UNKNOWN) node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark); else if ((node_ctx.type == REPO_MODE_DIR && !node_ctx.srcRev) || node_ctx.textLength != LENGTH_UNKNOWN) repo_add(node_ctx.dst, node_ctx.type, node_ctx.mark); } if (node_ctx.propLength == LENGTH_UNKNOWN && node_ctx.srcMode) node_ctx.type = node_ctx.srcMode; if (node_ctx.mark) fast_export_blob(node_ctx.type, node_ctx.mark, node_ctx.textLength); else if (node_ctx.textLength != LENGTH_UNKNOWN) buffer_skip_bytes(node_ctx.textLength); }
static void handle_node(void) { const uint32_t type = node_ctx.type; const int have_props = node_ctx.propLength != LENGTH_UNKNOWN; const int have_text = node_ctx.text_length != -1; /* * Old text for this node: * NULL - directory or bug * empty_blob - empty * "<dataref>" - data retrievable from fast-import */ static const char *const empty_blob = "::empty::"; const char *old_data = NULL; uint32_t old_mode = REPO_MODE_BLB; if (node_ctx.action == NODEACT_DELETE) { if (have_text || have_props || node_ctx.srcRev) die("invalid dump: deletion node has " "copyfrom info, text, or properties"); repo_delete(node_ctx.dst.buf); return; } if (node_ctx.action == NODEACT_REPLACE) { repo_delete(node_ctx.dst.buf); node_ctx.action = NODEACT_ADD; } if (node_ctx.srcRev) { repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf); if (node_ctx.action == NODEACT_ADD) node_ctx.action = NODEACT_CHANGE; } if (have_text && type == REPO_MODE_DIR) die("invalid dump: directories cannot have text attached"); /* * Find old content (old_data) and decide on the new mode. */ if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) { if (type != REPO_MODE_DIR) die("invalid dump: root of tree is not a regular file"); old_data = NULL; } else if (node_ctx.action == NODEACT_CHANGE) { uint32_t mode; old_data = repo_read_path(node_ctx.dst.buf, &mode); if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR) die("invalid dump: cannot modify a directory into a file"); if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR) die("invalid dump: cannot modify a file into a directory"); node_ctx.type = mode; old_mode = mode; } else if (node_ctx.action == NODEACT_ADD) { if (type == REPO_MODE_DIR) old_data = NULL; else if (have_text) old_data = empty_blob; else die("invalid dump: adds node without text"); } else { die("invalid dump: Node-path block lacks Node-action"); } /* * Adjust mode to reflect properties. */ if (have_props) { if (!node_ctx.prop_delta) node_ctx.type = type; if (node_ctx.propLength) read_props(); } /* * Save the result. */ if (type == REPO_MODE_DIR) /* directories are not tracked. */ return; assert(old_data); if (old_data == empty_blob) /* For the fast_export_* functions, NULL means empty. */ old_data = NULL; if (!have_text) { fast_export_modify(node_ctx.dst.buf, node_ctx.type, old_data); return; } if (!node_ctx.text_delta) { fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline"); fast_export_data(node_ctx.type, node_ctx.text_length, &input); return; } fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline"); fast_export_blob_delta(node_ctx.type, old_mode, old_data, node_ctx.text_length, &input); }