From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nicolas Pitre" <nico@fluxnic.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 01/10] test-dump: new test program to examine binary data
Date: Thu, 26 Sep 2013 09:26:40 +0700 [thread overview]
Message-ID: <1380162409-18224-2-git-send-email-pclouds@gmail.com> (raw)
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
next prev parent reply other threads:[~2013-09-26 2:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-26 2:26 [PATCH 00/10] pack v4 UI support Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` Nguyễn Thái Ngọc Duy [this message]
2013-09-26 2:26 ` [PATCH 02/10] config: add core.preferredPackVersion Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 03/10] upload-pack: new capability to send pack v4 Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 04/10] fetch: new option to set preferred pack version for transfer Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 05/10] clone: " Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 06/10] fetch: pack v4 support on smart http Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 07/10] receive-pack: request for packv4 if it's the preferred version Nguyễn Thái Ngọc Duy
2013-10-17 17:26 ` Junio C Hamano
2013-09-26 2:26 ` [PATCH 08/10] send-pack: support pack v4 Nguyễn Thái Ngọc Duy
2013-09-26 2:26 ` [PATCH 09/10] repack: add --pack-version and fall back to core.preferredPackVersion Nguyễn Thái Ngọc Duy
2013-09-26 8:32 ` [PATCH] repack: Add --version parameter Stefan Beller
2013-09-26 10:17 ` Felipe Contreras
2013-09-28 8:53 ` Stefan Beller
2013-09-26 11:42 ` Duy Nguyen
2013-09-28 8:54 ` Stefan Beller
2013-09-26 2:26 ` [PATCH 10/10] count-objects: report pack v4 usage Nguyễn Thái Ngọc Duy
2013-09-26 4:51 ` [PATCH 00/10] pack v4 UI support Nicolas Pitre
2013-09-26 5:09 ` Duy Nguyen
2013-09-27 2:59 ` Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380162409-18224-2-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=nico@fluxnic.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).