cmd_diff(): use an object_array for holding trees
Change cmd_diff() to use a (struct object_array) for holding the trees that it accumulates, rather than rolling its own equivalent. Incidentally, this change removes a hard-coded limit of 100 trees in combined diff, not that it matters in practice. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
May 25, 2013 at 11:08 UTC
33055fa823eff9f4fddb858856f9b9a8d85316fc
1 file changed
+18
-19
builtin/diff.c
+18
-19
@@ -253,8 +253,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
253
{
254
int i;
255
struct rev_info rev;
256
- struct object_array_entry ent[100];
257
- int ents = 0, blobs = 0, paths = 0;
256
+ struct object_array ent = OBJECT_ARRAY_INIT;
257
+ int blobs = 0, paths = 0;
258
const char *path = NULL;
259
struct blobinfo blob[2];
260
int nongit;
@@ -351,13 +351,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
351
if (obj->type == OBJ_COMMIT)
352
obj = &((struct commit *)obj)->tree->object;
353
if (obj->type == OBJ_TREE) {
354
- if (ARRAY_SIZE(ent) <= ents)
355
- die(_("more than %d trees given: '%s'"),
356
- (int) ARRAY_SIZE(ent), name);
354
obj->flags |= flags;
358
- ent[ents].item = obj;
359
- ent[ents].name = name;
360
- ents++;
355
+ add_object_array(obj, name, &ent);
356
continue;
357
}
358
if (obj->type == OBJ_BLOB) {
@@ -381,7 +376,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
376
/*
377
* Now, do the arguments look reasonable?
378
*/
384
- if (!ents) {
379
+ if (!ent.nr) {
380
switch (blobs) {
381
case 0:
382
result = builtin_diff_files(&rev, argc, argv);
@@ -402,22 +397,26 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
397
}
398
else if (blobs)
399
usage(builtin_diff_usage);
405
- else if (ents == 1)
400
+ else if (ent.nr == 1)
401
result = builtin_diff_index(&rev, argc, argv);
407
- else if (ents == 2)
408
- result = builtin_diff_tree(&rev, argc, argv, &ent[0], &ent[1]);
409
- else if (ent[0].item->flags & UNINTERESTING) {
402
+ else if (ent.nr == 2)
403
+ result = builtin_diff_tree(&rev, argc, argv,
404
+ &ent.objects[0], &ent.objects[1]);
405
+ else if (ent.objects[0].item->flags & UNINTERESTING) {
406
/*
407
* diff A...B where there is at least one merge base
412
- * between A and B. We have ent[0] == merge-base,
413
- * ent[ents-2] == A, and ent[ents-1] == B. Show diff
414
- * between the base and B. Note that we pick one
415
- * merge base at random if there are more than one.
408
+ * between A and B. We have ent.objects[0] ==
409
+ * merge-base, ent.objects[ents-2] == A, and
410
+ * ent.objects[ents-1] == B. Show diff between the
411
+ * base and B. Note that we pick one merge base at
412
+ * random if there are more than one.
413
*/
417
- result = builtin_diff_tree(&rev, argc, argv, &ent[0], &ent[ents-1]);
414
+ result = builtin_diff_tree(&rev, argc, argv,
415
+ &ent.objects[0],
416
+ &ent.objects[ent.nr-1]);
417
} else
418
result = builtin_diff_combined(&rev, argc, argv,
420
- ent, ents);
419
+ ent.objects, ent.nr);
420
result = diff_result_code(&rev.diffopt, result);
421
if (1 < rev.diffopt.skip_stat_unmatch)
422
refresh_index_quietly();