6 int cmd__example_decorate(int argc
, const char **argv
)
9 struct object_id one_oid
= { {1} };
10 struct object_id two_oid
= { {2} };
11 struct object_id three_oid
= { {3} };
12 struct object
*one
, *two
, *three
;
14 int decoration_a
, decoration_b
;
18 int i
, objects_noticed
= 0;
21 * The struct must be zero-initialized.
23 memset(&n
, 0, sizeof(n
));
26 * Add 2 objects, one with a non-NULL decoration and one with a NULL
29 one
= lookup_unknown_object(one_oid
.hash
);
30 two
= lookup_unknown_object(two_oid
.hash
);
31 ret
= add_decoration(&n
, one
, &decoration_a
);
33 die("BUG: when adding a brand-new object, NULL should be returned");
34 ret
= add_decoration(&n
, two
, NULL
);
36 die("BUG: when adding a brand-new object, NULL should be returned");
39 * When re-adding an already existing object, the old decoration is
42 ret
= add_decoration(&n
, one
, NULL
);
43 if (ret
!= &decoration_a
)
44 die("BUG: when readding an already existing object, existing decoration should be returned");
45 ret
= add_decoration(&n
, two
, &decoration_b
);
47 die("BUG: when readding an already existing object, existing decoration should be returned");
50 * Lookup returns the added declarations, or NULL if the object was
53 ret
= lookup_decoration(&n
, one
);
55 die("BUG: lookup should return added declaration");
56 ret
= lookup_decoration(&n
, two
);
57 if (ret
!= &decoration_b
)
58 die("BUG: lookup should return added declaration");
59 three
= lookup_unknown_object(three_oid
.hash
);
60 ret
= lookup_decoration(&n
, three
);
62 die("BUG: lookup for unknown object should return NULL");
65 * The user can also loop through all entries.
67 for (i
= 0; i
< n
.size
; i
++) {
68 if (n
.entries
[i
].base
)
71 if (objects_noticed
!= 2)
72 die("BUG: should have 2 objects");