THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
6.3KB

  1. #ifndef OBJECT_H
  2. #define OBJECT_H
  3. #include "cache.h"
  4. struct buffer_slab;
  5. struct parsed_object_pool {
  6. struct object **obj_hash;
  7. int nr_objs, obj_hash_size;
  8. /* TODO: migrate alloc_states to mem-pool? */
  9. struct alloc_state *blob_state;
  10. struct alloc_state *tree_state;
  11. struct alloc_state *commit_state;
  12. struct alloc_state *tag_state;
  13. struct alloc_state *object_state;
  14. unsigned commit_count;
  15. /* parent substitutions from .git/info/grafts and .git/shallow */
  16. struct commit_graft **grafts;
  17. int grafts_alloc, grafts_nr;
  18. int is_shallow;
  19. struct stat_validity *shallow_stat;
  20. char *alternate_shallow_file;
  21. int commit_graft_prepared;
  22. struct buffer_slab *buffer_slab;
  23. };
  24. struct parsed_object_pool *parsed_object_pool_new(void);
  25. void parsed_object_pool_clear(struct parsed_object_pool *o);
  26. struct object_list {
  27. struct object *item;
  28. struct object_list *next;
  29. };
  30. struct object_array {
  31. unsigned int nr;
  32. unsigned int alloc;
  33. struct object_array_entry {
  34. struct object *item;
  35. /*
  36. * name or NULL. If non-NULL, the memory pointed to
  37. * is owned by this object *except* if it points at
  38. * object_array_slopbuf, which is a static copy of the
  39. * empty string.
  40. */
  41. char *name;
  42. char *path;
  43. unsigned mode;
  44. } *objects;
  45. };
  46. #define OBJECT_ARRAY_INIT { 0, 0, NULL }
  47. /*
  48. * object flag allocation:
  49. * revision.h: 0---------10 25----28
  50. * fetch-pack.c: 01
  51. * negotiator/default.c: 2--5
  52. * walker.c: 0-2
  53. * upload-pack.c: 4 11-----14 16-----19
  54. * builtin/blame.c: 12-13
  55. * bisect.c: 16
  56. * bundle.c: 16
  57. * http-push.c: 16-----19
  58. * commit-graph.c: 15
  59. * commit-reach.c: 16-----19
  60. * sha1-name.c: 20
  61. * list-objects-filter.c: 21
  62. * builtin/fsck.c: 0--3
  63. * builtin/index-pack.c: 2021
  64. * builtin/pack-objects.c: 20
  65. * builtin/reflog.c: 10--12
  66. * builtin/show-branch.c: 0-------------------------------------------26
  67. * builtin/unpack-objects.c: 2021
  68. */
  69. #define FLAG_BITS 29
  70. /*
  71. * The object type is stored in 3 bits.
  72. */
  73. struct object {
  74. unsigned parsed : 1;
  75. unsigned type : TYPE_BITS;
  76. unsigned flags : FLAG_BITS;
  77. struct object_id oid;
  78. };
  79. const char *type_name(unsigned int type);
  80. int type_from_string_gently(const char *str, ssize_t, int gentle);
  81. #define type_from_string(str) type_from_string_gently(str, -1, 0)
  82. /*
  83. * Return the current number of buckets in the object hashmap.
  84. */
  85. unsigned int get_max_object_index(void);
  86. /*
  87. * Return the object from the specified bucket in the object hashmap.
  88. */
  89. struct object *get_indexed_object(unsigned int);
  90. /*
  91. * This can be used to see if we have heard of the object before, but
  92. * it can return "yes we have, and here is a half-initialised object"
  93. * for an object that we haven't loaded/parsed yet.
  94. *
  95. * When parsing a commit to create an in-core commit object, its
  96. * parents list holds commit objects that represent its parents, but
  97. * they are expected to be lazily initialized and do not know what
  98. * their trees or parents are yet. When this function returns such a
  99. * half-initialised objects, the caller is expected to initialize them
  100. * by calling parse_object() on them.
  101. */
  102. struct object *lookup_object(struct repository *r, const struct object_id *oid);
  103. void *create_object(struct repository *r, const struct object_id *oid, void *obj);
  104. void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
  105. /*
  106. * Returns the object, having parsed it to find out what it is.
  107. *
  108. * Returns NULL if the object is missing or corrupt.
  109. */
  110. struct object *parse_object(struct repository *r, const struct object_id *oid);
  111. /*
  112. * Like parse_object, but will die() instead of returning NULL. If the
  113. * "name" parameter is not NULL, it is included in the error message
  114. * (otherwise, the hex object ID is given).
  115. */
  116. struct object *parse_object_or_die(const struct object_id *oid, const char *name);
  117. /* Given the result of read_sha1_file(), returns the object after
  118. * parsing it. eaten_p indicates if the object has a borrowed copy
  119. * of buffer and the caller should not free() it.
  120. */
  121. struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
  122. /** Returns the object, with potentially excess memory allocated. **/
  123. struct object *lookup_unknown_object(const struct object_id *oid);
  124. struct object_list *object_list_insert(struct object *item,
  125. struct object_list **list_p);
  126. int object_list_contains(struct object_list *list, struct object *obj);
  127. /* Object array handling .. */
  128. void add_object_array(struct object *obj, const char *name, struct object_array *array);
  129. void add_object_array_with_path(struct object *obj, const char *name, struct object_array *array, unsigned mode, const char *path);
  130. /*
  131. * Returns NULL if the array is empty. Otherwise, returns the last object
  132. * after removing its entry from the array. Other resources associated
  133. * with that object are left in an unspecified state and should not be
  134. * examined.
  135. */
  136. struct object *object_array_pop(struct object_array *array);
  137. typedef int (*object_array_each_func_t)(struct object_array_entry *, void *);
  138. /*
  139. * Apply want to each entry in array, retaining only the entries for
  140. * which the function returns true. Preserve the order of the entries
  141. * that are retained.
  142. */
  143. void object_array_filter(struct object_array *array,
  144. object_array_each_func_t want, void *cb_data);
  145. /*
  146. * Remove from array all but the first entry with a given name.
  147. * Warning: this function uses an O(N^2) algorithm.
  148. */
  149. void object_array_remove_duplicates(struct object_array *array);
  150. /*
  151. * Remove any objects from the array, freeing all used memory; afterwards
  152. * the array is ready to store more objects with add_object_array().
  153. */
  154. void object_array_clear(struct object_array *array);
  155. void clear_object_flags(unsigned flags);
  156. /*
  157. * Clear the specified object flags from all in-core commit objects.
  158. */
  159. void clear_commit_marks_all(unsigned int flags);
  160. #endif /* OBJECT_H */