git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 1/5] oidmap: add oidmap_add()

From
Christian Couder <christian.couder@gmail.com>
Date
Jul 7, 2019, 08:29 UTC
Message-ID
<20190707083002.7037-2-chriscool@tuxfamily.org>
In-Reply-To
<20190707083002.7037-1-chriscool@tuxfamily.org>

We will need to have more than one entry with the same oid key in an oidmap, which is not supported yet, as oipmap_put() replaces an existing entry with the same oid key. So let's add oidmap_add().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 oidmap.c | 12 ++++++++++++
 oidmap.h |  6 ++++++
 2 files changed, 18 insertions(+)
diff --git a/oidmap.c b/oidmap.c
index 6d6e840d03..bfb290ee01 100644
--- a/oidmap.c
+++ b/oidmap.c
@@ -43,6 +43,17 @@ void *oidmap_remove(struct oidmap *map, const struct object_id *key)
 	return hashmap_remove(&map->map, &entry, key);
 }
 
+void oidmap_add(struct oidmap *map, void *entry)
+{
+	struct oidmap_entry *to_put = entry;
+
+	if (!map->map.cmpfn)
+		oidmap_init(map, 0);
+
+	hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid));
+	hashmap_add(&map->map, to_put);
+}
+
 void *oidmap_put(struct oidmap *map, void *entry)
 {
 	struct oidmap_entry *to_put = entry;
@@ -53,3 +64,4 @@ void *oidmap_put(struct oidmap *map, void *entry)
 	hashmap_entry_init(&to_put->internal_entry, oidhash(&to_put->oid));
 	return hashmap_put(&map->map, to_put);
 }
+
diff --git a/oidmap.h b/oidmap.h
index 7a939461ff..21d929ad79 100644
--- a/oidmap.h
+++ b/oidmap.h
@@ -49,6 +49,12 @@ void oidmap_free(struct oidmap *map, int free_entries);
 void *oidmap_get(const struct oidmap *map,
 		 const struct object_id *key);
 
+/*
+ * Adds an oidmap entry. This allows to add duplicate entries (i.e.
+ * separate values with the same oid key).
+ */
+void oidmap_add(struct oidmap *map, void *entry);
+
 /*
  * Adds or replaces an oidmap entry.
  *
-- 
2.22.0.514.g3228928bce.dirty
Previous: Christian CouderNext: Christian Couder
Message 2 of 9 in “oidmap: handle entries with the same key”
  1. 0/5 oidmap: handle entries with the same keyChristian Couder, Jul 7, 2019
  2. 1/5 oidmap: add oidmap_add()Christian Couder, Jul 7, 2019
  3. 2/5 oidmap: add oidmap_get_next()Christian Couder, Jul 7, 2019
  4. 3/5 test-oidmap: add back proper 'add' subcommandChristian Couder, Jul 7, 2019
  5. 4/5 test-oidmap: add 'get_all' subcommandChristian Couder, Jul 7, 2019
  6. 5/5 t0016: add 'add' and 'get_all' subcommand testChristian Couder, Jul 7, 2019
  7. Junio C HamanoJul 8, 2019
  8. Junio C HamanoJul 12, 2019
  9. Jeff KingJul 12, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.