about summary refs log tree commit diff
path: root/third_party/git/t/helper/test-read-cache.c
diff options
context:
space:
mode:
authorVincent Ambo <Vincent Ambo>2020-01-11T23·36+0000
committerVincent Ambo <Vincent Ambo>2020-01-11T23·40+0000
commit7ef0d62730840ded097b524104cc0a0904591a63 (patch)
treea670f96103667aeca4789a95d94ca0dff550c4ce /third_party/git/t/helper/test-read-cache.c
parent6a2a3007077818e24a3d56fc492ada9206a10cf0 (diff)
parent1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5 (diff)
merge(third_party/git): Merge squashed git subtree at v2.23.0 r/373
Merge commit '1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5' as 'third_party/git'
Diffstat (limited to 'third_party/git/t/helper/test-read-cache.c')
-rw-r--r--third_party/git/t/helper/test-read-cache.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/third_party/git/t/helper/test-read-cache.c b/third_party/git/t/helper/test-read-cache.c
new file mode 100644
index 000000000000..7e79b555de80
--- /dev/null
+++ b/third_party/git/t/helper/test-read-cache.c
@@ -0,0 +1,37 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "config.h"
+
+int cmd__read_cache(int argc, const char **argv)
+{
+	int i, cnt = 1, namelen;
+	const char *name = NULL;
+
+	if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
+		namelen = strlen(name);
+		argc--;
+		argv++;
+	}
+
+	if (argc == 2)
+		cnt = strtol(argv[1], NULL, 0);
+	setup_git_directory();
+	git_config(git_default_config, NULL);
+	for (i = 0; i < cnt; i++) {
+		read_cache();
+		if (name) {
+			int pos;
+
+			refresh_index(&the_index, REFRESH_QUIET,
+				      NULL, NULL, NULL);
+			pos = index_name_pos(&the_index, name, namelen);
+			if (pos < 0)
+				die("%s not in index", name);
+			printf("%s is%s up to date\n", name,
+			       ce_uptodate(the_index.cache[pos]) ? "" : " not");
+			write_file(name, "%d\n", i);
+		}
+		discard_cache();
+	}
+	return 0;
+}