6 static struct rev_info log_tree_opt;
8 static int diff_tree_commit_sha1(const unsigned char *sha1)
10 struct commit *commit = lookup_commit_reference(sha1);
13 return log_tree_commit(&log_tree_opt, commit);
16 static int diff_tree_stdin(char *line)
18 int len = strlen(line);
19 unsigned char sha1[20];
20 struct commit *commit;
22 if (!len || line[len-1] != '\n')
25 if (get_sha1_hex(line, sha1))
27 commit = lookup_commit(sha1);
28 if (!commit || parse_commit(commit))
30 if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
31 /* Graft the fake parents locally to the commit */
33 struct commit_list **pptr, *parents;
35 /* Free the real parent list */
36 for (parents = commit->parents; parents; ) {
37 struct commit_list *tmp = parents->next;
41 commit->parents = NULL;
42 pptr = &(commit->parents);
43 while (line[pos] && !get_sha1_hex(line + pos, sha1)) {
44 struct commit *parent = lookup_commit(sha1);
46 pptr = &commit_list_insert(parent, pptr)->next;
51 return log_tree_commit(&log_tree_opt, commit);
54 static const char diff_tree_usage[] =
55 "git-diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] "
56 "[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\n"
57 " -r diff recursively\n"
58 " --root include the initial commit as diff against /dev/null\n"
59 COMMON_DIFF_OPTIONS_HELP;
61 int main(int argc, const char **argv)
65 struct object *tree1, *tree2;
66 static struct rev_info *opt = &log_tree_opt;
67 struct object_list *list;
70 git_config(git_diff_config);
75 argc = setup_revisions(argc, argv, opt, NULL);
78 const char *arg = *++argv;
80 if (!strcmp(arg, "--stdin")) {
84 usage(diff_tree_usage);
88 * NOTE! "setup_revisions()" will have inserted the revisions
89 * it parsed in reverse order. So if you do
93 * the commit list will be "b" -> "a" -> NULL, so we reverse
94 * the order of the objects if the first one is not marked
98 list = opt->pending_objects;
108 usage(diff_tree_usage);
109 /* Switch them around if the second one was uninteresting.. */
110 if (tree2->flags & UNINTERESTING) {
111 struct object *tmp = tree2;
121 usage(diff_tree_usage);
124 diff_tree_commit_sha1(tree1->sha1);
127 diff_tree_sha1(tree1->sha1,
130 log_tree_diff_flush(opt);
137 if (opt->diffopt.detect_rename)
138 opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
139 DIFF_SETUP_USE_CACHE);
140 while (fgets(line, sizeof(line), stdin))
141 diff_tree_stdin(line);