[PATCH] Rewrite read-tree
Adds support for multiple ancestors, removes --emu23, much simplification. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Daniel Barkalow committed
Sep 5, 2005 at 02:04 UTC
ee6566e8d70da682ac4926dd8a67ac821b2c1743
2 files changed
+421
-804
read-tree.c
+421
-382
@@ -5,73 +5,291 @@
5
*/
6
#include "cache.h"
7
8
-static int stage = 0;
8
+#include "object.h"
9
+#include "tree.h"
10
+
11
+static int merge = 0;
12
static int update = 0;
13
11
-static int unpack_tree(unsigned char *sha1)
12
-{
13
- void *buffer;
14
- unsigned long size;
15
- int ret;
14
+static int head_idx = -1;
15
+static int merge_size = 0;
16
17
- buffer = read_object_with_reference(sha1, "tree", &size, NULL);
18
- if (!buffer)
19
- return -1;
20
- ret = read_tree(buffer, size, stage, NULL);
21
- free(buffer);
17
+static struct object_list *trees = NULL;
18
+
19
+static struct cache_entry df_conflict_entry = {
20
+};
21
+
22
+static struct tree_entry_list df_conflict_list = {
23
+ .name = NULL,
24
+ .next = &df_conflict_list
25
+};
26
+
27
+typedef int (*merge_fn_t)(struct cache_entry **src);
28
+
29
+static int entcmp(char *name1, int dir1, char *name2, int dir2)
30
+{
31
+ int len1 = strlen(name1);
32
+ int len2 = strlen(name2);
33
+ int len = len1 < len2 ? len1 : len2;
34
+ int ret = memcmp(name1, name2, len);
35
+ unsigned char c1, c2;
36
+ if (ret)
37
+ return ret;
38
+ c1 = name1[len];
39
+ c2 = name2[len];
40
+ if (!c1 && dir1)
41
+ c1 = '/';
42
+ if (!c2 && dir2)
43
+ c2 = '/';
44
+ ret = (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
45
+ if (c1 && c2 && !ret)
46
+ ret = len1 - len2;
47
return ret;
48
}
49
25
-static int path_matches(struct cache_entry *a, struct cache_entry *b)
50
+static int unpack_trees_rec(struct tree_entry_list **posns, int len,
51
+ const char *base, merge_fn_t fn, int *indpos)
52
{
27
- int len = ce_namelen(a);
28
- return ce_namelen(b) == len &&
29
- !memcmp(a->name, b->name, len);
53
+ int baselen = strlen(base);
54
+ int src_size = len + 1;
55
+ do {
56
+ int i;
57
+ char *first;
58
+ int firstdir = 0;
59
+ int pathlen;
60
+ unsigned ce_size;
61
+ struct tree_entry_list **subposns;
62
+ struct cache_entry **src;
63
+ int any_files = 0;
64
+ int any_dirs = 0;
65
+ char *cache_name;
66
+ int ce_stage;
67
+
68
+ /* Find the first name in the input. */
69
+
70
+ first = NULL;
71
+ cache_name = NULL;
72
+
73
+ /* Check the cache */
74
+ if (merge && *indpos < active_nr) {
75
+ /* This is a bit tricky: */
76
+ /* If the index has a subdirectory (with
77
+ * contents) as the first name, it'll get a
78
+ * filename like "foo/bar". But that's after
79
+ * "foo", so the entry in trees will get
80
+ * handled first, at which point we'll go into
81
+ * "foo", and deal with "bar" from the index,
82
+ * because the base will be "foo/". The only
83
+ * way we can actually have "foo/bar" first of
84
+ * all the things is if the trees don't
85
+ * contain "foo" at all, in which case we'll
86
+ * handle "foo/bar" without going into the
87
+ * directory, but that's fine (and will return
88
+ * an error anyway, with the added unknown
89
+ * file case.
90
+ */
91
+
92
+ cache_name = active_cache[*indpos]->name;
93
+ if (strlen(cache_name) > baselen &&
94
+ !memcmp(cache_name, base, baselen)) {
95
+ cache_name += baselen;
96
+ first = cache_name;
97
+ } else {
98
+ cache_name = NULL;
99
+ }
100
+ }
101
+
102
+ if (first)
103
+ printf("index %s\n", first);
104
+
105
+ for (i = 0; i < len; i++) {
106
+ if (!posns[i] || posns[i] == &df_conflict_list)
107
+ continue;
108
+ printf("%d %s\n", i + 1, posns[i]->name);
109
+ if (!first || entcmp(first, firstdir,
110
+ posns[i]->name,
111
+ posns[i]->directory) > 0) {
112
+ first = posns[i]->name;
113
+ firstdir = posns[i]->directory;
114
+ }
115
+ }
116
+ /* No name means we're done */
117
+ if (!first)
118
+ return 0;
119
+
120
+ pathlen = strlen(first);
121
+ ce_size = cache_entry_size(baselen + pathlen);
122
+
123
+ src = xmalloc(sizeof(struct cache_entry *) * src_size);
124
+ memset(src, 0, sizeof(struct cache_entry *) * src_size);
125
+
126
+ subposns = xmalloc(sizeof(struct tree_list_entry *) * len);
127
+ memset(subposns, 0, sizeof(struct tree_list_entry *) * len);
128
+
129
+ if (cache_name && !strcmp(cache_name, first)) {
130
+ any_files = 1;
131
+ src[0] = active_cache[*indpos];
132
+ remove_cache_entry_at(*indpos);
133
+ }
134
+
135
+ for (i = 0; i < len; i++) {
136
+ struct cache_entry *ce;
137
+
138
+ if (!posns[i] ||
139
+ (posns[i] != &df_conflict_list &&
140
+ strcmp(first, posns[i]->name))) {
141
+ continue;
142
+ }
143
+
144
+ if (posns[i] == &df_conflict_list) {
145
+ src[i + merge] = &df_conflict_entry;
146
+ continue;
147
+ }
148
+
149
+ if (posns[i]->directory) {
150
+ any_dirs = 1;
151
+ parse_tree(posns[i]->item.tree);
152
+ subposns[i] = posns[i]->item.tree->entries;
153
+ posns[i] = posns[i]->next;
154
+ src[i + merge] = &df_conflict_entry;
155
+ continue;
156
+ }
157
+
158
+ if (!merge)
159
+ ce_stage = 0;
160
+ else if (i + 1 < head_idx)
161
+ ce_stage = 1;
162
+ else if (i + 1 > head_idx)
163
+ ce_stage = 3;
164
+ else
165
+ ce_stage = 2;
166
+
167
+ ce = xmalloc(ce_size);
168
+ memset(ce, 0, ce_size);
169
+ ce->ce_mode = create_ce_mode(posns[i]->mode);
170
+ ce->ce_flags = create_ce_flags(baselen + pathlen,
171
+ ce_stage);
172
+ memcpy(ce->name, base, baselen);
173
+ memcpy(ce->name + baselen, first, pathlen + 1);
174
+
175
+ any_files = 1;
176
+
177
+ memcpy(ce->sha1, posns[i]->item.any->sha1, 20);
178
+ src[i + merge] = ce;
179
+ subposns[i] = &df_conflict_list;
180
+ posns[i] = posns[i]->next;
181
+ }
182
+ if (any_files) {
183
+ if (merge) {
184
+ int ret;
185
+
186
+ printf("%s:\n", first);
187
+ for (i = 0; i < src_size; i++) {
188
+ printf(" %d ", i);
189
+ if (src[i])
190
+ printf("%s\n", sha1_to_hex(src[i]->sha1));
191
+ else
192
+ printf("\n");
193
+ }
194
+
195
+ ret = fn(src);
196
+
197
+ printf("Added %d entries\n", ret);
198
+
199
+ *indpos += ret;
200
+ } else {
201
+ for (i = 0; i < src_size; i++) {
202
+ if (src[i]) {
203
+ add_cache_entry(src[i], ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ if (any_dirs) {
209
+ char *newbase = xmalloc(baselen + 2 + pathlen);
210
+ memcpy(newbase, base, baselen);
211
+ memcpy(newbase + baselen, first, pathlen);
212
+ newbase[baselen + pathlen] = '/';
213
+ newbase[baselen + pathlen + 1] = '\0';
214
+ if (unpack_trees_rec(subposns, len, newbase, fn,
215
+ indpos))
216
+ return -1;
217
+ }
218
+ free(subposns);
219
+ free(src);
220
+ } while (1);
221
}
222
32
-static int same(struct cache_entry *a, struct cache_entry *b)
223
+static void reject_merge(struct cache_entry *ce)
224
{
34
- return a->ce_mode == b->ce_mode &&
35
- !memcmp(a->sha1, b->sha1, 20);
225
+ die("Entry '%s' would be overwritten by merge. Cannot merge.",
226
+ ce->name);
227
}
228
229
+static void check_updates(struct cache_entry **src, int nr)
230
+{
231
+ static struct checkout state = {
232
+ .base_dir = "",
233
+ .force = 1,
234
+ .quiet = 1,
235
+ .refresh_cache = 1,
236
+ };
237
+ unsigned short mask = htons(CE_UPDATE);
238
+ while (nr--) {
239
+ struct cache_entry *ce = *src++;
240
+ if (!ce->ce_mode) {
241
+ if (update)
242
+ unlink(ce->name);
243
+ continue;
244
+ }
245
+ if (ce->ce_flags & mask) {
246
+ ce->ce_flags &= ~mask;
247
+ if (update)
248
+ checkout_entry(ce, &state);
249
+ }
250
+ }
251
+}
252
39
-/*
40
- * This removes all trivial merges that don't change the tree
41
- * and collapses them to state 0.
42
- */
43
-static struct cache_entry *merge_entries(struct cache_entry *a,
44
- struct cache_entry *b,
45
- struct cache_entry *c)
253
+static int unpack_trees(merge_fn_t fn)
254
{
47
- /*
48
- * Ok, all three entries describe the same
49
- * filename, but maybe the contents or file
50
- * mode have changed?
51
- *
52
- * The trivial cases end up being the ones where two
53
- * out of three files are the same:
54
- * - both destinations the same, trivially take either
55
- * - one of the destination versions hasn't changed,
56
- * take the other.
57
- *
58
- * The "all entries exactly the same" case falls out as
59
- * a special case of any of the "two same" cases.
60
- *
61
- * Here "a" is "original", and "b" and "c" are the two
62
- * trees we are merging.
63
- */
64
- if (a && b && c) {
65
- if (same(b,c))
66
- return c;
67
- if (same(a,b))
68
- return c;
69
- if (same(a,c))
70
- return b;
255
+ int indpos = 0;
256
+ unsigned len = object_list_length(trees);
257
+ struct tree_entry_list **posns =
258
+ xmalloc(len * sizeof(struct tree_entry_list *));
259
+ int i;
260
+ struct object_list *posn = trees;
261
+ merge_size = len;
262
+ for (i = 0; i < len; i++) {
263
+ posns[i] = ((struct tree *) posn->item)->entries;
264
+ posn = posn->next;
265
}
72
- return NULL;
266
+ if (unpack_trees_rec(posns, len, "", fn, &indpos))
267
+ return -1;
268
+
269
+ check_updates(active_cache, active_nr);
270
+ return 0;
271
}
272
273
+static int list_tree(unsigned char *sha1)
274
+{
275
+ struct tree *tree = parse_tree_indirect(sha1);
276
+ if (!tree)
277
+ return -1;
278
+ object_list_append(&tree->object, &trees);
279
+ return 0;
280
+}
281
+
282
+static int same(struct cache_entry *a, struct cache_entry *b)
283
+{
284
+ if (!!a != !!b)
285
+ return 0;
286
+ if (!a && !b)
287
+ return 1;
288
+ return a->ce_mode == b->ce_mode &&
289
+ !memcmp(a->sha1, b->sha1, 20);
290
+}
291
+
292
+
293
/*
294
* When a CE gets turned into an unmerged entry, we
295
* want it to be up-to-date
@@ -91,18 +309,7 @@ static void verify_uptodate(struct cache_entry *ce)
309
die("Entry '%s' not uptodate. Cannot merge.", ce->name);
310
}
311
94
-/*
95
- * If the old tree contained a CE that isn't even in the
96
- * result, that's always a problem, regardless of whether
97
- * it's up-to-date or not (ie it can be a file that we
98
- * have updated but not committed yet).
99
- */
100
-static void reject_merge(struct cache_entry *ce)
101
-{
102
- die("Entry '%s' would be overwritten by merge. Cannot merge.", ce->name);
103
-}
104
-
105
-static int merged_entry_internal(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst, int allow_dirty)
312
+static int merged_entry(struct cache_entry *merge, struct cache_entry *old)
313
{
314
merge->ce_flags |= htons(CE_UPDATE);
315
if (old) {
@@ -115,195 +322,129 @@ static int merged_entry_internal(struct cache_entry *merge, struct cache_entry *
322
*/
323
if (same(old, merge)) {
324
*merge = *old;
118
- } else if (!allow_dirty) {
325
+ } else {
326
verify_uptodate(old);
327
}
328
}
329
merge->ce_flags &= ~htons(CE_STAGEMASK);
123
- *dst++ = merge;
330
+ add_cache_entry(merge, ADD_CACHE_OK_TO_ADD);
331
return 1;
332
}
333
127
-static int merged_entry_allow_dirty(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst)
128
-{
129
- return merged_entry_internal(merge, old, dst, 1);
130
-}
131
-
132
-static int merged_entry(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst)
133
-{
134
- return merged_entry_internal(merge, old, dst, 0);
135
-}
136
-
137
-static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, struct cache_entry **dst)
334
+static int deleted_entry(struct cache_entry *ce, struct cache_entry *old)
335
{
336
if (old)
337
verify_uptodate(old);
338
ce->ce_mode = 0;
142
- *dst++ = ce;
339
+ add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
340
return 1;
341
}
342
146
-static int causes_df_conflict(struct cache_entry *ce, int stage,
147
- struct cache_entry **dst_,
148
- struct cache_entry **next_,
149
- int tail)
343
+static int keep_entry(struct cache_entry *ce)
344
{
151
- /* This is called during the merge operation and walking
152
- * the active_cache[] array is messy, because it is in the
153
- * middle of overlapping copy operation. The invariants
154
- * are:
155
- * (1) active_cache points at the first (zeroth) entry.
156
- * (2) up to dst pointer are resolved entries.
157
- * (3) from the next pointer (head-inclusive) to the tail
158
- * of the active_cache array have the remaining paths
159
- * to be processed. There can be a gap between dst
160
- * and next. Note that next is called "src" in the
161
- * merge_cache() function, and tail is the original
162
- * end of active_cache array when merge_cache() started.
163
- * (4) the path corresponding to *ce is not found in (2)
164
- * or (3). It is in the gap.
165
- *
166
- * active_cache -----......+++++++++++++.
167
- * ^dst ^next ^tail
168
- */
169
- int i, next, dst;
170
- const char *path = ce->name;
171
- int namelen = ce_namelen(ce);
172
-
173
- next = next_ - active_cache;
174
- dst = dst_ - active_cache;
175
-
176
- for (i = 0; i < tail; i++) {
177
- int entlen, len;
178
- const char *one, *two;
179
- if (dst <= i && i < next)
180
- continue;
181
- ce = active_cache[i];
182
- if (ce_stage(ce) != stage)
183
- continue;
184
- /* If ce->name is a prefix of path, then path is a file
185
- * that hangs underneath ce->name, which is bad.
186
- * If path is a prefix of ce->name, then it is the
187
- * other way around which also is bad.
188
- */
189
- entlen = ce_namelen(ce);
190
- if (namelen == entlen)
191
- continue;
192
- if (namelen < entlen) {
193
- len = namelen;
194
- one = path;
195
- two = ce->name;
196
- } else {
197
- len = entlen;
198
- one = ce->name;
199
- two = path;
200
- }
201
- if (memcmp(one, two, len))
202
- continue;
203
- if (two[len] == '/')
204
- return 1;
205
- }
206
- return 0;
345
+ add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
346
+ return 1;
347
}
348
209
-static int threeway_merge(struct cache_entry *stages[4],
210
- struct cache_entry **dst,
211
- struct cache_entry **next, int tail)
349
+static int threeway_merge(struct cache_entry **stages)
350
{
213
- struct cache_entry *old = stages[0];
214
- struct cache_entry *a = stages[1], *b = stages[2], *c = stages[3];
215
- struct cache_entry *merge;
351
+ struct cache_entry *index;
352
+ struct cache_entry *head;
353
+ struct cache_entry *remote = stages[head_idx + 1];
354
int count;
355
+ int head_match = 0;
356
+ int remote_match = 0;
357
218
- /* #5ALT */
219
- if (!a && b && c && same(b, c)) {
220
- if (old && !same(b, old))
221
- return -1;
222
- return merged_entry_allow_dirty(b, old, dst);
358
+ int df_conflict_head = 0;
359
+ int df_conflict_remote = 0;
360
+
361
+ int any_anc_missing = 0;
362
+ int i;
363
+
364
+ for (i = 1; i < head_idx; i++) {
365
+ if (!stages[i])
366
+ any_anc_missing = 1;
367
}
224
- /* #2ALT and #3ALT */
225
- if (!a && (!!b != !!c)) {
226
- /*
227
- * The reason we need to worry about directory/file
228
- * conflicts only in #2ALT and #3ALT case is this:
229
- *
230
- * (1) For all other cases that read-tree internally
231
- * resolves a path, we always have such a path in
232
- * *both* stage2 and stage3 when we begin.
233
- * Traditionally, the behaviour has been even
234
- * stricter and we did not resolve a path without
235
- * initially being in all of stage1, 2, and 3.
236
- *
237
- * (2) When read-tree finishes, all resolved paths (i.e.
238
- * the paths that are in stage0) must have come from
239
- * either stage2 or stage3. It is not possible to
240
- * have a stage0 path as a result of a merge if
241
- * neither stage2 nor stage3 had that path.
242
- *
243
- * (3) It is guaranteed that just after reading the
244
- * stages, each stage cannot have directory/file
245
- * conflicts on its own, because they are populated
246
- * by reading hierarchy of a tree. Combined with
247
- * (1) and (2) above, this means that no matter what
248
- * combination of paths we take from stage2 and
249
- * stage3 as a result of a merge, they cannot cause
250
- * a directory/file conflict situation (otherwise
251
- * the "guilty" path would have already had such a
252
- * conflict in the original stage, either stage2
253
- * or stage3). Although its stage2 is synthesized
254
- * by overlaying the current index on top of "our
255
- * head" tree, --emu23 case also has this guarantee,
256
- * by calling add_cache_entry() to create such stage2
257
- * entries.
258
- *
259
- * (4) Only #2ALT and #3ALT lack the guarantee (1).
260
- * They resolve paths that exist only in stage2
261
- * or stage3. The stage2 tree may have a file DF
262
- * while stage3 tree may have a file DF/DF. If
263
- * #2ALT and #3ALT rules happen to apply to both
264
- * of them, we would end up having DF (coming from
265
- * stage2) and DF/DF (from stage3) in the result.
266
- * When we attempt to resolve a path that exists
267
- * only in stage2, we need to make sure there is
268
- * no path that would conflict with it in stage3
269
- * and vice versa.
270
- */
271
- if (c) { /* #2ALT */
272
- if (!causes_df_conflict(c, 2, dst, next, tail) &&
273
- (!old || same(c, old)))
274
- return merged_entry_allow_dirty(c, old, dst);
275
- }
276
- else { /* #3ALT */
277
- if (!causes_df_conflict(b, 3, dst, next, tail) &&
278
- (!old || same(b, old)))
279
- return merged_entry_allow_dirty(b, old, dst);
368
+
369
+ index = stages[0];
370
+ head = stages[head_idx];
371
+
372
+ if (head == &df_conflict_entry) {
373
+ df_conflict_head = 1;
374
+ head = NULL;
375
+ }
376
+
377
+ if (remote == &df_conflict_entry) {
378
+ df_conflict_remote = 1;
379
+ remote = NULL;
380
+ }
381
+
382
+ /* First, if there's a #16 situation, note that to prevent #13
383
+ * and #14.
384
+ */
385
+ if (!same(remote, head)) {
386
+ for (i = 1; i < head_idx; i++) {
387
+ if (same(stages[i], head)) {
388
+ head_match = 1;
389
+ }
390
+ if (same(stages[i], remote)) {
391
+ remote_match = 1;
392
+ }
393
}
281
- /* otherwise we will apply the original rule */
394
}
283
- /* #14ALT */
284
- if (a && b && c && same(a, b) && !same(a, c)) {
285
- if (old && same(old, c))
286
- return merged_entry_allow_dirty(c, old, dst);
287
- /* otherwise the regular rule applies */
395
+
396
+ /* We start with cases where the index is allowed to match
397
+ * something other than the head: #14(ALT) and #2ALT, where it
398
+ * is permitted to match the result instead.
399
+ */
400
+ /* #14, #14ALT, #2ALT */
401
+ if (remote && !df_conflict_head && head_match && !remote_match) {
402
+ if (index && !same(index, remote) && !same(index, head))
403
+ reject_merge(index);
404
+ return merged_entry(remote, index);
405
}
406
/*
290
- * If we have an entry in the index cache ("old"), then we want
291
- * to make sure that it matches any entries in stage 2 ("first
292
- * branch", aka "b").
407
+ * If we have an entry in the index cache, then we want to
408
+ * make sure that it matches head.
409
*/
294
- if (old) {
295
- if (!b || !same(old, b))
296
- return -1;
410
+ if (index && !same(index, head)) {
411
+ reject_merge(index);
412
}
298
- merge = merge_entries(a, b, c);
299
- if (merge)
300
- return merged_entry(merge, old, dst);
301
- if (old)
302
- verify_uptodate(old);
413
+
414
+ if (head) {
415
+ /* #5ALT, #15 */
416
+ if (same(head, remote))
417
+ return merged_entry(head, index);
418
+ /* #13, #3ALT */
419
+ if (!df_conflict_remote && remote_match && !head_match)
420
+ return merged_entry(head, index);
421
+ }
422
+
423
+ /* #1 */
424
+ if (!head && !remote && any_anc_missing)
425
+ return 0;
426
+
427
+ /* Below are "no merge" cases, which require that the index be
428
+ * up-to-date to avoid the files getting overwritten with
429
+ * conflict resolution files.
430
+ */
431
+ if (index) {
432
+ verify_uptodate(index);
433
+ }
434
+
435
+ /* #2, #3, #4, #6, #7, #9, #11. */
436
count = 0;
304
- if (a) { *dst++ = a; count++; }
305
- if (b) { *dst++ = b; count++; }
306
- if (c) { *dst++ = c; count++; }
437
+ if (!head_match || !remote_match) {
438
+ for (i = 1; i < head_idx; i++) {
439
+ if (stages[i]) {
440
+ keep_entry(stages[i]);
441
+ count++;
442
+ break;
443
+ }
444
+ }
445
+ }
446
+ if (head) { count += keep_entry(head); }
447
+ if (remote) { count += keep_entry(remote); }
448
return count;
449
}
450
@@ -316,14 +457,14 @@ static int threeway_merge(struct cache_entry *stages[4],
457
* "carry forward" rule, please see <Documentation/git-read-tree.txt>.
458
*
459
*/
319
-static int twoway_merge(struct cache_entry **src, struct cache_entry **dst,
320
- struct cache_entry **next, int tail)
460
+static int twoway_merge(struct cache_entry **src)
461
{
462
struct cache_entry *current = src[0];
463
struct cache_entry *oldtree = src[1], *newtree = src[2];
464
325
- if (src[3])
326
- return -1;
465
+ if (merge_size != 2)
466
+ return error("Cannot do a twoway merge of %d trees\n",
467
+ merge_size);
468
469
if (current) {
470
if ((!oldtree && !newtree) || /* 4 and 5 */
@@ -334,78 +475,32 @@ static int twoway_merge(struct cache_entry **src, struct cache_entry **dst,
475
(oldtree && newtree &&
476
!same(oldtree, newtree) && /* 18 and 19*/
477
same(current, newtree))) {
337
- *dst++ = current;
338
- return 1;
478
+ return keep_entry(current);
479
}
480
else if (oldtree && !newtree && same(current, oldtree)) {
481
/* 10 or 11 */
342
- return deleted_entry(oldtree, current, dst);
482
+ return deleted_entry(oldtree, current);
483
}
484
else if (oldtree && newtree &&
485
same(current, oldtree) && !same(current, newtree)) {
486
/* 20 or 21 */
347
- return merged_entry(newtree, current, dst);
487
+ return merged_entry(newtree, current);
488
}
349
- else
489
+ else {
490
/* all other failures */
491
+ if (oldtree)
492
+ reject_merge(oldtree);
493
+ if (current)
494
+ reject_merge(current);
495
+ if (newtree)
496
+ reject_merge(newtree);
497
return -1;
498
+ }
499
}
500
else if (newtree)
354
- return merged_entry(newtree, current, dst);
501
+ return merged_entry(newtree, current);
502
else
356
- return deleted_entry(oldtree, current, dst);
357
-}
358
-
359
-/*
360
- * Two-way merge emulated with three-way merge.
361
- *
362
- * This treats "read-tree -m H M" by transforming it internally
363
- * into "read-tree -m H I+H M", where I+H is a tree that would
364
- * contain the contents of the current index file, overlayed on
365
- * top of H. Unlike the traditional two-way merge, this leaves
366
- * the stages in the resulting index file and lets the user resolve
367
- * the merge conflicts using standard tools for three-way merge.
368
- *
369
- * This function is just to set-up such an arrangement, and the
370
- * actual merge uses threeway_merge() function.
371
- */
372
-static void setup_emu23(void)
373
-{
374
- /* stage0 contains I, stage1 H, stage2 M.
375
- * move stage2 to stage3, and create stage2 entries
376
- * by scanning stage0 and stage1 entries.
377
- */
378
- int i, namelen, size;
379
- struct cache_entry *ce, *stage2;
380
-
381
- for (i = 0; i < active_nr; i++) {
382
- ce = active_cache[i];
383
- if (ce_stage(ce) != 2)
384
- continue;
385
- /* hoist them up to stage 3 */
386
- namelen = ce_namelen(ce);
387
- ce->ce_flags = create_ce_flags(namelen, 3);
388
- }
389
-
390
- for (i = 0; i < active_nr; i++) {
391
- ce = active_cache[i];
392
- if (ce_stage(ce) > 1)
393
- continue;
394
- namelen = ce_namelen(ce);
395
- size = cache_entry_size(namelen);
396
- stage2 = xmalloc(size);
397
- memcpy(stage2, ce, size);
398
- stage2->ce_flags = create_ce_flags(namelen, 2);
399
- if (add_cache_entry(stage2, ADD_CACHE_OK_TO_ADD) < 0)
400
- die("cannot merge index and our head tree");
401
-
402
- /* We are done with this name, so skip to next name */
403
- while (i < active_nr &&
404
- ce_namelen(active_cache[i]) == namelen &&
405
- !memcmp(active_cache[i]->name, ce->name, namelen))
406
- i++;
407
- i--; /* compensate for the loop control */
408
- }
503
+ return deleted_entry(oldtree, current);
504
}
505
506
/*
@@ -414,78 +509,21 @@ static void setup_emu23(void)
509
* The rule is:
510
* - take the stat information from stage0, take the data from stage1
511
*/
417
-static int oneway_merge(struct cache_entry **src, struct cache_entry **dst,
418
- struct cache_entry **next, int tail)
512
+static int oneway_merge(struct cache_entry **src)
513
{
514
struct cache_entry *old = src[0];
515
struct cache_entry *a = src[1];
516
423
- if (src[2] || src[3])
424
- return -1;
517
+ if (merge_size != 1)
518
+ return error("Cannot do a oneway merge of %d trees\n",
519
+ merge_size);
520
521
if (!a)
522
return 0;
523
if (old && same(old, a)) {
429
- *dst++ = old;
430
- return 1;
524
+ return keep_entry(old);
525
}
432
- return merged_entry(a, NULL, dst);
433
-}
434
-
435
-static void check_updates(struct cache_entry **src, int nr)
436
-{
437
- static struct checkout state = {
438
- .base_dir = "",
439
- .force = 1,
440
- .quiet = 1,
441
- .refresh_cache = 1,
442
- };
443
- unsigned short mask = htons(CE_UPDATE);
444
- while (nr--) {
445
- struct cache_entry *ce = *src++;
446
- if (!ce->ce_mode) {
447
- if (update)
448
- unlink(ce->name);
449
- continue;
450
- }
451
- if (ce->ce_flags & mask) {
452
- ce->ce_flags &= ~mask;
453
- if (update)
454
- checkout_entry(ce, &state);
455
- }
456
- }
457
-}
458
-
459
-typedef int (*merge_fn_t)(struct cache_entry **, struct cache_entry **, struct cache_entry **, int);
460
-
461
-static void merge_cache(struct cache_entry **src, int nr, merge_fn_t fn)
462
-{
463
- struct cache_entry **dst = src;
464
- int tail = nr;
465
-
466
- while (nr) {
467
- int entries;
468
- struct cache_entry *name, *ce, *stages[4] = { NULL, };
469
-
470
- name = ce = *src;
471
- for (;;) {
472
- int stage = ce_stage(ce);
473
- stages[stage] = ce;
474
- ce = *++src;
475
- active_nr--;
476
- if (!--nr)
477
- break;
478
- if (!path_matches(ce, name))
479
- break;
480
- }
481
-
482
- entries = fn(stages, dst, src, tail);
483
- if (entries < 0)
484
- reject_merge(name);
485
- dst += entries;
486
- active_nr += entries;
487
- }
488
- check_updates(active_cache, active_nr);
526
+ return merged_entry(a, NULL);
527
}
528
529
static int read_cache_unmerged(void)
@@ -516,8 +554,9 @@ static struct cache_file cache_file;
554
555
int main(int argc, char **argv)
556
{
519
- int i, newfd, merge, reset, emu23;
557
+ int i, newfd, reset, stage = 0;
558
unsigned char sha1[20];
559
+ merge_fn_t fn = NULL;
560
561
newfd = hold_index_file_for_update(&cache_file, get_index_file());
562
if (newfd < 0)
@@ -525,7 +564,6 @@ int main(int argc, char **argv)
564
565
merge = 0;
566
reset = 0;
528
- emu23 = 0;
567
for (i = 1; i < argc; i++) {
568
const char *arg = argv[i];
569
@@ -537,7 +575,7 @@ int main(int argc, char **argv)
575
576
/* This differs from "-m" in that we'll silently ignore unmerged entries */
577
if (!strcmp(arg, "--reset")) {
540
- if (stage || merge || emu23)
578
+ if (stage || merge)
579
usage(read_tree_usage);
580
reset = 1;
581
merge = 1;
@@ -546,9 +584,14 @@ int main(int argc, char **argv)
584
continue;
585
}
586
587
+ if (!strcmp(arg, "--head")) {
588
+ head_idx = stage - 1;
589
+ fn = threeway_merge;
590
+ }
591
+
592
/* "-m" stands for "merge", meaning we start in stage 1 */
593
if (!strcmp(arg, "-m")) {
551
- if (stage || merge || emu23)
594
+ if (stage || merge)
595
usage(read_tree_usage);
596
if (read_cache_unmerged())
597
die("you need to resolve your current index first");
@@ -557,45 +600,41 @@ int main(int argc, char **argv)
600
continue;
601
}
602
560
- /* "-emu23" uses 3-way merge logic to perform fast-forward */
561
- if (!strcmp(arg, "--emu23")) {
562
- if (stage || merge || emu23)
563
- usage(read_tree_usage);
564
- if (read_cache_unmerged())
565
- die("you need to resolve your current index first");
566
- merge = emu23 = stage = 1;
567
- continue;
568
- }
569
-
603
if (get_sha1(arg, sha1) < 0)
604
usage(read_tree_usage);
572
- if (stage > 3)
573
- usage(read_tree_usage);
574
- if (unpack_tree(sha1) < 0)
605
+ if (list_tree(sha1) < 0)
606
die("failed to unpack tree object %s", arg);
607
stage++;
608
}
609
if (update && !merge)
610
usage(read_tree_usage);
580
- if (merge) {
581
- static const merge_fn_t merge_function[] = {
582
- [1] = oneway_merge,
583
- [2] = twoway_merge,
584
- [3] = threeway_merge,
585
- };
586
- merge_fn_t fn;
587
-
588
- if (stage < 2 || stage > 4)
611
+ if (merge && !fn) {
612
+ if (stage < 2)
613
die("just how do you expect me to merge %d trees?", stage-1);
590
- if (emu23 && stage != 3)
591
- die("--emu23 takes only two trees");
592
- fn = merge_function[stage-1];
593
- if (stage == 3 && emu23) {
594
- setup_emu23();
595
- fn = merge_function[3];
614
+ switch (stage - 1) {
615
+ case 1:
616
+ fn = oneway_merge;
617
+ break;
618
+ case 2:
619
+ fn = twoway_merge;
620
+ break;
621
+ case 3:
622
+ fn = threeway_merge;
623
+ break;
624
+ default:
625
+ fn = threeway_merge;
626
+ break;
627
}
597
- merge_cache(active_cache, active_nr, fn);
628
}
629
+
630
+ if (head_idx < 0) {
631
+ if (stage - 1 >= 3)
632
+ head_idx = stage - 2;
633
+ else
634
+ head_idx = 1;
635
+ }
636
+
637
+ unpack_trees(fn);
638
if (write_cache(newfd, active_cache, active_nr) ||
639
commit_index_file(&cache_file))
640
die("unable to write new index file");
t/t1005-read-tree-m-2way-emu23.sh
deleted
-422
@@ -1,422 +0,0 @@
1
-#!/bin/sh
2
-#
3
-# Copyright (c) 2005 Junio C Hamano
4
-#
5
-
6
-test_description='Two way merge with read-tree --emu23 $H $M
7
-
8
-This test tries two-way merge (aka fast forward with carry forward).
9
-
10
-There is the head (called H) and another commit (called M), which is
11
-simply ahead of H. The index and the work tree contains a state that
12
-is derived from H, but may also have local changes. This test checks
13
-all the combinations described in the two-tree merge "carry forward"
14
-rules, found in <Documentation/git-rev-tree.txt>.
15
-
16
-In the test, these paths are used:
17
- bozbar - in H, stays in M, modified from bozbar to gnusto
18
- frotz - not in H added in M
19
- nitfol - in H, stays in M unmodified
20
- rezrov - in H, deleted in M
21
- yomin - not in H nor M
22
-'
23
-. ./test-lib.sh
24
-
25
-read_tree_twoway () {
26
- git-read-tree --emu23 "$1" "$2" &&
27
- git-ls-files --stage &&
28
- git-merge-index git-merge-one-file -a &&
29
- git-ls-files --stage
30
-}
31
-
32
-_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
33
-_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
34
-compare_change () {
35
- sed -n >current \
36
- -e '/^--- /d; /^+++ /d; /^@@ /d;' \
37
- -e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \
38
- "$1"
39
- diff -u expected current
40
-}
41
-
42
-check_cache_at () {
43
- clean_if_empty=`git-diff-files "$1"`
44
- case "$clean_if_empty" in
45
- '') echo "$1: clean" ;;
46
- ?*) echo "$1: dirty" ;;
47
- esac
48
- case "$2,$clean_if_empty" in
49
- clean,) : ;;
50
- clean,?*) false ;;
51
- dirty,) false ;;
52
- dirty,?*) : ;;
53
- esac
54
-}
55
-
56
-check_stages () {
57
- cat >expected_stages
58
- git-ls-files --stage | sed -e "s/ $_x40 / X /" >current_stages
59
- diff -u expected_stages current_stages
60
-}
61
-
62
-cat >bozbar-old <<\EOF
63
-This is a sample file used in two-way fast forward merge
64
-tests. Its second line ends with a magic word bozbar
65
-which will be modified by the merged head to gnusto.
66
-It has some extra lines so that external tools can
67
-successfully merge independent changes made to later
68
-lines (such as this one), avoiding line conflicts.
69
-EOF
70
-
71
-sed -e 's/bozbar/gnusto (earlier bozbar)/' bozbar-old >bozbar-new
72
-
73
-test_expect_success \
74
- setup \
75
- 'echo frotz >frotz &&
76
- echo nitfol >nitfol &&
77
- cat bozbar-old >bozbar &&
78
- echo rezrov >rezrov &&
79
- echo yomin >yomin &&
80
- git-update-index --add nitfol bozbar rezrov &&
81
- treeH=`git-write-tree` &&
82
- echo treeH $treeH &&
83
- git-ls-tree $treeH &&
84
-
85
- cat bozbar-new >bozbar &&
86
- git-update-index --add frotz bozbar --force-remove rezrov &&
87
- git-ls-files --stage >M.out &&
88
- treeM=`git-write-tree` &&
89
- echo treeM $treeM &&
90
- git-ls-tree $treeM &&
91
- git-diff-tree $treeH $treeM'
92
-
93
-# "read-tree -m H I+H M" but I is empty so this is "read-tree -m H H M".
94
-#
95
-# bozbar [O && A && B && O==A && O!=B (#14) ==> B] take M by read-tree
96
-# frotz [!O && !A && B (#2) ==> B] take M by read-tree
97
-# nitfol [O && A && B && O==A && O==B (#15) ==> B] take M by read-tree
98
-# rezrov [O && A && !B && O==A (#10) ==> no merge] removed by script
99
-#
100
-# Earlier one did not have #2ALT so taking M was done by the script,
101
-# which also updated the work tree and making frotz clean. With #2ALT,
102
-# this is resolved by read-tree itself and the path is left dirty
103
-# because we are not testing "read-tree -u --emu23".
104
-test_expect_success \
105
- '1, 2, 3 - no carry forward' \
106
- 'rm -f .git/index &&
107
- read_tree_twoway $treeH $treeM &&
108
- git-ls-files --stage >1-3.out &&
109
- diff -u M.out 1-3.out &&
110
- check_cache_at bozbar dirty &&
111
- check_cache_at frotz dirty && # same as pure 2-way again.
112
- check_cache_at nitfol dirty'
113
-
114
-echo '+100644 X 0 yomin' >expected
115
-
116
-test_expect_success \
117
- '4 - carry forward local addition.' \
118
- 'rm -f .git/index &&
119
- git-read-tree $treeH &&
120
- git-checkout-index -u -f -q -a &&
121
- git-update-index --add yomin &&
122
- read_tree_twoway $treeH $treeM &&
123
- git-ls-files --stage >4.out || return 1
124
- diff -u M.out 4.out >4diff.out
125
- compare_change 4diff.out expected &&
126
- check_cache_at yomin clean'
127
-
128
-# "read-tree -m H I+H M" where !H && !M; so (I+H) not being up-to-date
129
-# should not matter. Thanks to #3ALT, this is now possible.
130
-test_expect_success \
131
- '5 - carry forward local addition.' \
132
- 'rm -f .git/index &&
133
- git-read-tree $treeH &&
134
- git-checkout-index -u -f -q -a &&
135
- echo yomin >yomin &&
136
- git-update-index --add yomin &&
137
- echo yomin yomin >yomin &&
138
- read_tree_twoway $treeH $treeM &&
139
- git-ls-files --stage >5.out || return 1
140
- diff -u M.out 5.out >5diff.out
141
- compare_change 5diff.out expected &&
142
- check_cache_at yomin dirty'
143
-
144
-# "read-tree -m H I+H M" where !H && M && (I+H) == M, so this should
145
-# succeed (even the entry is clean), now thanks to #5ALT.
146
-test_expect_success \
147
- '6 - local addition already has the same.' \
148
- 'rm -f .git/index &&
149
- git-read-tree $treeH &&
150
- git-checkout-index -u -f -q -a &&
151
- git-update-index --add frotz &&
152
- read_tree_twoway $treeH $treeM &&
153
- git-ls-files --stage >6.out &&
154
- diff -u M.out 6.out &&
155
- check_cache_at frotz clean'
156
-
157
-# Exactly the same pattern as above but with dirty cache. This also
158
-# should succeed, now thanks to #5ALT.
159
-test_expect_success \
160
- '7 - local addition already has the same.' \
161
- 'rm -f .git/index &&
162
- git-read-tree $treeH &&
163
- git-checkout-index -u -f -q -a &&
164
- echo frotz >frotz &&
165
- git-update-index --add frotz &&
166
- echo frotz frotz >frotz &&
167
- read_tree_twoway $treeH $treeM &&
168
- git-ls-files --stage >7.out &&
169
- diff -u M.out 7.out &&
170
- check_cache_at frotz dirty'
171
-
172
-test_expect_success \
173
- '8 - conflicting addition.' \
174
- 'rm -f .git/index &&
175
- git-read-tree $treeH &&
176
- git-checkout-index -u -f -q -a &&
177
- echo frotz frotz >frotz &&
178
- git-update-index --add frotz &&
179
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
180
-
181
-test_expect_success \
182
- '9 - conflicting addition.' \
183
- 'rm -f .git/index &&
184
- git-read-tree $treeH &&
185
- git-checkout-index -u -f -q -a &&
186
- echo frotz frotz >frotz &&
187
- git-update-index --add frotz &&
188
- echo frotz >frotz &&
189
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
190
-
191
-test_expect_success \
192
- '10 - path removed.' \
193
- 'rm -f .git/index &&
194
- git-read-tree $treeH &&
195
- git-checkout-index -u -f -q -a &&
196
- echo rezrov >rezrov &&
197
- git-update-index --add rezrov &&
198
- read_tree_twoway $treeH $treeM &&
199
- git-ls-files --stage >10.out &&
200
- diff -u M.out 10.out'
201
-
202
-test_expect_success \
203
- '11 - dirty path removed.' \
204
- 'rm -f .git/index &&
205
- git-read-tree $treeH &&
206
- git-checkout-index -u -f -q -a &&
207
- echo rezrov >rezrov &&
208
- git-update-index --add rezrov &&
209
- echo rezrov rezrov >rezrov &&
210
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
211
-
212
-test_expect_success \
213
- '12 - unmatching local changes being removed.' \
214
- 'rm -f .git/index &&
215
- git-read-tree $treeH &&
216
- git-checkout-index -u -f -q -a &&
217
- echo rezrov rezrov >rezrov &&
218
- git-update-index --add rezrov &&
219
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
220
-
221
-test_expect_success \
222
- '13 - unmatching local changes being removed.' \
223
- 'rm -f .git/index &&
224
- git-read-tree $treeH &&
225
- git-checkout-index -u -f -q -a &&
226
- echo rezrov rezrov >rezrov &&
227
- git-update-index --add rezrov &&
228
- echo rezrov >rezrov &&
229
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
230
-
231
-cat >expected <<EOF
232
--100644 X 0 nitfol
233
-+100644 X 0 nitfol
234
-EOF
235
-
236
-test_expect_success \
237
- '14 - unchanged in two heads.' \
238
- 'rm -f .git/index &&
239
- git-read-tree $treeH &&
240
- git-checkout-index -u -f -q -a &&
241
- echo nitfol nitfol >nitfol &&
242
- git-update-index --add nitfol &&
243
- read_tree_twoway $treeH $treeM &&
244
- git-ls-files --stage >14.out || return 1
245
- diff -u M.out 14.out >14diff.out
246
- compare_change 14diff.out expected &&
247
- check_cache_at nitfol clean'
248
-
249
-test_expect_success \
250
- '15 - unchanged in two heads.' \
251
- 'rm -f .git/index &&
252
- git-read-tree $treeH &&
253
- git-checkout-index -u -f -q -a &&
254
- echo nitfol nitfol >nitfol &&
255
- git-update-index --add nitfol &&
256
- echo nitfol nitfol nitfol >nitfol &&
257
- read_tree_twoway $treeH $treeM &&
258
- git-ls-files --stage >15.out || return 1
259
- diff -u M.out 15.out >15diff.out
260
- compare_change 15diff.out expected &&
261
- check_cache_at nitfol dirty'
262
-
263
-# This is different from straight 2-way merge in that it leaves
264
-# three stages of bozbar in the index file without failing, so
265
-# the user can run git-diff-stages to examine the situation.
266
-# With #2ALT, frotz is resolved internally.
267
-test_expect_success \
268
- '16 - conflicting local change.' \
269
- 'rm -f .git/index &&
270
- git-read-tree $treeH &&
271
- git-checkout-index -u -f -q -a &&
272
- echo bozbar bozbar >bozbar &&
273
- git-update-index --add bozbar &&
274
- git-read-tree --emu23 $treeH $treeM &&
275
- check_stages' <<\EOF
276
-100644 X 1 bozbar
277
-100644 X 2 bozbar
278
-100644 X 3 bozbar
279
-100644 X 0 frotz
280
-100644 X 0 nitfol
281
-100644 X 1 rezrov
282
-100644 X 2 rezrov
283
-EOF
284
-
285
-test_expect_success \
286
- '17 - conflicting local change.' \
287
- 'rm -f .git/index &&
288
- git-read-tree $treeH &&
289
- git-checkout-index -u -f -q -a &&
290
- echo bozbar bozbar >bozbar &&
291
- git-update-index --add bozbar &&
292
- echo bozbar bozbar bozbar >bozbar &&
293
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
294
-
295
-test_expect_success \
296
- '18 - local change already having a good result.' \
297
- 'rm -f .git/index &&
298
- git-read-tree $treeH &&
299
- git-checkout-index -u -f -q -a &&
300
- cat bozbar-new >bozbar &&
301
- git-update-index --add bozbar &&
302
- read_tree_twoway $treeH $treeM &&
303
- git-ls-files --stage >18.out &&
304
- diff -u M.out 18.out &&
305
- check_cache_at bozbar clean'
306
-
307
-test_expect_success \
308
- '19 - local change already having a good result, further modified.' \
309
- 'rm -f .git/index &&
310
- git-read-tree $treeH &&
311
- git-checkout-index -u -f -q -a &&
312
- cat bozbar-new >bozbar &&
313
- git-update-index --add bozbar &&
314
- echo gnusto gnusto >bozbar &&
315
- read_tree_twoway $treeH $treeM &&
316
- git-ls-files --stage >19.out &&
317
- diff -u M.out 19.out &&
318
- check_cache_at bozbar dirty'
319
-
320
-test_expect_success \
321
- '20 - no local change, use new tree.' \
322
- 'rm -f .git/index &&
323
- git-read-tree $treeH &&
324
- git-checkout-index -u -f -q -a &&
325
- cat bozbar-old >bozbar &&
326
- git-update-index --add bozbar &&
327
- read_tree_twoway $treeH $treeM &&
328
- git-ls-files --stage >20.out &&
329
- diff -u M.out 20.out &&
330
- check_cache_at bozbar dirty'
331
-
332
-test_expect_success \
333
- '21 - no local change, dirty cache.' \
334
- 'rm -f .git/index &&
335
- git-read-tree $treeH &&
336
- git-checkout-index -u -f -q -a &&
337
- cat bozbar-old >bozbar &&
338
- git-update-index --add bozbar &&
339
- echo gnusto gnusto >bozbar &&
340
- if read_tree_twoway $treeH $treeM; then false; else :; fi'
341
-
342
-echo '-100644 X 0 bozbar
343
-+100644 X 0 bozbar' >expected
344
-
345
-# This fails with straight two-way fast forward, but emu23
346
-# can merge them.
347
-test_expect_success \
348
- '22 - local change cache updated.' \
349
- 'rm -f .git/index &&
350
- git-read-tree $treeH &&
351
- git-checkout-index -u -f -q -a &&
352
- sed -e "s/such as/SUCH AS/" bozbar-old >bozbar &&
353
- git-update-index --add bozbar &&
354
- read_tree_twoway $treeH $treeM &&
355
- git-ls-files --stage >22.out || return 1
356
- diff -u M.out 22.out >22diff.out
357
- compare_change 22diff.out &&
358
- check_cache_at bozbar clean'
359
-
360
-# Also make sure we did not break DF vs DF/DF case.
361
-test_expect_success \
362
- 'DF vs DF/DF case setup.' \
363
- 'rm -f .git/index &&
364
- echo DF >DF &&
365
- git-update-index --add DF &&
366
- treeDF=`git-write-tree` &&
367
- echo treeDF $treeDF &&
368
- git-ls-tree $treeDF &&
369
- git-ls-files --stage >DF.out
370
-
371
- rm -f DF &&
372
- mkdir DF &&
373
- echo DF/DF >DF/DF &&
374
- git-update-index --add --remove DF DF/DF &&
375
- treeDFDF=`git-write-tree` &&
376
- echo treeDFDF $treeDFDF &&
377
- git-ls-tree $treeDFDF &&
378
- git-ls-files --stage >DFDF.out'
379
-
380
-test_expect_success \
381
- 'DF vs DF/DF case test (#1)' \
382
- 'rm -f .git/index &&
383
- rm -fr DF &&
384
- echo DF >DF &&
385
- git-update-index --add DF &&
386
- read_tree_twoway $treeDF $treeDFDF &&
387
- git-ls-files --stage >DFDFcheck.out &&
388
- diff -u DFDF.out DFDFcheck.out &&
389
- check_cache_at DF/DF clean && # different from pure 2-way
390
- :'
391
-
392
-# The other way around
393
-test_expect_success \
394
- 'DF vs DF/DF case test (#2)' \
395
- 'rm -f .git/index &&
396
- rm -fr DF &&
397
- mkdir DF &&
398
- echo DF/DF >DF/DF &&
399
- git-update-index --add DF/DF &&
400
- read_tree_twoway $treeDFDF $treeDF &&
401
- git-ls-files --stage >DFDFcheck.out &&
402
- diff -u DF.out DFDFcheck.out &&
403
- check_cache_at DF clean && # different from pure 2-way
404
- :'
405
-
406
-# Emu23 can grok I having more than H. Make sure we did not
407
-# botch the conflict tests (fixed).
408
-test_expect_success \
409
- 'DF vs DF/DF case test (#3).' \
410
- 'rm -f .git/index &&
411
- rm -fr DF &&
412
- mkdir DF &&
413
- echo DF/DF >DF/DF &&
414
- git-update-index --add DF/DF &&
415
- # This should fail because I and H have a conflict
416
- # at DF.
417
- if git-read-tree --emu23 $treeDF $treeDFDF
418
- then false
419
- else true
420
- fi'
421
-
422
-test_done