]>
git.ipfire.org Git - thirdparty/git.git/blob - read-tree.c
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 static int unpack(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;
24 if (size
< len
+ 20 || sscanf(buffer
, "%o", &mode
) != 1)
25 usage("corrupt 'tree' file");
28 printf("%o %s (%s)\n", mode
, path
, sha1_to_hex(sha1
));
33 int main(int argc
, char **argv
)
36 unsigned char sha1
[20];
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
;
46 usage("unpack failed");