+static void call_diff_setup(void)
+{
+ diff_setup(diff_setup_opt);
+}
+
+static int call_diff_flush(void)
+{
+ if (detect_rename)
+ diffcore_rename(detect_rename, diff_score_opt);
+ if (pickaxe)
+ diffcore_pickaxe(pickaxe, pickaxe_opts);
+ if (diff_queue_is_empty()) {
+ diff_flush(DIFF_FORMAT_NO_OUTPUT, 0);
+ return 0;
+ }
+ if (header) {
+ const char *fmt = "%s";
+ if (diff_output_format == DIFF_FORMAT_MACHINE)
+ fmt = "%s%c";
+
+ printf(fmt, header, 0);
+ header = NULL;
+ }
+ diff_flush(diff_output_format, 1);
+ 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;
+}
+