26
lf;
27
commit_msg ::= data;
28
29
- file_change ::= file_clr | file_del | file_rnm | file_obm | file_inm;
29
+ file_change ::= file_clr
30
+ | file_del
31
+ | file_rnm
32
+ | file_cpy
33
+ | file_obm
34
+ | file_inm;
35
file_clr ::= 'deleteall' lf;
36
file_del ::= 'D' sp path_str lf;
37
file_rnm ::= 'R' sp path_str sp path_str lf;
38
+ file_cpy ::= 'C' sp path_str sp path_str lf;
39
file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf;
40
file_inm ::= 'M' sp mode sp 'inline' sp path_str lf
41
data;
629
avail_tree_entry = e;
630
}
631
632
+static struct tree_content *dup_tree_content(struct tree_content *s)
633
+{
634
+ struct tree_content *d;
635
+ struct tree_entry *a, *b;
636
+ unsigned int i;
637
+
638
+ if (!s)
639
+ return NULL;
640
+ d = new_tree_content(s->entry_count);
641
+ for (i = 0; i < s->entry_count; i++) {
642
+ a = s->entries[i];
643
+ b = new_tree_entry();
644
+ memcpy(b, a, sizeof(*a));
645
+ if (a->tree && is_null_sha1(b->versions[1].sha1))
646
+ b->tree = dup_tree_content(a->tree);
647
+ else
648
+ b->tree = NULL;
649
+ d->entries[i] = b;
650
+ }
651
+ d->entry_count = s->entry_count;
652
+ d->delta_depth = s->delta_depth;
653
+
654
+ return d;
655
+}
656
+
657
static void start_packfile(void)
658
{
659
static char tmpfile[PATH_MAX];
1304
return 1;
1305
}
1306
1307
+static int tree_content_get(
1308
+ struct tree_entry *root,
1309
+ const char *p,
1310
+ struct tree_entry *leaf)
1311
+{
1312
+ struct tree_content *t = root->tree;
1313
+ const char *slash1;
1314
+ unsigned int i, n;
1315
+ struct tree_entry *e;
1316
+
1317
+ slash1 = strchr(p, '/');
1318
+ if (slash1)
1319
+ n = slash1 - p;
1320
+ else
1321
+ n = strlen(p);
1322
+
1323
+ for (i = 0; i < t->entry_count; i++) {
1324
+ e = t->entries[i];
1325
+ if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) {
1326
+ if (!slash1) {
1327
+ memcpy(leaf, e, sizeof(*leaf));
1328
+ if (e->tree && is_null_sha1(e->versions[1].sha1))
1329
+ leaf->tree = dup_tree_content(e->tree);
1330
+ else
1331
+ leaf->tree = NULL;
1332
+ return 1;
1333
+ }
1334
+ if (!S_ISDIR(e->versions[1].mode))
1335
+ return 0;
1336
+ if (!e->tree)
1337
+ load_tree(e);
1338
+ return tree_content_get(e, slash1 + 1, leaf);
1339
+ }
1340
+ }
1341
+ return 0;
1342
+}
1343
+
1344
static int update_branch(struct branch *b)
1345
{
1346
static const char *msg = "fast-import";
1726
free(p_uq);
1727
}
1728
1661
-static void file_change_r(struct branch *b)
1729
+static void file_change_cr(struct branch *b, int rename)
1730
{
1731
const char *s, *d;
1732
char *s_uq, *d_uq;
1762
}
1763
1764
memset(&leaf, 0, sizeof(leaf));
1697
- tree_content_remove(&b->branch_tree, s, &leaf);
1765
+ if (rename)
1766
+ tree_content_remove(&b->branch_tree, s, &leaf);
1767
+ else
1768
+ tree_content_get(&b->branch_tree, s, &leaf);
1769
if (!leaf.versions[1].mode)
1770
die("Path %s not in branch", s);
1771
tree_content_set(&b->branch_tree, d,
1945
else if (!prefixcmp(command_buf.buf, "D "))
1946
file_change_d(b);
1947
else if (!prefixcmp(command_buf.buf, "R "))
1877
- file_change_r(b);
1948
+ file_change_cr(b, 1);
1949
+ else if (!prefixcmp(command_buf.buf, "C "))
1950
+ file_change_cr(b, 0);
1951
else if (!strcmp("deleteall", command_buf.buf))
1952
file_change_deleteall(b);
1953
else