Skip to content

Commit 33055fa

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 91de344 commit 33055fa

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

builtin/diff.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
253253
{
254254
int i;
255255
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;
258258
const char *path = NULL;
259259
struct blobinfo blob[2];
260260
int nongit;
@@ -351,13 +351,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
351351
if (obj->type == OBJ_COMMIT)
352352
obj = &((struct commit *)obj)->tree->object;
353353
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);
357354
obj->flags |= flags;
358-
ent[ents].item = obj;
359-
ent[ents].name = name;
360-
ents++;
355+
add_object_array(obj, name, &ent);
361356
continue;
362357
}
363358
if (obj->type == OBJ_BLOB) {
@@ -381,7 +376,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
381376
/*
382377
* Now, do the arguments look reasonable?
383378
*/
384-
if (!ents) {
379+
if (!ent.nr) {
385380
switch (blobs) {
386381
case 0:
387382
result = builtin_diff_files(&rev, argc, argv);
@@ -402,22 +397,26 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
402397
}
403398
else if (blobs)
404399
usage(builtin_diff_usage);
405-
else if (ents == 1)
400+
else if (ent.nr == 1)
406401
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) {
410406
/*
411407
* 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.
416413
*/
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]);
418417
} else
419418
result = builtin_diff_combined(&rev, argc, argv,
420-
ent, ents);
419+
ent.objects, ent.nr);
421420
result = diff_result_code(&rev.diffopt, result);
422421
if (1 < rev.diffopt.skip_stat_unmatch)
423422
refresh_index_quietly();

0 commit comments

Comments
 (0)