201
uint32_t mark = 0;
202
const uint32_t type = node_ctx.type;
203
const int have_props = node_ctx.propLength != LENGTH_UNKNOWN;
204
+ const int have_text = node_ctx.textLength != LENGTH_UNKNOWN;
205
206
if (node_ctx.text_delta)
207
die("text deltas not supported");
207
- if (node_ctx.textLength != LENGTH_UNKNOWN)
208
+ if (have_text)
209
mark = next_blob_mark();
210
if (node_ctx.action == NODEACT_DELETE) {
210
- if (mark || have_props || node_ctx.srcRev)
211
+ if (have_text || have_props || node_ctx.srcRev)
212
die("invalid dump: deletion node has "
213
"copyfrom info, text, or properties");
214
return repo_delete(node_ctx.dst);
222
if (node_ctx.action == NODEACT_ADD)
223
node_ctx.action = NODEACT_CHANGE;
224
}
224
- if (mark && type == REPO_MODE_DIR)
225
+ if (have_text && type == REPO_MODE_DIR)
226
die("invalid dump: directories cannot have text attached");
227
+
228
+ /*
229
+ * Decide on the new content (mark) and mode (node_ctx.type).
230
+ */
231
if (node_ctx.action == NODEACT_CHANGE && !~*node_ctx.dst) {
232
if (type != REPO_MODE_DIR)
233
die("invalid dump: root of tree is not a regular file");
234
} else if (node_ctx.action == NODEACT_CHANGE) {
230
- uint32_t mode = repo_modify_path(node_ctx.dst, 0, mark);
235
+ uint32_t mode;
236
+ if (!have_text)
237
+ mark = repo_read_path(node_ctx.dst);
238
+ mode = repo_modify_path(node_ctx.dst, 0, 0);
239
if (!mode)
240
die("invalid dump: path to be modified is missing");
241
if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
244
die("invalid dump: cannot modify a file into a directory");
245
node_ctx.type = mode;
246
} else if (node_ctx.action == NODEACT_ADD) {
239
- if (!mark && type != REPO_MODE_DIR)
247
+ if (!have_text && type != REPO_MODE_DIR)
248
die("invalid dump: adds node without text");
241
- repo_add(node_ctx.dst, type, mark);
249
} else {
250
die("invalid dump: Node-path block lacks Node-action");
251
}
252
+
253
+ /*
254
+ * Adjust mode to reflect properties.
255
+ */
256
if (have_props) {
246
- const uint32_t old_mode = node_ctx.type;
257
if (!node_ctx.prop_delta)
258
node_ctx.type = type;
259
if (node_ctx.propLength)
260
read_props();
251
- if (node_ctx.type != old_mode)
252
- repo_modify_path(node_ctx.dst, node_ctx.type, mark);
261
}
254
- if (mark)
262
+
263
+ /*
264
+ * Save the result.
265
+ */
266
+ repo_add(node_ctx.dst, node_ctx.type, mark);
267
+ if (have_text)
268
fast_export_blob(node_ctx.type, mark,
269
node_ctx.textLength, &input);
270
}