3 static int unpack(unsigned char *sha1
)
9 buffer
= read_sha1_file(sha1
, type
, &size
);
11 usage("unable to read sha1 file");
12 if (strcmp(type
, "tree"))
13 usage("expected a 'tree' node");
15 int len
= strlen(buffer
)+1;
16 unsigned char *sha1
= buffer
+ len
;
17 char *path
= strchr(buffer
, ' ')+1;
19 if (size
< len
+ 20 || sscanf(buffer
, "%o", &mode
) != 1)
20 usage("corrupt 'tree' file");
23 printf("%o %s (%s)\n", mode
, path
, sha1_to_hex(sha1
));
28 int main(int argc
, char **argv
)
31 unsigned char sha1
[20];
34 usage("read-tree <key>");
35 if (get_sha1_hex(argv
[1], sha1
) < 0)
36 usage("read-tree <key>");
37 sha1_file_directory
= getenv(DB_ENVIRONMENT
);
38 if (!sha1_file_directory
)
39 sha1_file_directory
= DEFAULT_DB_ENVIRONMENT
;
41 usage("unpack failed");