[PATCH] Make nsec checking optional
[git/dscho.git] / ls-tree.c
blob05c743ab6ab3a779c027eaa77e104d188ac0b698
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
8 static int list(unsigned char *sha1)
10 void *buffer;
11 unsigned long size;
12 char type[20];
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 unsigned char *type;
26 if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1)
27 usage("corrupt 'tree' file");
28 buffer = sha1 + 20;
29 size -= len + 20;
30 /* XXX: We do some ugly mode heuristics here.
31 * It seems not worth it to read each file just to get this
32 * and the file size. -- pasky@ucw.cz */
33 type = S_ISDIR(mode) ? "tree" : "blob";
34 printf("%03o\t%s\t%s\t%s\n", mode, type, sha1_to_hex(sha1), path);
36 return 0;
39 int main(int argc, char **argv)
41 unsigned char sha1[20];
43 if (argc != 2)
44 usage("ls-tree <key>");
45 if (get_sha1_hex(argv[1], sha1) < 0)
46 usage("ls-tree <key>");
47 sha1_file_directory = getenv(DB_ENVIRONMENT);
48 if (!sha1_file_directory)
49 sha1_file_directory = DEFAULT_DB_ENVIRONMENT;
50 if (list(sha1) < 0)
51 usage("list failed");
52 return 0;