git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob d79b087ab0423a13b5d27bcf71f608b20acdff64 3507 bytes (raw)
name: oidmap.h 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
#ifndef OIDMAP_H
#define OIDMAP_H

#include "cache.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);

/*
 * Frees an oidmap structure and allocated memory.
 *
 * If `free_entries` is true, each oidmap_entry in the map is freed as well
 * using stdlibs free().
 */
void oidmap_free(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);

#define oidmap_entry_from_hashmap_entry(entry) \
	container_of_or_null(entry, struct oidmap_entry, internal_entry)

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);
}

/* Returns the next oidmap_entry, or NULL if there are no more entries. */
static inline struct oidmap_entry *oidmap_iter_next(struct oidmap_iter *iter)
{
	return oidmap_entry_from_hashmap_entry(
			hashmap_iter_next(&iter->h_iter));
}

/* Initializes the iterator and returns the first entry, if any. */
static inline struct oidmap_entry *oidmap_iter_first(struct oidmap *map,
				      struct oidmap_iter *iter)
{
	oidmap_iter_init(map, iter);
	return oidmap_iter_next(iter);
}

/*
 * Returns the first entry in @map using @iter, where the entry if of
 * @type (e.g. "struct foo") and @member is the name of the
 * "struct oidmap_entry" in @type
 */
#define oidmap_iter_first_entry(map, iter, type, member) \
	container_of_or_null(oidmap_iter_first(map, iter), type, member)

/* Internal macro for oidmap_for_each_entry */
#define oidmap_iter_next_entry_offset(iter, offset) \
	container_of_or_null_offset(oidmap_iter_next(iter), offset)

/* Internal macro for oidmap_for_each_entry */
#define oidmap_iter_first_entry_offset(map, iter, offset) \
	container_of_or_null_offset(oidmap_iter_first(map, iter), offset)

/*
 * Iterate through @map using @iter, @var is a pointer to a type
 * containing a @member which is a "struct oidmap_entry"
 */
#define oidmap_for_each_entry(map, iter, var, member) \
	for (var = oidmap_iter_first_entry_offset(map, iter, \
						OFFSETOF_VAR(var, member)); \
		var; \
		var = oidmap_iter_next_entry_offset(iter, \
						OFFSETOF_VAR(var, member)))
#endif

debug log:

solving d79b087ab0 ...
found d79b087ab0 in https://public-inbox.org/git/20200425025921.1397-2-abhishekkumar8222@gmail.com/
found c66a83ab1d in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 c66a83ab1d6891dbe6916d13339b64456b8cc440	oidmap.h

applying [1/1] https://public-inbox.org/git/20200425025921.1397-2-abhishekkumar8222@gmail.com/
diff --git a/oidmap.h b/oidmap.h
index c66a83ab1d..d79b087ab0 100644

Checking patch oidmap.h...
Applied patch oidmap.h cleanly.

index at:
100644 d79b087ab0423a13b5d27bcf71f608b20acdff64	oidmap.h

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).