wt-status: provide function to expose status for trees

The "wt-status" subsystem is responsible for printing status information around the current state of the working tree. This most importantly includes information around whether the working tree or the index have any changes. We're about to introduce a new command where the changes in neither of them are actually relevant to us. Instead, what we want is to format the changes between two different trees. While it is a little bit of a stretch to add this as functionality to _working tree_ status, it doesn't make any sense to open-code this functionality, either. Implement a new function `wt_status_collect_changes_trees()` that diffs two trees and formats the status accordingly. This function is not yet used, but will be in a subsequent commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 13, 2026 at 10:54 UTC 475ade1cd6e8ff07495b4b5871a69f7b385259f7
2 files changed +33
wt-status.c
+24
@@ -612,6 +612,30 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
612 }
613 }
614
615 +void wt_status_collect_changes_trees(struct wt_status *s,
616 + const struct object_id *old_treeish,
617 + const struct object_id *new_treeish)
618 +{
619 + struct diff_options opts = { 0 };
620 +
621 + repo_diff_setup(s->repo, &opts);
622 + opts.output_format = DIFF_FORMAT_CALLBACK;
623 + opts.format_callback = wt_status_collect_updated_cb;
624 + opts.format_callback_data = s;
625 + opts.detect_rename = s->detect_rename >= 0 ? s->detect_rename : opts.detect_rename;
626 + opts.rename_limit = s->rename_limit >= 0 ? s->rename_limit : opts.rename_limit;
627 + opts.rename_score = s->rename_score >= 0 ? s->rename_score : opts.rename_score;
628 + opts.flags.recursive = 1;
629 + diff_setup_done(&opts);
630 +
631 + diff_tree_oid(old_treeish, new_treeish, "", &opts);
632 + diffcore_std(&opts);
633 + diff_flush(&opts);
634 + wt_status_get_state(s->repo, &s->state, 0);
635 +
636 + diff_free(&opts);
637 +}
638 +
639 static void wt_status_collect_changes_worktree(struct wt_status *s)
640 {
641 struct rev_info rev;
wt-status.h
+9
@@ -153,6 +153,15 @@ void wt_status_add_cut_line(struct wt_status *s);
153 void wt_status_prepare(struct repository *r, struct wt_status *s);
154 void wt_status_print(struct wt_status *s);
155 void wt_status_collect(struct wt_status *s);
156 +
157 +/*
158 + * Collect all changes between the two trees. Changes will be displayed as if
159 + * they were staged into the index.
160 + */
161 +void wt_status_collect_changes_trees(struct wt_status *s,
162 + const struct object_id *old_treeish,
163 + const struct object_id *new_treeish);
164 +
165 /*
166 * Frees the buffers allocated by wt_status_collect.
167 */