git
/
diffcore-rotate.c
47 строк · 1.0 Кб
1/*
2* Copyright (C) 2021, Google LLC.
3* Based on diffcore-order.c, which is Copyright (C) 2005, Junio C Hamano
4*/
5#include "git-compat-util.h"6#include "gettext.h"7#include "diff.h"8#include "diffcore.h"9
10void diffcore_rotate(struct diff_options *opt)11{
12struct diff_queue_struct *q = &diff_queued_diff;13struct diff_queue_struct outq;14int rotate_to, i;15
16if (!q->nr)17return;18
19for (i = 0; i < q->nr; i++) {20int cmp = strcmp(opt->rotate_to, q->queue[i]->two->path);21if (!cmp)22break; /* exact match */23if (!opt->rotate_to_strict && cmp < 0)24break; /* q->queue[i] is now past the target pathname */25}26
27if (q->nr <= i) {28/* we did not find the specified path */29if (opt->rotate_to_strict)30die(_("No such path '%s' in the diff"), opt->rotate_to);31return;32}33
34DIFF_QUEUE_CLEAR(&outq);35rotate_to = i;36
37for (i = rotate_to; i < q->nr; i++)38diff_q(&outq, q->queue[i]);39for (i = 0; i < rotate_to; i++) {40if (opt->skip_instead_of_rotate)41diff_free_filepair(q->queue[i]);42else43diff_q(&outq, q->queue[i]);44}45free(q->queue);46*q = outq;47}
48