2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 static int list(unsigned char *sha1
)
14 buffer
= read_sha1_file(sha1
, type
, &size
);
16 usage("unable to read sha1 file");
17 if (strcmp(type
, "tree"))
18 usage("expected a 'tree' node");
20 int len
= strlen(buffer
)+1;
21 unsigned char *sha1
= buffer
+ len
;
22 char *path
= strchr(buffer
, ' ')+1;
26 if (size
< len
+ 20 || sscanf(buffer
, "%o", &mode
) != 1)
27 usage("corrupt 'tree' file");
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
);
39 int main(int argc
, char **argv
)
41 unsigned char sha1
[20];
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
;