-static const char *header = NULL;
-static const char *header_prefix = "";
-static enum cmit_fmt commit_format = CMIT_FMT_RAW;
-
-static struct diff_options diff_options;
-
-static void call_diff_setup_done(void)
-{
- diff_setup_done(&diff_options);
-}
-
-static int call_diff_flush(void)
-{
- diffcore_std(&diff_options);
- if (diff_queue_is_empty()) {
- int saved_fmt = diff_options.output_format;
- diff_options.output_format = DIFF_FORMAT_NO_OUTPUT;
- diff_flush(&diff_options);
- diff_options.output_format = saved_fmt;
- return 0;
- }
- if (header) {
- printf("%s%c", header, diff_options.line_termination);
- header = NULL;
- }
- diff_flush(&diff_options);
- return 1;
-}
-
-static int diff_tree_sha1_top(const unsigned char *old,
- const unsigned char *new, const char *base)
-{
- int ret;
-
- call_diff_setup_done();
- ret = diff_tree_sha1(old, new, base, &diff_options);
- call_diff_flush();
- return ret;
-}
-
-static int diff_root_tree(const unsigned char *new, const char *base)
-{
- int retval;
- void *tree;
- struct tree_desc empty, real;
-
- call_diff_setup_done();
- tree = read_object_with_reference(new, "tree", &real.size, NULL);
- if (!tree)
- die("unable to read root tree (%s)", sha1_to_hex(new));
- real.buf = tree;
-
- empty.buf = "";
- empty.size = 0;
- retval = diff_tree(&empty, &real, base, &diff_options);
- 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)