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.

195 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-reach.c: 15-------19
  59. * sha1-name.c: 20
  60. * list-objects-filter.c: 21
  61. * builtin/fsck.c: 0--3
  62. * builtin/index-pack.c: 2021
  63. * builtin/pack-objects.c: 20
  64. * builtin/reflog.c: 10--12
  65. * builtin/show-branch.c: 0-------------------------------------------26
  66. * builtin/unpack-objects.c: 2021
  67. */
  68. #define FLAG_BITS 29
  69. /*
  70. * The object type is stored in 3 bits.
  71. */
  72. struct object {
  73. unsigned parsed : 1;
  74. unsigned type : TYPE_BITS;
  75. unsigned flags : FLAG_BITS;
  76. struct object_id oid;
  77. };
  78. const char *type_name(unsigned int type);
  79. int type_from_string_gently(const char *str, ssize_t, int gentle);
  80. #define type_from_string(str) type_from_string_gently(str, -1, 0)
  81. /*
  82. * Return the current number of buckets in the object hashmap.
  83. */
  84. unsigned int get_max_object_index(void);
  85. /*
  86. * Return the object from the specified bucket in the object hashmap.
  87. */
  88. struct object *get_indexed_object(unsigned int);
  89. /*
  90. * This can be used to see if we have heard of the object before, but
  91. * it can return "yes we have, and here is a half-initialised object"
  92. * for an object that we haven't loaded/parsed yet.
  93. *
  94. * When parsing a commit to create an in-core commit object, its
  95. * parents list holds commit objects that represent its parents, but
  96. * they are expected to be lazily initialized and do not know what
  97. * their trees or parents are yet. When this function returns such a
  98. * half-initialised objects, the caller is expected to initialize them
  99. * by calling parse_object() on them.
  100. */
  101. struct object *lookup_object(struct repository *r, const struct object_id *oid);
  102. void *create_object(struct repository *r, const struct object_id *oid, void *obj);
  103. void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
  104. /*
  105. * Returns the object, having parsed it to find out what it is.
  106. *
  107. * Returns NULL if the object is missing or corrupt.
  108. */
  109. struct object *parse_object(struct repository *r, const struct object_id *oid);
  110. /*
  111. * Like parse_object, but will die() instead of returning NULL. If the
  112. * "name" parameter is not NULL, it is included in the error message
  113. * (otherwise, the hex object ID is given).
  114. */
  115. struct object *parse_object_or_die(const struct object_id *oid, const char *name);
  116. /* Given the result of read_sha1_file(), returns the object after
  117. * parsing it. eaten_p indicates if the object has a borrowed copy
  118. * of buffer and the caller should not free() it.
  119. */
  120. 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);
  121. /** Returns the object, with potentially excess memory allocated. **/
  122. struct object *lookup_unknown_object(const struct object_id *oid);
  123. struct object_list *object_list_insert(struct object *item,
  124. struct object_list **list_p);
  125. int object_list_contains(struct object_list *list, struct object *obj);
  126. /* Object array handling .. */
  127. void add_object_array(struct object *obj, const char *name, struct object_array *array);
  128. void add_object_array_with_path(struct object *obj, const char *name, struct object_array *array, unsigned mode, const char *path);
  129. /*
  130. * Returns NULL if the array is empty. Otherwise, returns the last object
  131. * after removing its entry from the array. Other resources associated
  132. * with that object are left in an unspecified state and should not be
  133. * examined.
  134. */
  135. struct object *object_array_pop(struct object_array *array);
  136. typedef int (*object_array_each_func_t)(struct object_array_entry *, void *);
  137. /*
  138. * Apply want to each entry in array, retaining only the entries for
  139. * which the function returns true. Preserve the order of the entries
  140. * that are retained.
  141. */
  142. void object_array_filter(struct object_array *array,
  143. object_array_each_func_t want, void *cb_data);
  144. /*
  145. * Remove from array all but the first entry with a given name.
  146. * Warning: this function uses an O(N^2) algorithm.
  147. */
  148. void object_array_remove_duplicates(struct object_array *array);
  149. /*
  150. * Remove any objects from the array, freeing all used memory; afterwards
  151. * the array is ready to store more objects with add_object_array().
  152. */
  153. void object_array_clear(struct object_array *array);
  154. void clear_object_flags(unsigned flags);
  155. /*
  156. * Clear the specified object flags from all in-core commit objects.
  157. */
  158. void clear_commit_marks_all(unsigned int flags);
  159. #endif /* OBJECT_H */