[PATCH 04/27] test-read-cache: print cache entries with --table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Derrick Stolee <dstolee@xxxxxxxxxxxxx>

This table is helpful for discovering data in the index to ensure it is
being written correctly, especially as we build and test the
sparse-index.

To make the option parsing slightly more robust, wrap the string
comparisons in a loop adapted from test-dir-iterator.c.

Care must be taken with the final check for the 'cnt' variable. We
continue the expectation that the numerical value is the final argument.

Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx>
---
 t/helper/test-read-cache.c | 49 ++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 5 deletions(-)

diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
index 244977a29bd..cd7d106a675 100644
--- a/t/helper/test-read-cache.c
+++ b/t/helper/test-read-cache.c
@@ -2,18 +2,55 @@
 #include "cache.h"
 #include "config.h"
 
+static void print_cache_entry(struct cache_entry *ce)
+{
+	/* stat info */
+	printf("%08x %08x %08x %08x %08x %08x ",
+	       ce->ce_stat_data.sd_ctime.sec,
+	       ce->ce_stat_data.sd_ctime.nsec,
+	       ce->ce_stat_data.sd_mtime.sec,
+	       ce->ce_stat_data.sd_mtime.nsec,
+	       ce->ce_stat_data.sd_dev,
+	       ce->ce_stat_data.sd_ino);
+
+	/* mode in binary */
+	printf("0b%d%d%d%d ",
+		(ce->ce_mode >> 15) & 1,
+		(ce->ce_mode >> 14) & 1,
+		(ce->ce_mode >> 13) & 1,
+		(ce->ce_mode >> 12) & 1);
+
+	/* output permissions? */
+	printf("%04o ", ce->ce_mode & 01777);
+
+	printf("%s ", oid_to_hex(&ce->oid));
+
+	printf("%s\n", ce->name);
+}
+
+static void print_cache(struct index_state *cache)
+{
+	int i;
+	for (i = 0; i < the_index.cache_nr; i++)
+		print_cache_entry(the_index.cache[i]);
+}
+
 int cmd__read_cache(int argc, const char **argv)
 {
 	int i, cnt = 1;
 	const char *name = NULL;
+	int table = 0;
 
-	if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
-		argc--;
-		argv++;
+	for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
+		if (skip_prefix(*argv, "--print-and-refresh=", &name))
+			continue;
+		if (!strcmp(*argv, "--table")) {
+			table = 1;
+		}
 	}
 
-	if (argc == 2)
-		cnt = strtol(argv[1], NULL, 0);
+	if (argc == 1)
+		cnt = strtol(argv[0], NULL, 0);
 	setup_git_directory();
 	git_config(git_default_config, NULL);
 	for (i = 0; i < cnt; i++) {
@@ -30,6 +67,8 @@ int cmd__read_cache(int argc, const char **argv)
 			       ce_uptodate(the_index.cache[pos]) ? "" : " not");
 			write_file(name, "%d\n", i);
 		}
+		if (table)
+			print_cache(&the_index);
 		discard_cache();
 	}
 	return 0;
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux