Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
cmd_diff(): use an object_array for holding trees
author
Michael Haggerty
<mhagger@alum.mit.edu>
Sat, 25 May 2013 09:08:04 +0000
(11:08 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Tue, 28 May 2013 16:25:00 +0000
(09:25 -0700)
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>
builtin/diff.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
91de344
)
diff --git
a/builtin/diff.c
b/builtin/diff.c
index abdd613a83f60bc9a7fc395e421d09a672bb5c59..661fdde4d5169a59232db5494edc85b06a9928cc 100644
(file)
--- a/
builtin/diff.c
+++ b/
builtin/diff.c
@@
-253,8
+253,8
@@
int cmd_diff(int argc, const char **argv, const char *prefix)
{
int i;
struct rev_info rev;
{
int i;
struct rev_info rev;
- struct object_array
_entry ent[100]
;
- int
ents = 0,
blobs = 0, paths = 0;
+ struct object_array
ent = OBJECT_ARRAY_INIT
;
+ int blobs = 0, paths = 0;
const char *path = NULL;
struct blobinfo blob[2];
int nongit;
const char *path = NULL;
struct blobinfo blob[2];
int nongit;
@@
-351,13
+351,8
@@
int cmd_diff(int argc, const char **argv, const char *prefix)
if (obj->type == OBJ_COMMIT)
obj = &((struct commit *)obj)->tree->object;
if (obj->type == OBJ_TREE) {
if (obj->type == OBJ_COMMIT)
obj = &((struct commit *)obj)->tree->object;
if (obj->type == OBJ_TREE) {
- if (ARRAY_SIZE(ent) <= ents)
- die(_("more than %d trees given: '%s'"),
- (int) ARRAY_SIZE(ent), name);
obj->flags |= flags;
obj->flags |= flags;
- ent[ents].item = obj;
- ent[ents].name = name;
- ents++;
+ add_object_array(obj, name, &ent);
continue;
}
if (obj->type == OBJ_BLOB) {
continue;
}
if (obj->type == OBJ_BLOB) {
@@
-381,7
+376,7
@@
int cmd_diff(int argc, const char **argv, const char *prefix)
/*
* Now, do the arguments look reasonable?
*/
/*
* Now, do the arguments look reasonable?
*/
- if (!ent
s
) {
+ if (!ent
.nr
) {
switch (blobs) {
case 0:
result = builtin_diff_files(&rev, argc, argv);
switch (blobs) {
case 0:
result = builtin_diff_files(&rev, argc, argv);
@@
-402,22
+397,26
@@
int cmd_diff(int argc, const char **argv, const char *prefix)
}
else if (blobs)
usage(builtin_diff_usage);
}
else if (blobs)
usage(builtin_diff_usage);
- else if (ent
s
== 1)
+ else if (ent
.nr
== 1)
result = builtin_diff_index(&rev, argc, argv);
result = builtin_diff_index(&rev, argc, argv);
- else if (ents == 2)
- result = builtin_diff_tree(&rev, argc, argv, &ent[0], &ent[1]);
- else if (ent[0].item->flags & UNINTERESTING) {
+ else if (ent.nr == 2)
+ result = builtin_diff_tree(&rev, argc, argv,
+ &ent.objects[0], &ent.objects[1]);
+ else if (ent.objects[0].item->flags & UNINTERESTING) {
/*
* diff A...B where there is at least one merge base
/*
* diff A...B where there is at least one merge base
- * between A and B. We have ent[0] == merge-base,
- * ent[ents-2] == A, and ent[ents-1] == B. Show diff
- * between the base and B. Note that we pick one
- * merge base at random if there are more than one.
+ * between A and B. We have ent.objects[0] ==
+ * merge-base, ent.objects[ents-2] == A, and
+ * ent.objects[ents-1] == B. Show diff between the
+ * base and B. Note that we pick one merge base at
+ * random if there are more than one.
*/
*/
- result = builtin_diff_tree(&rev, argc, argv, &ent[0], &ent[ents-1]);
+ result = builtin_diff_tree(&rev, argc, argv,
+ &ent.objects[0],
+ &ent.objects[ent.nr-1]);
} else
result = builtin_diff_combined(&rev, argc, argv,
} else
result = builtin_diff_combined(&rev, argc, argv,
- ent
, ents
);
+ ent
.objects, ent.nr
);
result = diff_result_code(&rev.diffopt, result);
if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();
result = diff_result_code(&rev.diffopt, result);
if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();