-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 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) {
- if (!no_commit_id)
- 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;
-
- 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;
-
- 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 unsigned char *commit_sha1,
- const unsigned char *parent_sha1,
- const char *msg)
-{
- static char this_header[16384];
- int offset;
- unsigned long len;
- int abbrev = diff_options.abbrev;
-
- if (!verbose_header)
- return sha1_to_hex(commit_sha1);
-
- len = strlen(msg);
-
- offset = sprintf(this_header, "%s%s ",
- header_prefix,
- diff_unique_abbrev(commit_sha1, abbrev));
- if (commit_sha1 != parent_sha1)
- offset += sprintf(this_header + offset, "(from %s)\n",
- parent_sha1
- ? diff_unique_abbrev(parent_sha1, abbrev)
- : "root");
- else
- offset += sprintf(this_header + offset, "(from parents)\n");
- 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_sha1)