]> git.ipfire.org Git - thirdparty/git.git/blob - read-tree.c
Add copyright notices.
[thirdparty/git.git] / read-tree.c
1 /*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
7
8 static int unpack(unsigned char *sha1)
9 {
10 void *buffer;
11 unsigned long size;
12 char type[20];
13
14 buffer = read_sha1_file(sha1, type, &size);
15 if (!buffer)
16 usage("unable to read sha1 file");
17 if (strcmp(type, "tree"))
18 usage("expected a 'tree' node");
19 while (size) {
20 int len = strlen(buffer)+1;
21 unsigned char *sha1 = buffer + len;
22 char *path = strchr(buffer, ' ')+1;
23 unsigned int mode;
24 if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1)
25 usage("corrupt 'tree' file");
26 buffer = sha1 + 20;
27 size -= len + 20;
28 printf("%o %s (%s)\n", mode, path, sha1_to_hex(sha1));
29 }
30 return 0;
31 }
32
33 int main(int argc, char **argv)
34 {
35 int fd;
36 unsigned char sha1[20];
37
38 if (argc != 2)
39 usage("read-tree <key>");
40 if (get_sha1_hex(argv[1], sha1) < 0)
41 usage("read-tree <key>");
42 sha1_file_directory = getenv(DB_ENVIRONMENT);
43 if (!sha1_file_directory)
44 sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
45 if (unpack(sha1) < 0)
46 usage("unpack failed");
47 return 0;
48 }