2 #include "git-compat-util.h"
5 #include "repository.h"
7 int cmd__example_decorate(int argc UNUSED
, const char **argv UNUSED
)
10 struct object_id one_oid
= { {1} };
11 struct object_id two_oid
= { {2} };
12 struct object_id three_oid
= { {3} };
13 struct object
*one
, *two
, *three
;
15 int decoration_a
, decoration_b
;
19 int i
, objects_noticed
= 0;
22 * The struct must be zero-initialized.
24 memset(&n
, 0, sizeof(n
));
27 * Add 2 objects, one with a non-NULL decoration and one with a NULL
30 one
= lookup_unknown_object(the_repository
, &one_oid
);
31 two
= lookup_unknown_object(the_repository
, &two_oid
);
32 ret
= add_decoration(&n
, one
, &decoration_a
);
34 BUG("when adding a brand-new object, NULL should be returned");
35 ret
= add_decoration(&n
, two
, NULL
);
37 BUG("when adding a brand-new object, NULL should be returned");
40 * When re-adding an already existing object, the old decoration is
43 ret
= add_decoration(&n
, one
, NULL
);
44 if (ret
!= &decoration_a
)
45 BUG("when readding an already existing object, existing decoration should be returned");
46 ret
= add_decoration(&n
, two
, &decoration_b
);
48 BUG("when readding an already existing object, existing decoration should be returned");
51 * Lookup returns the added declarations, or NULL if the object was
54 ret
= lookup_decoration(&n
, one
);
56 BUG("lookup should return added declaration");
57 ret
= lookup_decoration(&n
, two
);
58 if (ret
!= &decoration_b
)
59 BUG("lookup should return added declaration");
60 three
= lookup_unknown_object(the_repository
, &three_oid
);
61 ret
= lookup_decoration(&n
, three
);
63 BUG("lookup for unknown object should return NULL");
66 * The user can also loop through all entries.
68 for (i
= 0; i
< n
.size
; i
++) {
69 if (n
.entries
[i
].base
)
72 if (objects_noticed
!= 2)
73 BUG("should have 2 objects");
75 clear_decoration(&n
, NULL
);