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

[RFC/PATCH v2 02/10] external odb foreach

From
Christian Couder <christian.couder@gmail.com>
Date
Jun 28, 2016, 18:19 UTC
Message-ID
<20160628181933.24620-3-chriscool@tuxfamily.org>
In-Reply-To
<20160628181933.24620-1-chriscool@tuxfamily.org>
From: Jeff King <peff@peff.net>
---
 external-odb.c | 14 ++++++++++++++
 external-odb.h |  6 ++++++
 odb-helper.c   | 15 +++++++++++++++
 odb-helper.h   |  4 ++++
 4 files changed, 39 insertions(+)
diff --git a/external-odb.c b/external-odb.c
index 1ccfa99..42978a3 100644
--- a/external-odb.c
+++ b/external-odb.c
@@ -113,3 +113,17 @@ int external_odb_fetch_object(const unsigned char *sha1)
 
 	return -1;
 }
+
+int external_odb_for_each_object(each_external_object_fn fn, void *data)
+{
+	struct odb_helper *o;
+
+	external_odb_init();
+
+	for (o = helpers; o; o = o->next) {
+		int r = odb_helper_for_each_object(o, fn, data);
+		if (r)
+			return r;
+	}
+	return 0;
+}
diff --git a/external-odb.h b/external-odb.h
index 2397477..cea8570 100644
--- a/external-odb.h
+++ b/external-odb.h
@@ -5,4 +5,10 @@ const char *external_odb_root(void);
 int external_odb_has_object(const unsigned char *sha1);
 int external_odb_fetch_object(const unsigned char *sha1);
 
+typedef int (*each_external_object_fn)(const unsigned char *sha1,
+				       enum object_type type,
+				       unsigned long size,
+				       void *data);
+int external_odb_for_each_object(each_external_object_fn, void *);
+
 #endif /* EXTERNAL_ODB_H */
diff --git a/odb-helper.c b/odb-helper.c
index 7029a59..045cf6f 100644
--- a/odb-helper.c
+++ b/odb-helper.c
@@ -235,5 +235,20 @@ int odb_helper_fetch_object(struct odb_helper *o, const unsigned char *sha1,
 		return -1;
 	}
 
+	return 0;
+}
+
+int odb_helper_for_each_object(struct odb_helper *o,
+			       each_external_object_fn fn,
+			       void *data)
+{
+	int i;
+	for (i = 0; i < o->have_nr; i++) {
+		struct odb_helper_object *obj = &o->have[i];
+		int r = fn(obj->sha1, obj->type, obj->size, data);
+		if (r)
+			return r;
+	}
+
 	return 0;
 }
diff --git a/odb-helper.h b/odb-helper.h
index 0f704f9..8c3916d 100644
--- a/odb-helper.h
+++ b/odb-helper.h
@@ -1,6 +1,8 @@
 #ifndef ODB_HELPER_H
 #define ODB_HELPER_H
 
+#include "external-odb.h"
+
 struct odb_helper {
 	const char *name;
 	const char *cmd;
@@ -21,5 +23,7 @@ struct odb_helper *odb_helper_new(const char *name, int namelen);
 int odb_helper_has_object(struct odb_helper *o, const unsigned char *sha1);
 int odb_helper_fetch_object(struct odb_helper *o, const unsigned char *sha1,
 			    int fd);
+int odb_helper_for_each_object(struct odb_helper *o,
+			       each_external_object_fn, void *);
 
 #endif /* ODB_HELPER_H */
-- 
2.9.0.rc2.11.g990c140
Previous: Christian CouderNext: Christian Couder
Message 3 of 13 in “Add initial experimental external ODB support”
  1. 00/10 Add initial experimental external ODB supportChristian Couder, Jun 28, 2016
  2. 01/10 Add initial external odb supportChristian Couder, Jun 28, 2016
  3. 02/10 external odb foreachChristian Couder, Jun 28, 2016
  4. 05/10 t0400: add test for 'put' commandChristian Couder, Jun 28, 2016
  5. 06/10 external odb: add write supportChristian Couder, Jun 28, 2016
  6. 07/10 external-odb: accept only blobs for nowChristian Couder, Jun 28, 2016
  7. 03/10 t0400: use --batch-all-objects to get all objectsChristian Couder, Jun 28, 2016
  8. 08/10 t0400: add test for external odb write supportChristian Couder, Jun 28, 2016
  9. 10/10 Add t0410 to test external ODB transferChristian Couder, Jun 28, 2016
  10. 04/10 t0400: add 'put' command to odb-helper scriptChristian Couder, Jun 28, 2016
  11. 09/10 Add GIT_NO_EXTERNAL_ODB env variableChristian Couder, Jun 28, 2016
  12. Eric WongJun 29, 2016
  13. Christian CouderJun 30, 2016

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.