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

[PATCH 01/10] test-dump: new test program to examine binary data

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 26, 2013, 02:26 UTC
Message-ID
<1380162409-18224-2-git-send-email-pclouds@gmail.com>
In-Reply-To
<1380162409-18224-1-git-send-email-pclouds@gmail.com>

This will come handy for verifying binary files like .pack, .idx or $GIT_DIR/index. For now the only supported command is "ntohl". This command looks into the given file at the given offset, do ntohl() and return the value in decimal.

More commands may be added later to decode varint, or decompress a zlib stream and so on...

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 .gitignore        |  1 +
 Makefile          |  1 +
 test-dump.c (new) | 27 +++++++++++++++++++++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 test-dump.c
diff --git a/.gitignore b/.gitignore
index 2e2ae2b..6d835e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -182,6 +182,7 @@
 /test-ctype
 /test-date
 /test-delta
+/test-dump
 /test-dump-cache-tree
 /test-scrap-cache-tree
 /test-genrandom
diff --git a/Makefile b/Makefile
index af2e3e3..a07a194 100644
--- a/Makefile
+++ b/Makefile
@@ -560,6 +560,7 @@ TEST_PROGRAMS_NEED_X += test-chmtime
 TEST_PROGRAMS_NEED_X += test-ctype
 TEST_PROGRAMS_NEED_X += test-date
 TEST_PROGRAMS_NEED_X += test-delta
+TEST_PROGRAMS_NEED_X += test-dump
 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
 TEST_PROGRAMS_NEED_X += test-genrandom
 TEST_PROGRAMS_NEED_X += test-index-version
diff --git a/test-dump.c b/test-dump.c
new file mode 100644
index 0000000..71c6f8f
--- /dev/null
+++ b/test-dump.c
@@ -0,0 +1,27 @@
+#include "cache.h"
+
+static inline uint32_t ntoh_l_force_align(void *p)
+{
+	uint32_t x;
+	memcpy(&x, p, sizeof(x));
+	return ntohl(x);
+}
+
+int main(int ac, char **av)
+{
+	unsigned char *p;
+	int fd = open(av[2], O_RDONLY);
+	struct stat st;
+	if (lstat(av[2], &st))
+		return 1;
+	p = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (p == (unsigned char*)MAP_FAILED)
+		return 2;
+	if (!strcmp(av[1], "ntohl"))
+		printf("%u\n", ntoh_l_force_align(p + atoi(av[3])));
+	else {
+		fprintf(stderr, "unknown command %s\n", av[1]);
+		return 3;
+	}
+	return 0;
+}
-- 
1.8.2.82.gc24b958
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 2 of 20 in “pack v4 UI support”
  1. 00/10 pack v4 UI supportNguyễn Thái Ngọc Duy, Sep 26, 2013
  2. 01/10 test-dump: new test program to examine binary dataNguyễn Thái Ngọc Duy, Sep 26, 2013
  3. 02/10 config: add core.preferredPackVersionNguyễn Thái Ngọc Duy, Sep 26, 2013
  4. 03/10 upload-pack: new capability to send pack v4Nguyễn Thái Ngọc Duy, Sep 26, 2013
  5. 04/10 fetch: new option to set preferred pack version for transferNguyễn Thái Ngọc Duy, Sep 26, 2013
  6. 05/10 clone: new option to set preferred pack version for transferNguyễn Thái Ngọc Duy, Sep 26, 2013
  7. 06/10 fetch: pack v4 support on smart httpNguyễn Thái Ngọc Duy, Sep 26, 2013
  8. 07/10 receive-pack: request for packv4 if it's the preferred versionNguyễn Thái Ngọc Duy, Sep 26, 2013
  9. Junio C HamanoOct 17, 2013
  10. 08/10 send-pack: support pack v4Nguyễn Thái Ngọc Duy, Sep 26, 2013
  11. 09/10 repack: add --pack-version and fall back to core.preferredPackVersionNguyễn Thái Ngọc Duy, Sep 26, 2013
  12. repack: Add --version parameterStefan Beller, Sep 26, 2013
  13. Felipe ContrerasSep 26, 2013
  14. Stefan BellerSep 28, 2013
  15. Duy NguyenSep 26, 2013
  16. Stefan BellerSep 28, 2013
  17. 10/10 count-objects: report pack v4 usageNguyễn Thái Ngọc Duy, Sep 26, 2013
  18. Nicolas PitreSep 26, 2013
  19. Duy NguyenSep 26, 2013
  20. Nicolas PitreSep 27, 2013

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.