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

[PATCH 4/8] resolve-undo.c: dump "REUC" extension as json

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 19, 2019, 09:58 UTC
Message-ID
<20190619095858.30124-5-pclouds@gmail.com>
In-Reply-To
<20190619095858.30124-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 read-cache.c   |  2 +-
 resolve-undo.c | 36 +++++++++++++++++++++++++++++++++++-
 resolve-undo.h |  4 +++-
 3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index eec030b3bb..3b5c63f53a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1701,7 +1701,7 @@ static int read_index_extension(struct index_state *istate,
 		istate->cache_tree = cache_tree_read(data, sz);
 		break;
 	case CACHE_EXT_RESOLVE_UNDO:
-		istate->resolve_undo = resolve_undo_read(data, sz);
+		istate->resolve_undo = resolve_undo_read(data, sz, istate->jw);
 		break;
 	case CACHE_EXT_LINK:
 		if (read_link_extension(istate, data, sz))
diff --git a/resolve-undo.c b/resolve-undo.c
index 236320f179..999020bc40 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "dir.h"
+#include "json-writer.h"
 #include "resolve-undo.h"
 #include "string-list.h"
 
@@ -49,7 +50,8 @@ void resolve_undo_write(struct strbuf *sb, struct string_list *resolve_undo)
 	}
 }
 
-struct string_list *resolve_undo_read(const char *data, unsigned long size)
+struct string_list *resolve_undo_read(const char *data, unsigned long size,
+				      struct json_writer *jw)
 {
 	struct string_list *resolve_undo;
 	size_t len;
@@ -59,6 +61,11 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
 
 	resolve_undo = xcalloc(1, sizeof(*resolve_undo));
 	resolve_undo->strdup_strings = 1;
+	if (jw) {
+		jw_object_inline_begin_object(jw, "resolve-undo");
+		jw_object_intmax(jw, "ext-size", size);
+		jw_object_inline_begin_array(jw, "entries");
+	}
 
 	while (size) {
 		struct string_list_item *lost;
@@ -94,6 +101,33 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
 			size -= rawsz;
 			data += rawsz;
 		}
+
+		if (jw) {
+			struct strbuf sb = STRBUF_INIT;
+
+			jw_array_inline_begin_object(jw);
+			jw_object_string(jw, "path", lost->string);
+
+			jw_object_inline_begin_array(jw, "mode");
+			for (i = 0; i < 3; i++) {
+				strbuf_addf(&sb, "%06o", ui->mode[i]);
+				jw_array_string(jw, sb.buf);
+				strbuf_reset(&sb);
+			}
+			jw_end(jw);
+
+			jw_object_inline_begin_array(jw, "oid");
+			for (i = 0; i < 3; i++)
+				jw_array_string(jw, oid_to_hex(&ui->oid[i]));
+			jw_end(jw);
+
+			jw_end(jw);
+			strbuf_release(&sb);
+		}
+	}
+	if (jw) {
+		jw_end(jw);	/* entries */
+		jw_end(jw);	/* resolve-undo */
 	}
 	return resolve_undo;
 
diff --git a/resolve-undo.h b/resolve-undo.h
index 2b3f0f901e..46b4e93a7e 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -3,6 +3,8 @@
 
 #include "cache.h"
 
+struct json_writer;
+
 struct resolve_undo_info {
 	unsigned int mode[3];
 	struct object_id oid[3];
@@ -10,7 +12,7 @@ struct resolve_undo_info {
 
 void record_resolve_undo(struct index_state *, struct cache_entry *);
 void resolve_undo_write(struct strbuf *, struct string_list *);
-struct string_list *resolve_undo_read(const char *, unsigned long);
+struct string_list *resolve_undo_read(const char *, unsigned long, struct json_writer *);
 void resolve_undo_clear_index(struct index_state *);
 int unmerge_index_entry_at(struct index_state *, int);
 void unmerge_index(struct index_state *, const struct pathspec *);
-- 
2.22.0.rc0.322.g2b0371e29a
Previous: Nguyễn Thái Ngọc DuyNext: Derrick Stolee
Message 9 of 36 in “Add 'ls-files --json' to dump the index in json”
  1. 0/8 Add 'ls-files --json' to dump the index in jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  2. 1/8 ls-files: add --json to dump the indexNguyễn Thái Ngọc Duy, Jun 19, 2019
  3. Ævar Arnfjörð BjarmasonJun 19, 2019
  4. Derrick StoleeJun 19, 2019
  5. Johannes SchindelinJun 21, 2019
  6. Duy NguyenJun 24, 2019
  7. 2/8 split-index.c: dump "link" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  8. 3/8 fsmonitor.c: dump "FSMN" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  9. 4/8 resolve-undo.c: dump "REUC" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  10. Derrick StoleeJun 19, 2019
  11. 5/8 read-cache.c: dump "EOIE" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  12. 6/8 read-cache.c: dump "IEOT" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  13. Derrick StoleeJun 19, 2019
  14. Duy NguyenJun 19, 2019
  15. Derrick StoleeJun 19, 2019
  16. 7/8 cache-tree.c: dump "TREE" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  17. 8/8 dir.c: dump "UNTR" extension as jsonNguyễn Thái Ngọc Duy, Jun 19, 2019
  18. Derrick StoleeJun 19, 2019
  19. Duy NguyenJun 19, 2019
  20. Derrick StoleeJun 19, 2019
  21. Jeff KingJun 19, 2019
  22. Duy NguyenJun 21, 2019
  23. Jeff KingJun 21, 2019
  24. Johannes SchindelinJun 21, 2019
  25. Duy NguyenJun 21, 2019
  26. Junio C HamanoJun 21, 2019
  27. Jeff KingJun 21, 2019
  28. Johannes SchindelinJun 24, 2019
  29. Johannes SchindelinJun 24, 2019
  30. Duy NguyenJun 24, 2019
  31. Jeff KingJun 21, 2019
  32. Johannes SchindelinJun 24, 2019
  33. Junio C HamanoJun 20, 2019
  34. Jeff HostetlerJun 20, 2019
  35. brian m. carlsonJun 21, 2019
  36. Duy NguyenJun 22, 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.