mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-27 11:47:49 -05:00
The Git project is not exactly the easiest project to get started in: it's written in C and POSIX shell, with bits of Perl, Rust and other languages sprinkled into it. On top of that, the project has grown somewhat organically over time, making the codebase hard to navigate. These are problems that we're aware of, and there have been and still are efforts to clean up some of the technical debt that is natural to exist an a project that is more than 20 years old. Furthermore, we provide resources to newcomers that help them out like our coding guidelines, code of conduct or "MyFirstContribution.adoc". But there is a rather practical problem: finding your way around in our project's tree is not easy. Doing a directory listing in the top-level directory will present you with more than 550 files, which makes it extremely hard for a newcomer to figure out what files they are even supposed to look at. This makes the onboarding experience somewhat harder than it really needs to be. This isn't only a problem for newcomers though, as I myself struggle to find the files I am looking for because of the sheer number of files. Besides the problem of discoverability it also creates a problem of structure. It is not obvious at all which files are part of "libgit.a" and which files are only linked into our final executables. So while we have this split in our build systems, that split is not evident at all in our tree. Introduce a new "lib/" directory and move all of our sources for "libgit.a" into it to fix these issues. It makes the split we have evident and reduces the number of files in our top-level tree from 550 files to ~80 files. This is still a lot of files, but it's significantly easier to navigate already. Furthermore, we can further iterate after this step and think about introducing a better structure for remaining files, as well. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
114 lines
2.9 KiB
C
114 lines
2.9 KiB
C
#ifndef OIDMAP_H
|
|
#define OIDMAP_H
|
|
|
|
#include "hash.h"
|
|
#include "hashmap.h"
|
|
|
|
/*
|
|
* struct oidmap_entry is a structure representing an entry in the hash table,
|
|
* which must be used as first member of user data structures.
|
|
*
|
|
* Users should set the oid field. oidmap_put() will populate the
|
|
* internal_entry field.
|
|
*/
|
|
struct oidmap_entry {
|
|
/* For internal use only */
|
|
struct hashmap_entry internal_entry;
|
|
|
|
struct object_id oid;
|
|
};
|
|
|
|
struct oidmap {
|
|
struct hashmap map;
|
|
};
|
|
|
|
#define OIDMAP_INIT { { NULL } }
|
|
|
|
/*
|
|
* Initializes an oidmap structure.
|
|
*
|
|
* `map` is the oidmap to initialize.
|
|
*
|
|
* If the total number of entries is known in advance, the `initial_size`
|
|
* parameter may be used to preallocate a sufficiently large table and thus
|
|
* prevent expensive resizing. If 0, the table is dynamically resized.
|
|
*/
|
|
void oidmap_init(struct oidmap *map, size_t initial_size);
|
|
|
|
/*
|
|
* Function type for functions that free oidmap entries.
|
|
*/
|
|
typedef void (*oidmap_free_fn)(void *);
|
|
|
|
/*
|
|
* Clear an oidmap, freeing any allocated memory. The map is empty and
|
|
* can be reused without another explicit init.
|
|
*
|
|
* The `free_fn`, if not NULL, is called for each oidmap entry in the map
|
|
* to free any user data associated with the entry.
|
|
*/
|
|
void oidmap_clear_with_free(struct oidmap *map,
|
|
oidmap_free_fn free_fn);
|
|
|
|
/*
|
|
* Clear an oidmap, freeing any allocated memory. The map is empty and
|
|
* can be reused without another explicit init.
|
|
*
|
|
* If `free_entries` is true, each oidmap_entry in the map is freed as well
|
|
* using stdlibs free().
|
|
*/
|
|
void oidmap_clear(struct oidmap *map, int free_entries);
|
|
|
|
/*
|
|
* Returns the oidmap entry for the specified oid, or NULL if not found.
|
|
*/
|
|
void *oidmap_get(const struct oidmap *map,
|
|
const struct object_id *key);
|
|
|
|
/*
|
|
* Adds or replaces an oidmap entry.
|
|
*
|
|
* ((struct oidmap_entry *) entry)->internal_entry will be populated by this
|
|
* function.
|
|
*
|
|
* Returns the replaced entry, or NULL if not found (i.e. the entry was added).
|
|
*/
|
|
void *oidmap_put(struct oidmap *map, void *entry);
|
|
|
|
/*
|
|
* Removes an oidmap entry matching the specified oid.
|
|
*
|
|
* Returns the removed entry, or NULL if not found.
|
|
*/
|
|
void *oidmap_remove(struct oidmap *map, const struct object_id *key);
|
|
|
|
static inline unsigned int oidmap_get_size(struct oidmap *map)
|
|
{
|
|
return hashmap_get_size(&map->map);
|
|
}
|
|
|
|
struct oidmap_iter {
|
|
struct hashmap_iter h_iter;
|
|
};
|
|
|
|
static inline void oidmap_iter_init(struct oidmap *map, struct oidmap_iter *iter)
|
|
{
|
|
hashmap_iter_init(&map->map, &iter->h_iter);
|
|
}
|
|
|
|
static inline void *oidmap_iter_next(struct oidmap_iter *iter)
|
|
{
|
|
/* TODO: this API could be reworked to do compile-time type checks */
|
|
return (void *)hashmap_iter_next(&iter->h_iter);
|
|
}
|
|
|
|
static inline void *oidmap_iter_first(struct oidmap *map,
|
|
struct oidmap_iter *iter)
|
|
{
|
|
oidmap_iter_init(map, iter);
|
|
/* TODO: this API could be reworked to do compile-time type checks */
|
|
return (void *)oidmap_iter_next(iter);
|
|
}
|
|
|
|
#endif
|