- if (!len || line[len-1] != '\n')
- return -1;
- line[len-1] = 0;
- if (get_sha1_hex(line, commit))
- return -1;
- if (isspace(line[40]) && !get_sha1_hex(line+41, parent)) {
- line[40] = 0;
- line[81] = 0;
- sprintf(this_header, "%s (from %s)\n", line, line+41);
- header = this_header;
- return diff_tree_sha1(parent, commit, "");
+static int call_diff_flush(void)
+{
+ diffcore_std(0,
+ detect_rename, diff_score_opt,
+ pickaxe, pickaxe_opts,
+ diff_break_opt,
+ orderfile);
+ 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;
+}
+
+static char *generate_header(const char *commit, const char *parent, const char *msg, unsigned long len)
+{
+ static char this_header[16384];
+ int offset;
+
+ offset = sprintf(this_header, "%s%s (from %s)\n", header_prefix, commit, parent);
+ if (verbose_header) {
+ offset += pretty_print_commit(commit_format, msg, len, this_header + offset, sizeof(this_header) - offset);
+ this_header[offset++] = '\n';
+ this_header[offset++] = 0;