+static void call_diff_setup(void)
+{
+ diff_setup(diff_setup_opt);
+}
+
+static int call_diff_flush(void)
+{
+ diffcore_std(NULL,
+ detect_rename, diff_score_opt,
+ pickaxe, pickaxe_opts,
+ diff_break_opt,
+ orderfile,
+ diff_filter);
+ if (diff_queue_is_empty()) {
+ diff_flush(DIFF_FORMAT_NO_OUTPUT);
+ return 0;
+ }
+ if (header) {
+ printf("%s%c", header, diff_output_format == DIFF_FORMAT_MACHINE ? 0 : '\n');
+ header = NULL;
+ }
+ diff_flush(diff_output_format);
+ return 1;
+}
+
+static int diff_tree_sha1_top(const unsigned char *old,
+ const unsigned char *new, const char *base)
+{
+ int ret;
+
+ call_diff_setup();
+ ret = diff_tree_sha1(old, new, base);
+ call_diff_flush();
+ return ret;
+}
+
+static int diff_root_tree(const unsigned char *new, const char *base)
+{
+ int retval;
+ void *tree;
+ unsigned long size;
+
+ call_diff_setup();
+ tree = read_object_with_reference(new, "tree", &size, NULL);
+ if (!tree)
+ die("unable to read root tree (%s)", sha1_to_hex(new));
+ retval = diff_tree("", 0, tree, size, base);
+ free(tree);
+ call_diff_flush();
+ return retval;
+}
+
+static const char *generate_header(const char *commit, const char *parent, const char *msg, unsigned long len)
+{
+ static char this_header[16384];
+ int offset;
+
+ if (!verbose_header)
+ return commit;
+
+ offset = sprintf(this_header, "%s%s (from %s)\n", header_prefix, commit, parent);
+ offset += pretty_print_commit(commit_format, msg, len, this_header + offset, sizeof(this_header) - offset);
+ return this_header;
+}
+
+static int diff_tree_commit(const unsigned char *commit, const char *name)
+{
+ unsigned long size, offset;
+ char *buf = read_object_with_reference(commit, "commit", &size, NULL);
+
+ if (!buf)
+ return -1;
+
+ if (!name) {
+ static char commit_name[60];
+ strcpy(commit_name, sha1_to_hex(commit));
+ name = commit_name;
+ }