aboutsummaryrefslogtreecommitdiff
path: root/read-tree.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 15:13:13 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 15:13:13 -0700
commite83c5163316f89bfbde7d9ab23ca2e25604af290 (patch)
tree2b5bfdf7798569e0b59b16eb9602d5fa572d6038 /read-tree.c
downloadgit-e83c5163316f89bfbde7d9ab23ca2e25604af290.tar.gz
git-e83c5163316f89bfbde7d9ab23ca2e25604af290.tar.xz
Initial revision of "git", the information manager from hell
Diffstat (limited to 'read-tree.c')
-rw-r--r--read-tree.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/read-tree.c b/read-tree.c
new file mode 100644
index 000000000..1b47742d8
--- /dev/null
+++ b/read-tree.c
@@ -0,0 +1,43 @@
+#include "cache.h"
+
+static int unpack(unsigned char *sha1)
+{
+ void *buffer;
+ unsigned long size;
+ char type[20];
+
+ buffer = read_sha1_file(sha1, type, &size);
+ if (!buffer)
+ usage("unable to read sha1 file");
+ if (strcmp(type, "tree"))
+ usage("expected a 'tree' node");
+ while (size) {
+ int len = strlen(buffer)+1;
+ unsigned char *sha1 = buffer + len;
+ char *path = strchr(buffer, ' ')+1;
+ unsigned int mode;
+ if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1)
+ usage("corrupt 'tree' file");
+ buffer = sha1 + 20;
+ size -= len + 20;
+ printf("%o %s (%s)\n", mode, path, sha1_to_hex(sha1));
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int fd;
+ unsigned char sha1[20];
+
+ if (argc != 2)
+ usage("read-tree <key>");
+ if (get_sha1_hex(argv[1], sha1) < 0)
+ usage("read-tree <key>");
+ sha1_file_directory = getenv(DB_ENVIRONMENT);
+ if (!sha1_file_directory)
+ sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
+ if (unpack(sha1) < 0)
+ usage("unpack failed");
+ return 0;
+}